Codync
免費、開源的 1:1 替代方案,取代 Grok Bot 與 Muse。從 iPhone、Mac 或 Linux 桌面將 Claude Code、Codex、Cursor 與 40+ 程式碼代理人作為持續機器人傳訊。群組聊天、主題串…
AI 翻譯
尚未收集儲存庫資訊。
尚未偵測到更新。GitHub 發布版本後會顯示在這裡。
製作者的介紹僅有上面的一句話。 更多詳情請閱讀儲存庫 README。 儲存庫 README ↗
正在載入完整 README。
檢視完整 README ↗A type-safe, PostgreSQL-native ORM for TypeScript with deep relational querying, middleware support, and declarative schema definitions.
npm add @casekit/orm @casekit/orm-cli @casekit/orm-migrate pg zod
pnpm orm init --directory ./src/db
// src/db/models/author.ts
import type { ModelDefinition } from "@casekit/orm";
import { sql } from "@casekit/sql";
export const author = {
fields: {
id: { type: "serial", primaryKey: true },
name: { type: "text" },
email: { type: "text", unique: true },
createdAt: { type: "timestamptz", default: sql`now()` },
},
relations: {
books: {
type: "1:N",
model: "book",
fromField: "id",
toField: "authorId",
},
},
} as const satisfies ModelDefinition;
// src/db/index.ts
import { orm, type Config } from "@casekit/orm";
import { snakeCase } from "es-toolkit";
import * as models from "./models/index.js";
const config = {
models,
naming: { column: snakeCase },
connection: { database: "myapp" },
} as const satisfies Config;
export const db = orm(config);
pnpm orm db push
import { $ilike } from "@casekit/orm";
const authorsWithBooks = await db.findMany("author", {
select: ["id", "name"],
include: {
books: {
select: ["id", "title"],
where: { published: true },
orderBy: [["title", "asc"]],
limit: 5,
},
},
where: {
email: { [$ilike]: "%@example.com" },
},
});
// Create
const author = await db.createOne("author", {
values: { name: "Jane", email: "[email protected]" },
returning: ["id", "createdAt"],
});
// Read
const authors = await db.findMany("author", {
select: ["id", "name"],
where: { name: { [$ilike]: "%john%" } },
orderBy: [["name", "asc"]],
limit: 10,
});
// Update
await db.updateOne("author", {
set: { name: "Jane Doe" },
where: { id: 1 },
});
// Delete
await db.deleteOne("author", {
where: { id: 1 },
});
await db.transact(async (tx) => {
const author = await tx.createOne("author", {
values: { name: "New Author", email: "[email protected]" },
returning: ["id"],
});
await tx.createOne("book", {
values: { title: "New Book", authorId: author.id },
});
});
Apply cross-cutting concerns like multi-tenancy or automatic timestamps:
const dbWithMiddleware = db.middleware([
tenancy({ org: currentOrg }),
userstamps({ user: currentUser }),
]);
// All queries automatically filtered by org and stamped with user
For complex queries, use raw SQL with type safety via Zod:
import { z } from "zod";
import { sql } from "@casekit/sql";
const results = await db.query(
z.object({ total: z.number() }),
sql`SELECT COUNT(*) as total FROM authors WHERE active = true`
);
| Package | Description |
|---|---|
@casekit/orm | Core ORM library |
@casekit/orm-cli | CLI for init, push, pull, generate |
@casekit/orm-migrate | Schema migration engine |
@casekit/orm-schema | Type definitions |
@casekit/orm-config | Configuration normalization |
@casekit/sql | SQL template literal builder |
Full documentation available at the docs site.
MIT