














v0.10.0ESM-onlyTypeScript strictNode 22+ · Bun · Deno
Repositories, functional queries, and a plugin core that hardens both — in a toolkit that never hides your SQL. Not an ORM, by design.
Works with PostgreSQL · MySQL · SQLite · MSSQL
const executor = await createExecutor(db, [
rlsPlugin({ schema: rlsSchema }),
softDeletePlugin(),
])
// One plugin core — both patterns
const orm = await createORM(executor, []) // Repository
const ctx = createContext(executor) // Functional DAL
// Filters and policies apply to every query —
// including inside transactions
Kysera is a thin layer over Kysely, not a replacement for it. Every query is still a Kysely query; every escape hatch stays open — drop to the raw instance or a sql template whenever you need to.
Plugins intercept queries at the executor, so the Repository pattern and the functional DAL share the same soft-delete filters and RLS policies — in and out of transactions. Repositories add an atomic audit trail on top. Mix both styles in one codebase (CQRS-lite).
Row-level security enforces SELECT, UPDATE, and DELETE in SQL. Soft delete narrows mutations to live rows. Opt-outs are scoped per statement — there is no global bypass switch to forget about.
Structured CRUD where you want conventions, composable functions where you want reach — against the same executor, the same plugins, the same transaction.
users.repository.ts
import {
createORM, createRepositoryFactory, zodAdapter
} from '@kysera/repository'
const orm = await createORM(executor, [])
const users = orm.createRepository(exec =>
createRepositoryFactory(exec).create({
tableName: 'users',
mapRow: row => row,
schemas: { create: zodAdapter(CreateUser) },
})
)
const user = await users.create({
email: 'ada@example.com',
name: 'Ada',
})
await users.softDelete(user.id) // added by the plugin
await users.findAll() // deleted rows filtered
users.queries.ts
import {
createQuery, createContext, withTransaction,
type DbContext
} from '@kysera/dal'
const userByEmail = createQuery(
(ctx: DbContext<DB>, email: string) =>
ctx.db
.selectFrom('users')
.selectAll()
.where('email', '=', email)
.executeTakeFirst()
)
const ctx = createContext(executor)
await userByEmail(ctx, 'ada@example.com')
// soft-delete filter applied automatically
await withTransaction(executor, async tx => {
await userByEmail(tx, 'ada@example.com')
}) // plugins survive; nested calls → savepoints
Each plugin declares a priority tier and runs in a fixed, inspectable order — security → filters → transforms → audit — no matter how you register them.
Thirteen focused packages. Install what you use; tree-shake the rest.
0
Third-party runtime deps
3
Runtimes: Node, Bun, Deno
Tested in CI against live PostgreSQL and MySQL on every push; concurrency claims are proven by racing tests. A benchmark suite tracks overhead each release: the executor without plugins measures within noise-to-13% of raw Kysely on the execute path, and a full three-plugin stack costs ~15–20%.
Add the packages to an existing project, or let the CLI scaffold one — config, migrations, and a health check included.
npm install kysely zod
npm install @kysera/executor @kysera/repository @kysera/soft-delete
ESM-only, Node 22+. Zod is optional — bring Valibot or TypeBox instead, or skip validation entirely.
npx @kysera/cli init my-app
npx @kysera/cli doctor
init sets up config and migrations; doctor verifies the whole environment in one shot.
import { Kysely, PostgresDialect } from 'kysely'
import { createExecutor } from '@kysera/executor'
import {
createORM, createRepositoryFactory, zodAdapter
} from '@kysera/repository'
import { softDeletePlugin } from '@kysera/soft-delete'
import { z } from 'zod'
const db = new Kysely<Database>({
dialect: new PostgresDialect({ pool })
})
const executor = await createExecutor(db, [softDeletePlugin()])
const orm = await createORM(executor, [])
const users = orm.createRepository(exec =>
createRepositoryFactory(exec).create({
tableName: 'users',
mapRow: row => row,
schemas: {
create: zodAdapter(
z.object({ email: z.string().email(), name: z.string() })
)
},
})
)
const user = await users.create({ email: 'ada@example.com', name: 'Ada' })
await users.softDelete(user.id)
await users.findAll() // soft-deleted rows are filtered out
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。