Waddler <> PostgreSQL

This guide assumes familiarity with:

Waddler has native support for PostgreSQL connections with the node-postgres and postgres.js drivers.

There are a few differences between the node-postgres and postgres.js drivers that we discovered while using both and integrating them with the Waddler. For example:

node-postgres

Step 1 - Install packages

npm
yarn
pnpm
bun
npm i waddler pg
npm i -D @types/pg

Step 2 - Initialize the driver and make a query

node-postgres
node-postgres with config
import 'dotenv/config';
import { waddler } from 'waddler/node-postgres';

const sql = waddler(process.env.DATABASE_URL!);
const result = await sql`select 1;`;

If you need to provide your existing driver:

with existing driver
with pg-query-stream extension
// Make sure to install the 'pg' package 
import { waddler } from "waddler/node-postgres";
import pg from 'pg';

const { Pool } = pg;

const pool = new Pool({
  connectionString: process.env.DATABASE_URL,
});
const sql = waddler({ client: pool });
 
const result = await sql`select 1;`;

postgres.js

Step 1 - Install packages

npm
yarn
pnpm
bun
npm i waddler postgres

Step 2 - Initialize the driver and make a query

postgres.js
postgres.js with config
import { waddler } from 'waddler/postgres-js';

const sql = waddler(process.env.DATABASE_URL);

const result = await sql`select 1;`;

If you need to provide your existing driver:

// Make sure to install the 'postgres' package
import { waddler } from 'waddler/postgres-js';
import postgres from 'postgres';

const queryClient = postgres(process.env.DATABASE_URL);
const sql = waddler({ client: queryClient });

const result = await sql`select 1;`;