Files
2026-07-13 12:10:05 +08:00

90 lines
2.5 KiB
Markdown

- 🎉 Added Knex and Kysely adapters! They allow you to manage the schemas and migrations with Drizzle and query the data with your favorite query builder. See documentation for more details:
- [Knex adapter](https://github.com/drizzle-team/drizzle-knex)
- [Kysely adapter](https://github.com/drizzle-team/drizzle-kysely)
- 🎉 Added "type maps" to all entities. You can access them via the special `_` property. For example:
```ts
const users = mysqlTable('users', {
id: int('id').primaryKey(),
name: text('name').notNull(),
});
type UserFields = typeof users['_']['columns'];
type InsertUser = typeof users['_']['model']['insert'];
```
Full documentation on the type maps is coming soon.
- 🎉 Added `.$type()` method to all column builders to allow overriding the data type. It also replaces the optional generics on columns.
```ts
// Before
const test = mysqlTable('test', {
jsonField: json<Data>('json_field'),
});
// After
const test = mysqlTable('test', {
jsonField: json('json_field').$type<Data>(),
});
```
- ❗ Changed syntax for text-based enum columns:
```ts
// Before
const test = mysqlTable('test', {
role: text<'admin' | 'user'>('role'),
});
// After
const test = mysqlTable('test', {
role: text('role', { enum: ['admin', 'user'] }),
});
```
- 🎉 Allowed passing an array of values into `.insert().values()` directly without spreading:
```ts
const users = mysqlTable('users', {
id: int('id').primaryKey(),
name: text('name').notNull(),
});
await users.insert().values([
{ name: 'John' },
{ name: 'Jane' },
]);
```
The spread syntax is now deprecated and will be removed in one of the next releases.
- 🎉 Added "table creators" to allow for table name customization:
```ts
import { mysqlTableCreator } from 'drizzle-orm/mysql-core';
const mysqlTable = mysqlTableCreator((name) => `myprefix_${name}`);
const users = mysqlTable('users', {
id: int('id').primaryKey(),
name: text('name').notNull(),
});
// Users table is a normal table, but its name is `myprefix_users` in runtime
```
- 🎉 Implemented support for selecting/joining raw SQL expressions:
```ts
// select current_date + s.a as dates from generate_series(0,14,7) as s(a);
const result = await db
.select({
dates: sql`current_date + s.a`,
})
.from(sql`generate_series(0,14,7) as s(a)`);
```
- 🐛 Fixed a lot of bugs from user feedback on GitHub and Discord (thank you! ❤). Fixes #293 #301 #276 #269 #253 #311 #312