@pidgeyjs/next
v0.2.0
Published
Next.js integration for Pidgey
Readme
@pidgeyjs/next
Next.js integration for Pidgey with batteries-included configuration helpers.
Installation
pnpm add @pidgeyjs/next @pidgeyjs/coreYou'll also need an adapter:
# For PostgreSQL
pnpm add @pidgeyjs/postgres pg
# For SQLite
pnpm add @pidgeyjs/sqlite better-sqlite3
# For Redis
pnpm add @pidgeyjs/redis bullmq ioredisQuick Start
1. Initialize the Client
Create a Pidgey client using the Pidgey() helper in lib/pidgey.ts:
import { Pidgey } from '@pidgeyjs/next';
export const pidgey = Pidgey({
adapter: 'sqlite',
});Smart Defaults: If you don't provide a config, Pidgey uses SQLite in development and throws an error in production (forcing you to configure it properly).
2. Define Jobs
Create job handlers in your app:
// jobs/email.ts
import { pidgey } from '@/lib/pidgey';
export const sendEmailJob = pidgey.defineJob({
name: 'send-email',
handler: async (data: { to: string; subject: string }) => {
console.log(`Sending email to ${data.to}`);
// Send email logic here
return { sent: true };
},
});3. Enqueue Jobs
Use the job definition to enqueue work:
// app/api/register/route.ts
import { sendEmailJob } from '@/jobs/email';
export async function POST() {
await sendEmailJob.enqueue({
to: '[email protected]',
subject: 'Welcome!',
});
return Response.json({ success: true });
}Adapter Configuration
PostgreSQL
import { Pidgey } from '@pidgeyjs/next';
export const pidgey = Pidgey({
adapter: 'postgres',
connection: process.env.DATABASE_URL!,
});SQLite
import { Pidgey } from '@pidgeyjs/next';
export const pidgey = Pidgey({
adapter: 'sqlite',
filename: './dev.db', // defaults to ':memory:'
});Redis
import { Pidgey } from '@pidgeyjs/next';
export const pidgey = Pidgey({
adapter: 'redis',
options: {
host: 'localhost',
port: 6379,
},
});Running Workers
See the @pidgeyjs/cli package for running background workers.
License
MIT
