Skip to main content
Problem: you have an external PostgreSQL (or other SQL) database and want to sync its rows into a context, fetching only records changed since the last run. Prerequisite: read Data sources and sync first — this recipe assumes you know the ExuluContextSource shape and ExuluItem fields.

Complete source listing

This example uses knex with the pg driver, which is already a dependency of @exulu/backend. Create the pool once at module scope so it is reused across source runs.
src/integrations/product-catalog/source.ts
Attach the source to a context:
src/contexts/index.ts

Key points

Connection string alternative

If you prefer a connection string over individual options, knex accepts one:
Store the connection string in an IMP variable and read it from process.env.

Incremental sync deep dive

Upsert matching, hash checks, and deletion semantics explained.

API sync — ticketing

Paginated REST source with rate-limit handling.

Data sources and sync tutorial

The full tutorial introducing sources and the ExuluContextSource shape.