Skip to content

@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.

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();
import {
VeguiPermsPostgresAdapter,
postgresSchema,
vpermsGrants,
vpermsSubjects,
} from "@vperms/drizzle-adapter/postgres";
const adapter = new VeguiPermsPostgresAdapter({ db /* NodePgDatabase */ });
await adapter.migrate();

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.

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).

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.