Loading...
Loading...
Compare original and translation side by side
| Category | Impact | Description |
|---|---|---|
| Function Syntax | CRITICAL | New function syntax with args/returns/handler |
| Validators | CRITICAL | Type-safe argument and return validation |
| Schema Design | HIGH | Table definitions, indexes, system fields |
| Query Patterns | HIGH | Efficient data fetching with indexes |
| Mutation Patterns | MEDIUM | Database writes, patch vs replace |
| Action Patterns | MEDIUM | External API calls, Node.js runtime |
| Scheduling | MEDIUM | Crons and delayed function execution |
| File Storage | LOW | Blob storage and metadata |
| 分类 | 影响级别 | 描述 |
|---|---|---|
| 函数语法 | 关键 | 包含参数/返回值/处理器的新函数语法 |
| 验证器 | 关键 | 类型安全的参数和返回值验证 |
| 模式设计 | 高 | 表定义、索引、系统字段 |
| 查询模式 | 高 | 使用索引的高效数据获取 |
| 变更模式 | 中 | 数据库写入、部分更新vs全量替换 |
| 操作模式 | 中 | 外部API调用、Node.js运行时 |
| 任务调度 | 中 | 定时任务和延迟函数执行 |
| 文件存储 | 低 | Blob存储和元数据 |
// Public functions (exposed to clients)
import { query, mutation, action } from "./_generated/server";
// Internal functions (only callable from other Convex functions)
import {
internalQuery,
internalMutation,
internalAction,
} from "./_generated/server";// 公开函数(对客户端暴露)
import { query, mutation, action } from "./_generated/server";
// 内部函数(仅可从其他Convex函数调用)
import {
internalQuery,
internalMutation,
internalAction,
} from "./_generated/server";export const myFunction = query({
args: { name: v.string() },
returns: v.string(),
handler: async (ctx, args) => {
return "Hello " + args.name;
},
});export const myFunction = query({
args: { name: v.string() },
returns: v.string(),
handler: async (ctx, args) => {
return "Hello " + args.name;
},
});| Type | Validator | Example |
|---|---|---|
| String | | |
| Number | | |
| Boolean | | |
| ID | | |
| Array | | |
| Object | | |
| Optional | | |
| Union | | |
| Literal | | |
| Null | | |
| 类型 | 验证器 | 示例 |
|---|---|---|
| 字符串 | | |
| 数字 | | |
| 布尔值 | | |
| ID | | |
| 数组 | | |
| 对象 | | |
| 可选值 | | |
| 联合类型 | | |
| 字面量 | | |
| 空值 | | |
// Public functions
import { api } from "./_generated/api";
api.example.myQuery; // convex/example.ts → myQuery
// Internal functions
import { internal } from "./_generated/api";
internal.example.myInternalMutation;// 公开函数
import { api } from "./_generated/api";
api.example.myQuery; // convex/example.ts → myQuery
// 内部函数
import { internal } from "./_generated/api";
internal.example.myInternalMutation;// Schema
messages: defineTable({...}).index("by_channel", ["channelId"])
// Query
await ctx.db
.query("messages")
.withIndex("by_channel", (q) => q.eq("channelId", channelId))
.order("desc")
.take(10);// 模式
messages: defineTable({...}).index("by_channel", ["channelId"])
// 查询
await ctx.db
.query("messages")
.withIndex("by_channel", (q) => q.eq("channelId", channelId))
.order("desc")
.take(10);argsreturnsv.null()withIndex()filter()internalQuery/Mutation/Actionctx.dbargsreturnsv.null()withIndex()filter()internalQuery/Mutation/Actionctx.dbAGENTS.mdAGENTS.md