- 使用Prisma的Query API来防范SQL注入攻击:
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
// Use parameterization to prevent SQL injections
const user = await prisma.user.findMany({
where: {
age: {
gt: 18
}
}
})
- 使用参数化查询来防范SQL注入攻击:
const { Client } = require('pg')
const client = new Client()
await client.connect()
const res = await client.query({
text: 'SELECT * FROM users WHERE id = $1',
values: [userId]
})
await client.end()
- 使用预处理语句来防范SQL注入攻击:
const { Client } = require('pg')
const client = new Client()
await client.connect()
const res = await client.query({
text: 'SELECT * FROM users WHERE id = $1',
name: 'fetch-user',
values: [userId]
})
await client.end()