@vorsteh-queue/adapter-drizzle
v0.5.0
Published
Drizzle ORM adapter for Vorsteh Queue with PostgreSQL support
Downloads
17
Maintainers
Readme
@vorsteh-queue/adapter-drizzle
Drizzle ORM adapter for Vorsteh Queue supporting PostgreSQL databases.
Features
- PostgreSQL Support: Full PostgreSQL compatibility with PGlite, node-postgres, and postgres.js
- Type Safety: Full TypeScript support with Drizzle ORM
- SKIP LOCKED: Concurrent job processing without lock contention
- JSON Payloads: Complex data structures with proper serialization
- UTC-First: All timestamps stored as UTC for reliable timezone handling
Requirements
- Node.js 20+
- PostgreSQL 12+ (for SKIP LOCKED support)
- ESM only - This package is ESM-only and cannot be imported with
require()
Installation
npm install @vorsteh-queue/adapter-drizzle drizzle-orm
# or
pnpm add @vorsteh-queue/adapter-drizzle drizzle-ormNote: Make sure your project has
"type": "module"in package.json or use.mjsfile extensions.
Usage
import { drizzle } from "drizzle-orm/node-postgres"
import { Pool } from "pg"
import { PostgresQueueAdapter } from "@vorsteh-queue/adapter-drizzle"
import { Queue } from "@vorsteh-queue/core"
// Setup PostgreSQL connection
const pool = new Pool({
connectionString: "postgresql://user:password@localhost:5432/database",
})
const db = drizzle(pool)
interface EmailPayload {
to: string
subject: string
body: string
}
interface EmailResult {
messageId: string
sent: boolean
}
// Create adapter and queue
const adapter = new PostgresQueueAdapter(db)
const queue = new Queue(adapter, { name: "my-queue" })
// Register job handlers
queue.register<EmailPayload, EmailResult>("send-email", async (job) => {
console.log(`Sending email to ${job.payload.to}`)
// Send email logic here
await sendEmail(job.payload)
return {
messageId: "msg_123",
sent: true,
}
})
// Add jobs
await queue.add("send-email", {
to: "[email protected]",
subject: "Welcome!",
body: "Welcome to our service!",
})
// Start processing
queue.start()Schema Setup
Using Drizzle Schemas (Recommended)
import { drizzle } from "drizzle-orm/node-postgres"
import { postgresSchema } from "@vorsteh-queue/adapter-drizzle"
const db = drizzle(pool, { schema: postgresSchema })Using Drizzle Kit Migrations
// src/schema/index.ts - Your application schema
import { pgTable, serial, varchar } from "drizzle-orm/pg-core"
import { postgresSchema } from "@vorsteh-queue/adapter-drizzle"
// Your existing tables
export const users = pgTable("users", {
id: serial("id").primaryKey(),
name: varchar("name", { length: 255 }),
})
// Export queue schema alongside your schema
export const queueJobs = postgresSchema.queueJobs# Generate and run migrations
npx drizzle-kit generate
npx drizzle-kit migrateSupported PostgreSQL Drivers
- node-postgres (
pg) - postgres.js (
postgres) - PGlite (for embedded/testing)
Testing
pnpm testLicense
MIT License - see LICENSE file for details.
