Kosame is a database framework based on Drizzle that supports model-driven development.
bun add kosameAdd a Model on top of your Drizzle table
Add a Model class and start building model-driven.
Defining a Modelts
import { Model } from "kosame";
export class User extends Model {
static table = usersTable;
}Keep the Drizzle project you already have
Kosame works with the schema you already wrote. Pass your own db to createContext, and drop back to plain Drizzle through context.raw whenever you want.
schema.tsunchangeddb.tsunchangedmodels/user.tsnewdata/context.tsnew
Stop a bad write before it happens
Override beforeCreate, beforeUpdate or beforeDelete on the Model and throw to abort the write. Inside a transaction, afterCommit and afterRollback run once the outcome is known.
Hooksts
export class User extends Model {
static table = usersTable;
override async beforeCreate() {
if (!this.name.includes("kosame")) {
throw new Error("Name must contain kosame");
}
}
}Close to raw Drizzle
Measured against raw Drizzle on PostgreSQL. Where Kosame has a first-class API the cost is within noise; where it needs an extra round trip, it says so.
Full results and method- Drizzle
- Kosame
- Kosame via context.raw (2 queries)
- Prisma
find by id
find by id + include
insert one
update one
20 roots + relation (one call per root)
Time per operation relative to raw Drizzle (1.0). Shorter is faster. One run on Apple M3, Bun 1.3, PostgreSQL 17.
- PostgreSQLnode-postgres
- MySQLmysql2
- SQLitebetter-sqlite3 / libsql
- Cloudflare D1not verified yet
