跳转到内容

Table SDK

eidos.space.table() 方法提供了类似 Prisma 风格的 CRUD (增删改查) 操作 API。这是与表格数据交互的推荐方式。

// 获取表格客户端 (tableId 是不带连字符的 UUIDv7)
const Users = eidos.space.table("01935b4c9d2e7f8a0b1c2d3e4f5a6b7c")
// CRUD 操作
await Users.create({ data: { name: "张三", age: 25 } })
await Users.findMany({ where: { age: { gte: 18 } } })

创建单条记录。如果未提供 _id,将自动生成。

async create(args: {
data: Record<string, any>
}): Promise<Record<string, any> & { _id: string }>

批量创建多条记录。

async createMany(args: {
data: Record<string, any>[]
skipDuplicates?: boolean
}): Promise<{ count: number }>

通过 _id 查找单条记录。

async findUnique(args: {
where: { _id: string }
}): Promise<Record<string, any> | null>

查找符合条件的第一条记录。

async findFirst(args: {
where?: Record<string, any>
orderBy?: Record<string, 'asc' | 'desc'>
}): Promise<Record<string, any> | null>

查询多条记录,支持过滤、排序和分页。

async findMany(args?: {
where?: Record<string, any>
orderBy?: Record<string, 'asc' | 'desc'>
skip?: number
take?: number
select?: Record<string, boolean>
}): Promise<Record<string, any>[]>

Where 子句运算符:

运算符描述示例
equals精确匹配{ name: { equals: "张三" } }
not不等于{ status: { not: "deleted" } }
gt大于{ age: { gt: 18 } }
gte大于等于{ age: { gte: 18 } }
lt小于{ age: { lt: 65 } }
lte小于等于{ age: { lte: 65 } }
contains包含子字符串{ name: { contains: "张" } }
startsWith以…开头{ email: { startsWith: "admin" } }
endsWith以…结尾{ email: { endsWith: "@gmail.com" } }
in在数组中{ status: { in: ["active", "pending"] } }
notIn不在数组中{ status: { notIn: ["deleted"] } }

统计符合条件的记录数。

async count(args?: {
where?: Record<string, any>
}): Promise<number>

通过 _id 更新单条记录。

async update(args: {
where: { _id: string }
data: Record<string, any>
}): Promise<Record<string, any> | null>

批量更新符合条件的记录。

async updateMany(args: {
where: Record<string, any>
data: Record<string, any>
}): Promise<{ count: number }>

通过 _id 删除单条记录。

async delete(args: {
where: { _id: string }
}): Promise<Record<string, any> | null>

批量删除符合条件的记录。

async deleteMany(args?: {
where?: Record<string, any>
}): Promise<{ count: number }>