This package is part of the zugriff ecosystem. It runs on both Edge Runtimes using the fetch
API and your machine using the fetch
API or the postgres
package.
npm i --save @zugriff/postgres
import { Postgres } from '@zugriff/postgres';
const client = new Postgres(
process.env.ZUGRIFF_POSTGRES_TOKEN || {
host: 'localhost',
port: 5432,
username: 'root',
password: 'root',
database: 'zugriff',
}
);
// Prepare the database
await client.execute`
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
created TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
name VARCHAR(256),
age INTEGER,
misc JSON
)
`;
// Insert a user
await client.execute`
INSERT INTO users (name, age, misc)
VALUES (${'Luca'}, ${1}, ${{ hello: 'world' }})
`;
let user = client.query<{
name: string;
age: number;
misc: Object;
}>`
SELECT name, age, misc
FROM users
WHERE
name=${'Luca'}
`;
// { anchor: "id", success: [{name: "Luca", age: 1, misc: { hello: "world" }}] }