0.28.6
版本发布时间: 2023-09-06 23:54:05
drizzle-team/drizzle-orm最新发布版本:0.34.1(2024-10-08 04:07:09)
Changes
Note: MySQL
datetime
withmode: 'date'
will now store dates in UTC strings and retrieve data in UTC as well to align with MySQL behavior fordatetime
. If you need a different behavior and want to handledatetime
mapping in a different way, please usemode: 'string'
or Custom Types implementation
Check Fix Datetime mapping for MySQL for implementation details
New Features
🎉 LibSQL
batch api support
Batch API usage example:
const batchResponse = await db.batch([
db.insert(usersTable).values({ id: 1, name: 'John' }).returning({
id: usersTable.id,
}),
db.update(usersTable).set({ name: 'Dan' }).where(eq(usersTable.id, 1)),
db.query.usersTable.findMany({}),
db.select().from(usersTable).where(eq(usersTable.id, 1)),
db.select({ id: usersTable.id, invitedBy: usersTable.invitedBy }).from(
usersTable,
),
]);
Type for batchResponse
in this example would be:
type BatchResponse = [
{
id: number;
}[],
ResultSet,
{
id: number;
name: string;
verified: number;
invitedBy: number | null;
}[],
{
id: number;
name: string;
verified: number;
invitedBy: number | null;
}[],
{
id: number;
invitedBy: number | null;
}[],
];
All possible builders that can be used inside db.batch
:
`db.all()`,
`db.get()`,
`db.values()`,
`db.run()`,
`db.query.<table>.findMany()`,
`db.query.<table>.findFirst()`,
`db.select()...`,
`db.update()...`,
`db.delete()...`,
`db.insert()...`,
More usage examples here: integration-tests/tests/libsql-batch.test.ts and in docs
🎉 Add json mode for text in SQLite
Example
const test = sqliteTable('test', {
dataTyped: text('data_typed', { mode: 'json' }).$type<{ a: 1 }>().notNull(),
});
🎉 Add .toSQL()
to Relational Query API calls
Example
const query = db.query.usersTable.findFirst().toSQL();
🎉 Added new PostgreSQL operators for Arrays - thanks @L-Mario564
List of operators and usage examples
arrayContains
, arrayContained
, arrayOverlaps
const contains = await db.select({ id: posts.id }).from(posts)
.where(arrayContains(posts.tags, ['Typescript', 'ORM']));
const contained = await db.select({ id: posts.id }).from(posts)
.where(arrayContained(posts.tags, ['Typescript', 'ORM']));
const overlaps = await db.select({ id: posts.id }).from(posts)
.where(arrayOverlaps(posts.tags, ['Typescript', 'ORM']));
const withSubQuery = await db.select({ id: posts.id }).from(posts)
.where(arrayContains(
posts.tags,
db.select({ tags: posts.tags }).from(posts).where(eq(posts.id, 1)),
));
🎉 Add more SQL operators for where filter function in Relational Queries - thanks @cayter!
Before
import { inArray } from "drizzle-orm/pg-core";
await db.users.findFirst({
where: (table, _) => inArray(table.id, [ ... ])
})
After
await db.users.findFirst({
where: (table, { inArray }) => inArray(table.id, [ ... ])
})
Bug Fixes
- 🐛 Correct where in on conflict in sqlite - Thanks @hanssonduck!
- 🐛 Fix libsql/client type import - Thanks @luisfvieirasilva!
- 🐛 Fix: raw sql query not being mapped properly on RDS - Thanks @boian-ivanov
- 🐛 Fix Datetime mapping for MySQL - thanks @Angelelz
- 🐛 Fix smallserial generating as serial - thanks @L-Mario564
1、 drizzle-orm-0.28.6-dist.tgz 442.32KB