0.0.25 • Published 12 months ago

qustar-pg v0.0.25

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

qustar-pg

PostgreSQL support for qustar via pg package.

Installation

To start using pg with qustar you need to install the following packages:

npm install qustar qustar-pg pg

Usage

Here is a minimal example:

import {Q} from 'qustar';
import {PgConnector} from 'qustar-pg';

// create a connector for PostgreSQL database
const connector = new PgConnector(
  'postgresql://user:password@localhost:5432/qustar'
);

// construct a query
const query = Q.table({
  name: 'users',
  schema: {
    id: Q.i32(),
  },
});

// run the query using the connector
const users = await query.fetch(connector);

// use the result
console.log(users);

// close the connector
await connector.close();

You can also create PgConnector by passing an instance of a pg pool:

import {Pool} from 'pg';
import {PgConnector} from 'qustar-pg';

const pool = new Pool({
  database: 'qustar',
  port: 5432,
  user: 'user',
  password: 'password',
  host: 'localhost',
});

const connector = new PgConnector(pool);

But usually it's more convenient to pass pool options directly to the connector:

import {PgConnector} from 'qustar-pg';

// connector will pass the options to pg
const connector = new PgConnector({
  database: 'qustar',
  port: 5432,
  user: 'user',
  password: 'password',
  host: 'localhost',
});

You can run raw SQL using a connector:

// execute a statement
await connector.execute('INSERT INTO users VALUES (42);');

// run a query
await connector.query('SELECT 42 as meaning');

// run a parametrized query
await connector.query({
  sql: 'SELECT id FROM users WHERE id = $1',
  args: [42],
});

License

MIT License, see LICENSE.

0.0.25

12 months ago

0.0.24

12 months ago

0.0.23

12 months ago

0.0.22

12 months ago

0.0.21

12 months ago

0.0.20

12 months ago

0.0.19

12 months ago

0.0.18

12 months ago

0.0.17

12 months ago

0.0.16

12 months ago

0.0.15

12 months ago

0.0.14

12 months ago

0.0.13

12 months ago

0.0.12

12 months ago

0.0.11

12 months ago

0.0.10

12 months ago

0.0.9

12 months ago

0.0.8

12 months ago

0.0.7

12 months ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago