Getting Started
Unconventional Queries is a tiny query builder for the pg library. Perfect for edge workers with size limits, such as Cloudflare Workers, where every line of code counts. Unlock the utility of your Postgres DB, minimize bloat, and never write a line of SQL manually again!
Getting started is easy. Simply install the package, initialize your client, and execute a query:
Installation
npm i unconventional-pg-queriesnpm i unconventional-pg-queriesyarn add unconventional-pg-queriesyarn add unconventional-pg-queriespnpm add unconventional-pg-queriespnpm add unconventional-pg-queriesCreate Client
Each query accepts a pg client, which it uses to execute the call to your database. Start by initializing and opening a connection from this client:
ts
import { Client } from 'pg';
const client = new Client({
host: <host>,
user: <user>,
password: <password>,
database: <database>,
port: <port>,
ssl: true
});
await client.connect();import { Client } from 'pg';
const client = new Client({
host: <host>,
user: <user>,
password: <password>,
database: <database>,
port: <port>,
ssl: true
});
await client.connect();Execute Query
Then pass your client to any of the supported action methods with a query definition. The example below selects the first row of the public.users table.
ts
import { selectOne, SqlWhereOperator } from 'unconventional-pg-queries';
const response = await selectOne(client, {
table: 'public.users',
where: [{ field: 'id', operator: SqlWhereOperator.Eq, value: 1 }]
});import { selectOne, SqlWhereOperator } from 'unconventional-pg-queries';
const response = await selectOne(client, {
table: 'public.users',
where: [{ field: 'id', operator: SqlWhereOperator.Eq, value: 1 }]
});That's it! You're now ready to go!