Skip to content

Commit 40ff12d

Browse files
authored
Merge pull request #19 from noxify/adapter-kysely
add kysely adapter
2 parents 7b75263 + 8be17ad commit 40ff12d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+4132
-1796
lines changed

.changeset/funny-cobras-sneeze.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
"@vorsteh-queue/adapter-kysely": minor
3+
---
4+
5+
Add Kysely ORM adapter for PostgreSQL with type-safe database operations
6+
7+
**Features:**
8+
9+
- `PostgresQueueAdapter`: PostgreSQL support using Kysely ORM
10+
- Raw SQL with `SKIP LOCKED` for race condition prevention
11+
- UTC-first design with proper timezone handling
12+
- Database schema uses UTC defaults: `timezone('utc', now())` for PostgreSQL
13+
- All timestamps explicitly stored as UTC for consistent behavior
14+
15+
**Usage:**
16+
17+
```typescript
18+
import { Kysely, PostgresDialect } from "kysely"
19+
import { Pool } from "pg"
20+
21+
import { PostgresQueueAdapter } from "@vorsteh-queue/adapter-kysely"
22+
import { Queue } from "@vorsteh-queue/core"
23+
24+
const db = new Kysely({
25+
dialect: new PostgresDialect({
26+
pool: new Pool({ connectionString: "postgresql://..." }),
27+
}),
28+
})
29+
30+
const adapter = new PostgresQueueAdapter(db)
31+
const queue = new Queue(adapter, { name: "my-queue" })
32+
33+
// Register job handlers
34+
queue.register("send-email", async (payload: { to: string }) => {
35+
// Send email logic
36+
return { sent: true }
37+
})
38+
39+
// Add jobs
40+
await queue.add("send-email", { to: "[email protected]" })
41+
42+
// Start processing
43+
queue.start()
44+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vorsteh-queue/adapter-drizzle": patch
3+
---
4+
5+
Add `PostgresQueueAdapter` as alias to `PostgresDrizzleQueueAdapter`
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vorsteh-queue/adapter-prisma": patch
3+
---
4+
5+
Add `PostgresQueueAdapter` as alias to `PostgresPrismaQueueAdapter`

.changeset/loose-parrots-glow.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"create-vorsteh-queue": patch
3+
"@vorsteh-queue/adapter-drizzle": patch
4+
"@vorsteh-queue/adapter-prisma": patch
5+
"@vorsteh-queue/core": patch
6+
---
7+
8+
update dependencies

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -311,19 +311,20 @@ This project was developed with AI assistance, combining human expertise with AI
311311
# Install dependencies
312312
pnpm install
313313

314-
# Run all tests
315-
pnpm test
314+
# Autofix format issues
315+
pnpm format:fix
316+
317+
# Fix issues in the `package.json` ( order, version mismatch )
318+
pnpm lint:ws -f
316319

317-
# Run specific test suites
318-
pnpm test:core # Core package tests
319-
pnpm test:drizzle-postgres # PostgreSQL adapter tests
320-
pnpm test:drizzle-mariadb # MariaDB adapter tests
320+
# Lint
321+
pnpm lint
321322

322323
# Type check
323324
pnpm typecheck
324325

325-
# Lint
326-
pnpm lint
326+
# Run all tests
327+
pnpm test
327328

328329
# Build packages
329330
pnpm build

apps/docs/content/docs/01.getting-started/01.introduction.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Vorsteh Queue is a powerful, type-safe queue engine designed for PostgreSQL 12+.
88
## Key Features
99

1010
- **Type-safe**: Full TypeScript support with generic job payloads
11-
- **Multiple adapters**: Drizzle ORM (PostgreSQL), Prisma ORM (PostgreSQL), and in-memory implementations
11+
- **Multiple adapters**: Drizzle ORM (PostgreSQL), Prisma ORM (PostgreSQL), Kysely (PostgreSQL) and in-memory implementations
1212
- **Priority queues**: Numeric priority system (lower = higher priority)
1313
- **Delayed jobs**: Schedule jobs for future execution
1414
- **Recurring jobs**: Cron expressions and interval-based repetition

apps/docs/content/docs/01.getting-started/02.installation.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,20 @@ If you prefer to add Vorsteh Queue to an existing project:
5353
className={{ container: "not-prose", code: "not-prose" }}
5454
/>
5555

56+
### Prisma ORM (PostgreSQL)
57+
58+
<PackageInstall
59+
packages={["@vorsteh-queue/core", "@vorsteh-queue/adapter-kysely"]}
60+
className={{ container: "not-prose", code: "not-prose" }}
61+
/>
62+
5663
## Database Setup
5764

5865
After installation, you'll need to set up the required database tables. Each adapter provides migration scripts or schema definitions:
5966

6067
- **Drizzle**: Use the provided schema and run migrations
6168
- **Prisma**: Add the schema to your `schema.prisma` and run `prisma migrate`
69+
- **Kysely**: Use the provided schema and run migrations
6270

6371
Refer to the specific adapter documentation for detailed setup instructions.
6472

apps/docs/content/docs/02.packages/adapter-drizzle.mdx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,9 @@ If you don't want to use the pre-defined schema, you can create your own schema
5555

5656
### Migration
5757

58-
Push the schema to your database:
58+
To run the migrations, we recommend to use [`drizzle-kit`](https://orm.drizzle.team/docs/kit-overview).
5959

60-
```bash
61-
npx drizzle-kit push
62-
```
63-
64-
Or generate and run migrations:
65-
66-
```bash
67-
npx drizzle-kit generate
68-
npx drizzle-kit migrate
69-
```
60+
> Drizzle Kit is a CLI tool for managing SQL database migrations with Drizzle.
7061
7162
## References
7263

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: Kysely Adapter
3+
navTitle: "@vorsteh-queue/adapter-kysely"
4+
description: Kysely adapter for PostgreSQL providing type-safe database operations with excellent performance.
5+
---
6+
7+
The Kysely adapter provides PostgreSQL support using Kysely, offering excellent TypeScript integration and performance.
8+
9+
## Installation
10+
11+
<PackageInstall packages={["@vorsteh-queue/core", "@vorsteh-queue/adapter-kysely"]} />
12+
13+
## Quick Start
14+
15+
```typescript
16+
import { Kysely } from "kysely"
17+
import { PostgresJSDialect } from "kysely-postgres-js"
18+
import postgres from "postgres"
19+
20+
import type { QueueJobTableDefinition } from "@vorsteh-queue/adapter-kysely/types"
21+
import { PostgresQueueAdapter } from "@vorsteh-queue/adapter-kysely"
22+
import { Queue } from "@vorsteh-queue/core"
23+
24+
interface DB {
25+
queue_jobs: QueueJobTableDefinition
26+
other_table: {
27+
name: string
28+
}
29+
}
30+
31+
// Shared database connection
32+
const client = postgres(
33+
process.env.DATABASE_URL || "postgresql://postgres:password@localhost:5432/queue_db",
34+
{ max: 10 }, // Connection pool
35+
)
36+
37+
const db = new Kysely<DB>({
38+
dialect: new PostgresJSDialect({
39+
postgres: client,
40+
}),
41+
})
42+
43+
const adapter = new PostgresQueueAdapter(db)
44+
const queue = new Queue(adapter)
45+
```
46+
47+
## Supported providers
48+
49+
- PGlite
50+
- Postgres.JS
51+
- Node Progress
52+
53+
## Database Setup
54+
55+
### Schema
56+
57+
The adapter includes a pre-defined migration:
58+
59+
```typescript
60+
// migrations/queue-jobs.ts
61+
import { down, up } from "@vorsteh-queue/adapter-kysely/migrations"
62+
63+
// Use in your schema file
64+
export { up, down }
65+
```
66+
67+
If you don't want to use the pre-defined schema, you can create your own migration.
68+
69+
<RemoteCodeBlock
70+
source="./packages/adapter-kysely/src/migrations/queue_table.ts"
71+
language="ts"
72+
showToolbar={true}
73+
path="queue-jobs.ts"
74+
/>
75+
76+
### Migration
77+
78+
To run the migrations, we recommend to use [`kysely-ctl`](https://github.com/kysely-org/kysely-ctl).
79+
80+
> `kysely-ctl` is the command-line tool for Kysely.
81+
82+
## References
83+
84+
- Sources: https://github.com/noxify/vorsteh-queue/tree/main/packages/adapter-kysely
85+
- NPM: https://www.npmjs.com/package/@vorsteh-queue/adapter-kysely

apps/docs/content/docs/02.packages/adapter-prisma.mdx

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,9 @@ Add the queue job model to your `schema.prisma`:
3939

4040
### Migration
4141

42-
Push the schema to your database:
42+
To run the migrations, we recommend to use the [`prisma cli`](https://www.prisma.io/docs/orm/tools/prisma-cli).
4343

44-
```bash
45-
npx prisma db push
46-
```
47-
48-
Or generate and apply the migration:
49-
50-
```bash
51-
npx prisma migrate dev --name add-queue-jobs
52-
```
53-
54-
### Generate Client
55-
56-
Generate the Prisma client:
57-
58-
```bash
59-
npx prisma generate
60-
```
44+
> The Prisma command line interface (CLI) is the primary way to interact with your Prisma project from the command line.
6145
6246
## References
6347

0 commit comments

Comments
 (0)