UPDATE
For WHERE examples, please see the WHERE section.
Simple update
QueryBuilder
import { QueryBuilder } from 'mysql2-orm';
const { sql, params } = QueryBuilder.update({
table: 'users',
set: {
name: 'John',
},
});
MySQL2 ORM Class
import { MySQL } from 'mysql2-orm';
const pool = new MySQL({
// ...
});
await pool.update({
table: 'users',
set: {
name: 'John',
},
});
SQL Query
UPDATE `users` SET `name` = ?
-- params: ['John']
Update multiple columns
QueryBuilder
import { QueryBuilder } from 'mysql2-orm';
const { sql, params } = QueryBuilder.update({
table: 'users',
set: {
name: 'John',
age: 29,
// ...
},
});
MySQL2 ORM Class
import { MySQL } from 'mysql2-orm';
const pool = new MySQL({
// ...
});
await pool.update({
table: 'users',
set: {
name: 'John',
age: 29,
// ...
},
});
SQL Query
UPDATE `users` SET `name` = ?, `age` = ?
-- params: ['John', 29]