Skip to content

Mutations

create

Insert a single record and return it:

const user = await r.users.create({
data: {
firstName: 'John',
lastName: 'Doe',
email: 'john@example.com',
},
});
// { id: 1, firstName: 'John', lastName: 'Doe', email: 'john@example.com', ... }

The data object is typed based on the table’s insert type from Drizzle ($inferInsert). Required columns must be provided; columns with defaults are optional.

createMany

Insert multiple records at once:

const users = await r.users.createMany({
data: [
{ firstName: 'John', lastName: 'Doe', email: 'john@example.com' },
{ firstName: 'Jane', lastName: 'Doe', email: 'jane@example.com' },
],
});
// [{ id: 1, ... }, { id: 2, ... }]

update

Update a record matching the where condition and return it:

const updated = await r.users.update({
where: { id: 1 },
data: { firstName: 'Jane' },
});
// { id: 1, firstName: 'Jane', ... }

The where clause supports all the same operators as findMany. The data object accepts partial updates — only the specified columns are changed.

updateMany

Update multiple records matching the filter. Returns a count:

const result = await r.users.updateMany({
where: { role: 'guest' },
data: { active: false },
});
// { count: 15 }

delete

Delete a single record matching the where condition and return it:

const deleted = await r.users.delete({
where: { id: 1 },
});
// { id: 1, firstName: 'John', ... }

deleteMany

Delete multiple records matching the filter. Returns a count:

const result = await r.users.deleteMany({
where: { active: false },
});
// { count: 8 }

RETURNING behavior

The create, update, and delete methods return the affected row(s). This depends on dialect support:

DialectRETURNING support
PostgreSQLNative RETURNING *
SQLiteNative RETURNING *
MySQLNo RETURNING — uses insertId fallback for create

Combining with transactions

All mutation methods are available inside transactions:

await r.$transaction(async (tx) => {
const user = await tx.users.create({
data: { firstName: 'John', lastName: 'Doe', email: 'john@example.com' },
});
await tx.orders.create({
data: { userId: user.id, total: 100 },
});
});

See Transactions for details.