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.
SQLite
Section titled “SQLite”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();Postgres
Section titled “Postgres”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();Options
Section titled “Options”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.
Schema
Section titled “Schema”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), withtypeandparents.vperms_grants— primary key(workspace_id, subject_id, permission), withvalue.
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";Migrations
Section titled “Migrations”Regenerate the bundled migrations for all dialects from the repository with:
bun run db:generate