🚧 Glyx is pre-release software. APIs may change before v1.0. Get started →
Documentation
Packages
@glyx-dev/drizzle

@glyx-dev/drizzle Stable

Drizzle ORM adapter for Glyx's built-in SQLite. Bridges Drizzle's sqlite-proxy driver to Glyx's native database bindings.

Requires capability: "db"

Install

npm install drizzle-orm @glyx-dev/drizzle

drizzle-kit CLI commands (drizzle-kit push, drizzle-kit migrate) do not work with @glyx-dev/drizzle — they cannot connect to an embedded Glyx SQLite database. Use db.migrate() for schema migrations instead.

Setup

Open a database handle with db.open(), then pass it to createDrizzle:

// src/db.ts
import { createDrizzle } from '@glyx-dev/drizzle'
import { db } from '@glyx-dev/react'
import * as schema from './schema'
 
const handle = await db.open('app.db')
export const drizzleDb = createDrizzle(handle, schema)

API

createDrizzle(handle, schema?)

ParamTypeDescription
handlenumberDatabase handle from db.open()
schemaobjectOptional Drizzle relational schema for .query.* API

Returns a Drizzle SqliteRemoteDatabase — the full Drizzle query builder API.

Schema

// src/schema.ts
import { integer, text, sqliteTable } from 'drizzle-orm/sqlite-core'
 
export const notes = sqliteTable('notes', {
  id:         integer('id').primaryKey({ autoIncrement: true }),
  title:      text('title').notNull().default(''),
  body:       text('body').notNull().default(''),
  pinned:     integer('pinned', { mode: 'boolean' }).notNull().default(false),
  createdAt:  integer('created_at', { mode: 'timestamp' }).notNull(),
  updatedAt:  integer('updated_at', { mode: 'timestamp' }).notNull(),
})

Queries

import { drizzleDb } from './db'
import * as schema from './schema'
import { desc, eq, like } from 'drizzle-orm'
 
// Select all
const allNotes = await drizzleDb.select().from(schema.notes).orderBy(desc(schema.notes.updatedAt))
 
// Select one
const note = await drizzleDb.select().from(schema.notes).where(eq(schema.notes.id, 42)).get()
 
// Insert
const [created] = await drizzleDb.insert(schema.notes)
  .values({ title: 'Hello', createdAt: new Date(), updatedAt: new Date() })
  .returning()
 
// Update
await drizzleDb.update(schema.notes)
  .set({ title: 'Updated', updatedAt: new Date() })
  .where(eq(schema.notes.id, 42))
 
// Delete
await drizzleDb.delete(schema.notes).where(eq(schema.notes.id, 42))
 
// Search
const results = await drizzleDb.select().from(schema.notes)
  .where(like(schema.notes.title, '%hello%'))

Migrations

Use db.migrate() for schema migrations — not Drizzle's migration runner (which requires a file system). Run migrations before calling createDrizzle:

import { db } from '@glyx-dev/react'
import { createDrizzle } from '@glyx-dev/drizzle'
import * as schema from './schema'
 
await db.migrate([
  {
    version: 1,
    name: 'create_notes',
    up: `CREATE TABLE notes (
      id         INTEGER PRIMARY KEY AUTOINCREMENT,
      title      TEXT NOT NULL DEFAULT '',
      body       TEXT NOT NULL DEFAULT '',
      pinned     INTEGER NOT NULL DEFAULT 0,
      created_at INTEGER NOT NULL DEFAULT (unixepoch()),
      updated_at INTEGER NOT NULL DEFAULT (unixepoch())
    )`,
  },
])
 
const handle = await db.open('app.db')
export const drizzleDb = createDrizzle(handle, schema)

Notes

  • @glyx-dev/drizzle uses Drizzle's sqlite-proxy driver internally — async queries only.
  • The .query.* relational API is available if you pass schema to createDrizzle.
  • All queries go through Glyx's native SQLite binding — no Node.js better-sqlite3 required.