那是什么 :name 语法?
What is that :name syntax?
TypeORM documentation中有这样的例子:
import {getConnection} from "typeorm";
await getConnection()
.createQueryBuilder()
.update(User)
.set({ firstName: "Timber", lastName: "Saw" })
.where("id = :id", { id: 1 })
.execute();
在哪里可以找到有关 :id
语法的更多信息?它也可以用在 .set
方法中吗?
我认为在 set 方法中使用它没有意义,因为您正在那里传递一个对象,它应该已经被转义了。查询参数用于使查询更具可读性并防止 SQL 注入。
TypeORM documentation中有这样的例子:
import {getConnection} from "typeorm";
await getConnection()
.createQueryBuilder()
.update(User)
.set({ firstName: "Timber", lastName: "Saw" })
.where("id = :id", { id: 1 })
.execute();
在哪里可以找到有关 :id
语法的更多信息?它也可以用在 .set
方法中吗?
我认为在 set 方法中使用它没有意义,因为您正在那里传递一个对象,它应该已经被转义了。查询参数用于使查询更具可读性并防止 SQL 注入。