npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@arxjs/drizzle

v0.0.1

Published

Drizzle ORM adapter for @arxjs/core — supports PostgreSQL, MySQL, and SQLite

Downloads

58

Readme

@arxjs/drizzle

Drizzle ORM adapter for @arxjs/core. Supports PostgreSQL, MySQL, and SQLite via dialect-specific adapters.

Installation

pnpm add @arxjs/drizzle @arxjs/core drizzle-orm
# npm install @arxjs/drizzle @arxjs/core drizzle-orm

Quick start

Pick the adapter that matches your database. No schema configuration needed — each adapter bundles its own schema internally.

PostgreSQL

import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'
import { createAuthorization } from '@arxjs/core'
import { DrizzlePgAdapter } from '@arxjs/drizzle'

const db = drizzle(postgres(process.env.DATABASE_URL))

const arx = createAuthorization({
  adapter: new DrizzlePgAdapter(db),
})

MySQL

import { drizzle } from 'drizzle-orm/mysql2'
import mysql from 'mysql2/promise'
import { createAuthorization } from '@arxjs/core'
import { DrizzleMysqlAdapter } from '@arxjs/drizzle'

const connection = await mysql.createConnection(process.env.DATABASE_URL)
const db = drizzle(connection)

const arx = createAuthorization({
  adapter: new DrizzleMysqlAdapter(db),
})

SQLite

import { drizzle } from 'drizzle-orm/better-sqlite3'
import Database from 'better-sqlite3'
import { createAuthorization } from '@arxjs/core'
import { DrizzleSqliteAdapter } from '@arxjs/drizzle'

const db = drizzle(new Database('sqlite.db'))

const arx = createAuthorization({
  adapter: new DrizzleSqliteAdapter(db),
})

Setting up the database tables

arx needs five tables in your database. There are two ways to create them.

Option A — drizzle-kit (recommended)

drizzle-kit generates and runs migrations automatically. For it to work, it needs to see the arx tables alongside your own tables in your schema file.

1. Re-export the arx schema from your schema file

Pick the subpath that matches your dialect and re-export its contents:

// src/schema.ts

// Re-export arx tables so drizzle-kit includes them in migrations
export * from '@arxjs/drizzle/schema/pg'     // PostgreSQL
// export * from '@arxjs/drizzle/schema/mysql'  // MySQL
// export * from '@arxjs/drizzle/schema/sqlite' // SQLite

// Your own tables
export const posts = pgTable('posts', {
  id:    text('id').primaryKey(),
  title: text('title').notNull(),
})

Why re-export? drizzle-kit reads your schema file to build a complete picture of your database. If the arx tables aren't visible in your schema, drizzle-kit won't generate migration SQL for them. This is the standard Drizzle pattern for third-party schemas.

2. Point drizzle.config.ts to your schema file

// drizzle.config.ts
import { defineConfig } from 'drizzle-kit'

export default defineConfig({
  schema: './src/schema.ts',  // your schema file that re-exports arx tables
  out:    './drizzle',
  dialect: 'postgresql',
  dbCredentials: { url: process.env.DATABASE_URL },
})

3. Generate and run the migration

npx drizzle-kit generate   # creates SQL migration files in ./drizzle
npx drizzle-kit migrate    # applies the migrations to your database

For local development, drizzle-kit push skips the migration files and applies changes directly:

npx drizzle-kit push

Option B — manual SQL

If you manage your own migrations, see the database schema reference in @arxjs/core. It contains a database-agnostic diagram of all five tables with their columns and constraints.

Usage

await arx.createRole('editor', { permissions: ['post:edit', 'post:view'] })
await arx.assignRole('user-1', 'editor')
await arx.can('user-1', 'post:edit') // true

See @arxjs/core for the full API reference.

Schema reference

The arx table definitions are exported from the dialect-specific schema subpaths:

| Subpath | Dialect | |---|---| | @arxjs/drizzle/schema/pg | PostgreSQL | | @arxjs/drizzle/schema/mysql | MySQL / MariaDB | | @arxjs/drizzle/schema/sqlite | SQLite |

Each exports five table objects (roles, permissions, rolePermissions, userRoles, userPermissions) and a schema object that bundles all five.

// Access individual tables if needed (e.g. for manual queries)
import { roles, permissions } from '@arxjs/drizzle/schema/pg'

Advanced: using the relational query API

Drizzle's relational query API (db.query.roles.findMany(...)) requires the schema to be passed to the drizzle() constructor. If you want to use this API on arx tables directly, merge the arx schema into your drizzle() call:

import { drizzle } from 'drizzle-orm/postgres-js'
import * as arxSchema from '@arxjs/drizzle/schema/pg'
import * as mySchema from './schema'

const db = drizzle(client, {
  schema: { ...arxSchema, ...mySchema },
})

// Now db.query.roles is typed and available
const allRoles = await db.query.roles.findMany()

In most cases you won't need to query arx tables directly — the adapter handles all of that.

Advanced: custom table names

If you need to rename the arx tables (e.g. to avoid conflicts with existing tables), you can extend DrizzleAdapter with your own schema object:

import { DrizzleAdapter } from '@arxjs/drizzle'
import type { ArxDrizzleSchema } from '@arxjs/drizzle'
import { pgTable, primaryKey, text, timestamp } from 'drizzle-orm/pg-core'

// Define renamed versions of the arx tables
const myRoles = pgTable('auth_roles', {
  id:        text('id').primaryKey(),
  name:      text('name').notNull().unique(),
  createdAt: timestamp('created_at').notNull().defaultNow(),
})
// ... define all five tables

const customSchema: ArxDrizzleSchema = {
  roles:           myRoles,
  permissions:     myPermissions,
  rolePermissions: myRolePermissions,
  userRoles:       myUserRoles,
  userPermissions: myUserPermissions,
}

class MyAdapter extends DrizzleAdapter {
  constructor(db: AnyDrizzleDB) {
    super(db, customSchema)
  }
}

Peer dependencies

| Package | Version | |---|---| | @arxjs/core | * | | drizzle-orm | >=0.31.0 |

License

MIT