|
1 | 1 | <div align="center"> |
2 | 2 | <img src="./assets/vorsteh-queue-logo-nobg.png" alt="Vorsteh Queue" height="200" /> |
3 | 3 | <h1>Vorsteh Queue</h1> |
4 | | - <p>A powerful, ORM-agnostic queue engine that works with any orm. Handle background jobs, scheduled tasks, and recurring processes with ease.</p> |
| 4 | + <p>A powerful, ORM-agnostic queue engine for PostgreSQL 12+. Handle background jobs, scheduled tasks, and recurring processes with ease.</p> |
5 | 5 | </div> |
6 | 6 |
|
7 | 7 | ## Features |
8 | 8 |
|
9 | 9 | - **Type-safe**: Full TypeScript support with generic job payloads |
10 | | -- **Multiple adapters**: Drizzle ORM (PostgreSQL + MariaDB/MySQL) and in-memory implementations |
| 10 | +- **Multiple adapters**: Drizzle ORM (PostgreSQL), Prisma ORM (PostgreSQL), and in-memory implementations |
11 | 11 | - **Priority queues**: Numeric priority system (lower = higher priority) |
12 | 12 | - **Delayed jobs**: Schedule jobs for future execution |
13 | 13 | - **Recurring jobs**: Cron expressions and interval-based repetition |
|
22 | 22 | . |
23 | 23 | ├── packages/ |
24 | 24 | │ ├── core/ # Core queue logic and interfaces |
25 | | -│ ├── adapter-drizzle/ # Drizzle ORM adapter (PostgreSQL + MariaDB/MySQL) |
26 | | -│ └── adapter-prisma/ # Prisma adapter (coming soon) |
| 25 | +│ ├── adapter-drizzle/ # Drizzle ORM adapter (PostgreSQL) |
| 26 | +│ └── adapter-prisma/ # Prisma ORM adapter (PostgreSQL) |
27 | 27 | ├── examples/ # Standalone usage examples |
28 | 28 | │ ├── drizzle-pg/ # Drizzle + node-postgres |
29 | 29 | │ ├── drizzle-postgres/ # Drizzle + postgres.js |
@@ -53,40 +53,53 @@ pnpm add @vorsteh-queue/core @vorsteh-queue/adapter-drizzle |
53 | 53 | ### Basic Usage |
54 | 54 |
|
55 | 55 | ```typescript |
56 | | -// PostgreSQL |
| 56 | +// Drizzle ORM with PostgreSQL |
57 | 57 | import { drizzle } from "drizzle-orm/node-postgres" |
58 | 58 | import { Pool } from "pg" |
59 | 59 | import { PostgresQueueAdapter } from "@vorsteh-queue/adapter-drizzle" |
60 | 60 | import { Queue } from "@vorsteh-queue/core" |
61 | 61 |
|
| 62 | +interface EmailPayload { |
| 63 | + to: string |
| 64 | + subject: string |
| 65 | + body: string |
| 66 | +} |
| 67 | + |
| 68 | +interface EmailResult { |
| 69 | + messageId: string |
| 70 | + sent: boolean |
| 71 | +} |
| 72 | + |
62 | 73 | const pool = new Pool({ connectionString: "postgresql://..." }) |
63 | 74 | const db = drizzle(pool) |
64 | | -const adapter = new PostgresQueueAdapter(db, "my-queue") |
65 | | -const queue = new Queue(adapter, { name: "my-queue" }) |
66 | | - |
67 | | -// MariaDB/MySQL |
68 | | -import { drizzle } from "drizzle-orm/mysql2" |
69 | | -import mysql from "mysql2/promise" |
70 | | -import { MariaDBQueueAdapter } from "@vorsteh-queue/adapter-drizzle" |
71 | | - |
72 | | -const connection = await mysql.createConnection({ |
73 | | - host: "localhost", |
74 | | - user: "root", |
75 | | - password: "password", |
76 | | - database: "queue_db", |
77 | | -}) |
78 | | -const db = drizzle(connection, { mode: "default" }) |
79 | | -const adapter = new MariaDBQueueAdapter(db, "my-queue") |
80 | | -const queue = new Queue(adapter, { name: "my-queue" }) |
| 75 | +const queue = new Queue(new PostgresQueueAdapter(db), { name: "my-queue" }) |
| 76 | + |
| 77 | +// Prisma ORM with PostgreSQL |
| 78 | +import { PrismaClient } from "@prisma/client" |
| 79 | +import { PostgresPrismaQueueAdapter } from "@vorsteh-queue/adapter-prisma" |
| 80 | + |
| 81 | +const prisma = new PrismaClient() |
| 82 | +const queue = new Queue(new PostgresPrismaQueueAdapter(prisma), { name: "my-queue" }) |
81 | 83 |
|
82 | 84 | // Register job handlers |
83 | | -queue.register("send-email", async (payload: { to: string; subject: string }) => { |
84 | | - // Send email logic |
85 | | - return { sent: true } |
| 85 | +queue.register<EmailPayload, EmailResult>("send-email", async (job) => { |
| 86 | + console.log(`Sending email to ${job.payload.to}`) |
| 87 | + |
| 88 | + // Send email logic here |
| 89 | + await sendEmail(job.payload) |
| 90 | + |
| 91 | + return { |
| 92 | + messageId: "msg_123", |
| 93 | + sent: true |
| 94 | + } |
86 | 95 | }) |
87 | 96 |
|
88 | 97 | // Add jobs |
89 | | -await queue. add( "send-email", { to: "[email protected]", subject: "Welcome!" }) |
| 98 | +await queue.add("send-email", { |
| 99 | + |
| 100 | + subject: "Welcome!", |
| 101 | + body: "Welcome to our service!" |
| 102 | +}) |
90 | 103 | await queue.add( |
91 | 104 | "send-email", |
92 | 105 | { to: "[email protected]", subject: "Report" }, |
|
0 commit comments