Skip to content

Drizzle adapters

@vperms/drizzle-adapter provides one entry point per SQL dialect. The dialect comes from the import you use, and each ships its own migrations. All three extend VeguiPermsSqlAdapter and require an already-created Drizzle instance.

import Database from "better-sqlite3";
import { drizzle } from "drizzle-orm/better-sqlite3";
import {
sqliteSchema,
VeguiPermsSqliteAdapter,
} from "@vperms/drizzle-adapter/sqlite";
const adapter = new VeguiPermsSqliteAdapter({
db: drizzle(new Database(":memory:"), { schema: sqliteSchema }),
});
await adapter.migrate();
import { drizzle } from "drizzle-orm/mysql2";
import {
mysqlSchema,
VeguiPermsMysqlAdapter,
} from "@vperms/drizzle-adapter/mysql";
const adapter = new VeguiPermsMysqlAdapter({
db: drizzle(pool, { schema: mysqlSchema, mode: "default" }),
});
await adapter.migrate();
import { drizzle } from "drizzle-orm/node-postgres";
import {
postgresSchema,
VeguiPermsPostgresAdapter,
} from "@vperms/drizzle-adapter/postgres";
const adapter = new VeguiPermsPostgresAdapter({
db: drizzle(pool, { schema: postgresSchema }),
});
await adapter.migrate();

Each VeguiPerms*Adapter takes the Drizzle db instance plus optional migrationsFolder:

interface DriverOptions {
/** Folder with the bundled drizzle-kit migrations. */
migrationsFolder?: string;
}

Each dialect resolves its own bundled migrations/<dialect> folder by default; override it to apply migrations from a custom location. migrate() is explicit, idempotent and never called automatically.

Every entry point exports its Drizzle schema and tables, so you can include them in your own schema or introspection:

import { vpermsGrants, vpermsSubjects } from "@vperms/drizzle-adapter/sqlite";

The two tables are:

  • vperms_subjects — primary key (workspace_id, id), with type and parents.
  • vperms_grants — primary key (workspace_id, subject_id, permission), with value.

The root entry @vperms/drizzle-adapter re-exports the SQL base adapter and its types:

export { VeguiPermsSqlAdapter } from "@vperms/drizzle-adapter";
export type { GrantRecord, SqlAdapterDriver, SubjectRecord } from "@vperms/drizzle-adapter";

Regenerate the bundled migrations for all dialects from the repository with:

Terminal window
bun run db:generate