@zugriff/postgres
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@zugriff/postgres

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.

Usage

npm i --save @zugriff/postgres

Creating a client

import { Postgres } from '@zugriff/postgres';

const client = new Postgres(
  process.env.ZUGRIFF_POSTGRES_TOKEN || {
    host: 'localhost',
    port: 5432,
    username: 'root',
    password: 'root',
    database: 'zugriff',
  }
);

Executing a stament

// 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' }})
`;

Querying the database

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" }}] }

Package Sidebar

Install

npm i @zugriff/postgres

Weekly Downloads

4

Version

1.0.1

License

MIT

Unpacked Size

23.7 kB

Total Files

8

Last publish

Collaborators

  • lucagoslar