0.1.0 • Published 2 years ago

pg-query-tag v0.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

pg-query-tag

Install

npm install pg
npm install pg-query-tag

get help with typescript

npm install -D @types/pg

Usage

init query tag

set global pool then you can use query tag everywhere

import {Pool} from 'pg';
import {query, setPool, transaction} from 'pg-query-tag';

const pool = new Pool({
    connectionString: 'postgres://postgres:postgres@localhost:5432/postgres',
})
// setPool before use query
setPool(pool);
// or set pool and schema
setPool(pool, 'public');

or just create a query tag

import {createQuery} from 'pg-query-tag';

const query = createQuery('postgres://postgres:postgres@localhost:5432/postgres')

const id = 1;
const result = await query`select * from users where id = ${id}`;
console.log(result.rows)
await query.client.end()

use transaction

//...
const id = 1;
const name = 'user1';
const result = await transaction(async (query) => {
    await query`insert into users (id,name) values (${id},${name})`;
    return await query`select * from users where id = ${id}`;
});
console.log(result.rows)
0.1.0

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago