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

@magnet-cms/adapter-db-drizzle

v4.0.0

Published

Drizzle ORM database adapter for Magnet CMS - supports PostgreSQL, MySQL, and SQLite

Downloads

389

Readme

@magnet-cms/adapter-db-drizzle

Drizzle ORM database adapter for Magnet CMS. Supports PostgreSQL, MySQL, and SQLite through Drizzle ORM.

Installation

# Install the adapter
bun add @magnet-cms/adapter-db-drizzle drizzle-orm

# For PostgreSQL
bun add pg
# or for Neon serverless
bun add @neondatabase/serverless

# For MySQL
bun add mysql2

# For SQLite
bun add better-sqlite3

Usage

Basic Setup

import { MagnetModule } from '@magnet-cms/core'
import { Module } from '@nestjs/common'

@Module({
  imports: [
    MagnetModule.forRoot({
      db: {
        connectionString: process.env.DATABASE_URL,
        dialect: 'postgresql',
      },
      jwt: {
        secret: process.env.JWT_SECRET,
      },
    }),
  ],
})
export class AppModule {}

With Neon (Serverless PostgreSQL)

MagnetModule.forRoot({
  db: {
    connectionString: process.env.NEON_DATABASE_URL,
    dialect: 'postgresql',
    driver: 'neon', // Use Neon serverless driver
  },
  jwt: {
    secret: process.env.JWT_SECRET,
  },
})

Defining Schemas

Use the same @Schema() and @Prop() decorators from @magnet-cms/common:

import { Schema, Prop } from '@magnet-cms/common'

@Schema()
export class Article {
  @Prop({ required: true, intl: true })
  title!: string

  @Prop({ intl: true })
  content?: string

  @Prop({ required: true, unique: true })
  slug!: string

  @Prop({ type: Boolean, default: false })
  featured?: boolean
}

The adapter automatically generates Drizzle table schemas from these decorators.

Configuration Options

| Option | Type | Description | |--------|------|-------------| | connectionString | string | Database connection URL | | dialect | 'postgresql' \| 'mysql' \| 'sqlite' | SQL dialect to use | | driver | 'pg' \| 'neon' \| 'mysql2' \| 'better-sqlite3' | Database driver (auto-detected) | | debug | boolean | Enable query logging |

i18n and Versioning

Like the Mongoose adapter, this adapter supports document-based i18n and versioning. Each document can have multiple locale variants stored in the same table:

-- Auto-generated table structure
CREATE TABLE articles (
  id UUID PRIMARY KEY,
  document_id UUID NOT NULL,      -- Groups locale variants
  locale VARCHAR(10) DEFAULT 'en',
  status VARCHAR(20) DEFAULT 'draft',
  published_at TIMESTAMP,
  title TEXT NOT NULL,
  content TEXT,
  slug VARCHAR(255),
  featured BOOLEAN DEFAULT false,
  created_at TIMESTAMP DEFAULT NOW(),
  updated_at TIMESTAMP DEFAULT NOW(),
  UNIQUE(document_id, locale, status)
);

Query Builder

The adapter provides a fluent query builder with MongoDB-style operators:

const articles = await articleModel.query()
  .where({ status: 'active', views: { $gte: 100 } })
  .sort({ createdAt: -1 })
  .limit(10)
  .exec()

Supported Operators

| Operator | SQL Equivalent | |----------|---------------| | $eq | = | | $ne | <> | | $gt | > | | $gte | >= | | $lt | < | | $lte | <= | | $in | IN (...) | | $nin | NOT IN (...) | | $regex | ILIKE '%...%' | | $like | LIKE | | $ilike | ILIKE |

Native Access

For advanced queries, you can access the native Drizzle instance:

const { db, table } = articleModel.native()

// Use Drizzle directly
const results = await db
  .select()
  .from(table)
  .where(sql`${table.views} > 1000`)

License

MIT