|
| 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 |
0 commit comments