SuperAPI AI 工具集

convex-development-general

编程与开发

查看项目

更新于 10-16 09:47

技能介绍

用途:为 Convex 后端开发提供通用规则,涵盖 schema 设计、验证器、索引优先查询、函数注册与异步处理,帮助避免常见反模式。

主要能力与规范:在 convex/schema.ts 用 defineTable(v.object({...})) 定义表结构;跨文档引用用 v.id("tableName"),不要用 v.string();不要在 schema 中写 _id 和 _creationTime,它们是自动生成的系统字段。函数使用新语法,必须同时提供 args 与 returns 验证器,无返回值时用 returns: v.null();私有逻辑用 internalQuery/internalMutation/internalAction,不通过公开 API 暴露;HTTP 端点用 httpAction 配合 httpRouter 写在 convex/http.ts。

查询模式:优先 .withIndex("by_field", (q) => q.eq("field", value)),而非 .filter;索引在 defineTable 上用 .index("name", ["field1"]) 添加;全文搜索用 .withSearchIndex。避免对大表无界 .collect(),改用 .paginate(opts) 或 .take(n)。query 为只读、响应式、运行于 V8 沙箱;mutation 负责写入、事务性、运行于 V8 沙箱;action 可调外部 API/Node.js,但非事务性。跨函数调用用 ctx.runQuery/ctx.runMutation。所有 Promise 必须 await,如 ctx.db.patch、ctx.scheduler.runAfter,可启用 no-floating-promises ESLint 规则。客户端 useQuery 钩子自动订阅并响应数据变化。

限制:资料未提供价格、平台支持范围或具体安装步骤;使用需遵循其硬性约束与反模式表。