@vperms/drizzle-adapter
@vperms/drizzle-adapter provides Drizzle-backed adapters for SQLite, MySQL and
Postgres. Each subpath ships its schema, a driver and the migration files.
SQLite
Section titled “SQLite”import { VeguiPermsSqliteAdapter, sqliteSchema, vpermsGrants, vpermsSubjects,} from "@vperms/drizzle-adapter/sqlite";
const adapter = new VeguiPermsSqliteAdapter({ db, // BetterSQLite3Database<SqliteSchema> migrationsFolder: "node_modules/@vperms/drizzle-adapter/migrations/sqlite",});await adapter.migrate();import { VeguiPermsMysqlAdapter, mysqlSchema, vpermsGrants, vpermsSubjects,} from "@vperms/drizzle-adapter/mysql";
const adapter = new VeguiPermsMysqlAdapter({ db /* MySql2Database */ });await adapter.migrate();Postgres
Section titled “Postgres”import { VeguiPermsPostgresAdapter, postgresSchema, vpermsGrants, vpermsSubjects,} from "@vperms/drizzle-adapter/postgres";
const adapter = new VeguiPermsPostgresAdapter({ db /* NodePgDatabase */ });await adapter.migrate();Options
Section titled “Options”Every adapter accepts the Drizzle database plus driver options:
interface DriverOptions { migrationsFolder?: string;}migrate() calls Drizzle’s migrate with the package’s bundled migrations
folder. Pass migrationsFolder to point at your own copy, for example when
bundling.
Schema
Section titled “Schema”The SQLite schema (mirrored, with native types, for MySQL and Postgres):
const vpermsSubjects = sqliteTable("vperms_subjects", { workspaceId: text("workspace_id").notNull(), id: text("id").notNull(), type: text("type").notNull(), parents: text("parents", { mode: "json" }).$type<string[]>().notNull(),});
const vpermsGrants = sqliteTable("vperms_grants", { workspaceId: text("workspace_id").notNull(), subjectId: text("subject_id").notNull(), permission: text("permission").notNull(), value: integer("value", { mode: "boolean" }).notNull(),});Subjects are keyed by (workspace_id, id) and grants by
(workspace_id, subject_id, permission).
Root exports
Section titled “Root exports”The package root re-exports the SQL base adapter and its record types:
VeguiPermsSqlAdapter, GrantRecord, SubjectRecord, SqlAdapterDriver.
Regenerate migration files in this repository with bun run db:generate.