From 2eec23214fa4a83d10333ee7c50734456cf3bc2a Mon Sep 17 00:00:00 2001 From: liruifengv Date: Wed, 10 Sep 2025 21:03:28 +0800 Subject: [PATCH] i18n(zh-cn): Update `db.mdx` --- .../zh-cn/guides/integrations-guide/db.mdx | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/content/docs/zh-cn/guides/integrations-guide/db.mdx b/src/content/docs/zh-cn/guides/integrations-guide/db.mdx index 0483c272dc39b..558300e5ecc8c 100644 --- a/src/content/docs/zh-cn/guides/integrations-guide/db.mdx +++ b/src/content/docs/zh-cn/guides/integrations-guide/db.mdx @@ -128,6 +128,28 @@ const Comment = defineTable({ - `unique` - 将列标记为唯一。这将防止表中条目的值重复。 - `references` - 通过列引用相关表。这会建立一个外键约束,意味着每个列值必须在引用的表中有一个匹配的值。 +`text` 列可以选择性地定义字符串字面量列表以用作生成枚举类型。但是,**这不会在运行时执行任何校验**。删除、添加和更改这些值都应该由你的项目代码来处理。 + +```ts title="db/config.ts" {8} +import { defineTable, column } from 'astro:db'; + +// 表定义 +const UserTable = defineTable({ + columns: { + id: column.number({ primaryKey: true }), + name: column.text(), + rank: column.text({ enum: ['user', 'mod', 'admin'] }), + }, +}); + +// 生成的类型定义 +type UserTableInferInsert = { + id?: string; + name: string; + rank: "user" | "mod" | "admin"; +} +``` + ### `indexes` 表索引用于提高在特定列或列组合上的查找速度。`indexes` 属性接受一个配置对象数组,用于指定要索引的列: