DrizzleORM v0.28.3 发布
2023年8月22日

修复

新功能

🎉 新增 SQLite 简化查询 API

🎉 为列构建器新增 .$defaultFn() / .$default() 方法

更多信息请查看 PostgreSQLMySQLSQLite 的文档。

您可以为像 cuid() 这样的函数指定任何逻辑和任何实现,用于运行时默认值。Drizzle 不会限制您可以添加的实现数量。

注意:此值不影响 drizzle-kit 的行为,它仅在 drizzle-orm 运行时使用

import { varchar, mysqlTable } from "drizzle-orm/mysql-core";
import { createId } from '@paralleldrive/cuid2';

const table = mysqlTable('table', {
	id: varchar('id', { length: 128 }).$defaultFn(() => createId()),
});

🎉 新增 table.$inferSelect / table._.inferSelecttable.$inferInsert / table._.inferInsert,以便更方便地推断表模型类型

import { InferSelectModel, InferInsertModel } from 'drizzle-orm'

const usersTable = pgTable('users', {
  id: serial('id').primaryKey(),
  name: text('name').notNull(),
  verified: boolean('verified').notNull().default(false),
  jsonb: jsonb('jsonb').$type<string[]>(),
  createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
});

type SelectUser = typeof usersTable.$inferSelect;
type InsertUser = typeof usersTable.$inferInsert;

type SelectUser2 = InferSelectModel<typeof usersTable>;
type InsertUser2 = InferInsertModel<typeof usersTable>;