Update using Query Builder

You can create UPDATE queries using QueryBuilder. Examples:

await dataSource
    .createQueryBuilder()
    .update(User)
    .set({ firstName: "Timber", lastName: "Saw" })
    .where("id = :id", { id: 1 })
    .execute()

This is the most efficient way in terms of performance to update entities in your database.

Raw SQL support

In some cases when you need to execute SQL queries you need to use function style value:

await dataSource
    .createQueryBuilder()
    .update(User)
    .set({
        firstName: "Timber",
        lastName: "Saw",
        age: () => "age + 1",
    })
    .where("id = :id", { id: 1 })
    .execute()

This syntax doesn't escape your values, you need to handle escape on your own.

Copyright © runoops.com 备案号:闽ICP备19010956号-1 all right reserved,powered by GitbookFile Modify: 2024-09-11 17:40:30

results matching ""

    No results matching ""