Skip to content
Kosame is a database framework based on Drizzle that supports model-driven development.
bun add kosame

Add a Model on top of your Drizzle table

Add a Model class and start building model-driven.

Defining a Model
ts
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.tsunchanged
  • db.tsunchanged
  • models/user.tsnew
  • data/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.

Hooks
ts
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
1.00×
0.94×
1.22×
find by id + include
1.00×
1.12×
1.25×
insert one
1.00×
1.02×
1.15×
update one
1.00×
1.63×
1.49×
20 roots + relation (one call per root)
1.00×
5.31×
1.05×
1.72×

Time per operation relative to raw Drizzle (1.0). Shorter is faster. One run on Apple M3, Bun 1.3, PostgreSQL 17.

Runs where Drizzle runs

Install the Drizzle driver you already use.

Dialect notes
  • PostgreSQLnode-postgres
  • MySQLmysql2
  • SQLitebetter-sqlite3 / libsql
  • Cloudflare D1not verified yet