DrizzleORM v0.28.3 发布
Aug 22, 2023

修复

  • 修复了当结果为空时,sqlite-proxy 和 SQL.js 的 ‘.get()’ 响应的问题

新功能

🎉 添加了 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

  • 🛠 将 InferModel 类型废弃,推荐使用更明确的 InferSelectModelInferInsertModel
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>;
  • 🛠 禁用了 .d.ts 文件的绑定。
Become a Gold Sponsor