1.1.1 • Published 3 months ago

@sncutils/db v1.1.1

Weekly downloads
-
License
GPL-3.0-only
Repository
github
Last release
3 months ago

@sncutils/db

Setup and utilize postgresql database with ease.

Installation

% bun i @sncutils/db

Basic Usage

import { init_pool, pool, query } from '@sncutils/db';

const initial_script = `
create table if not exists list (
	id int not null primary key,
	value text not null
);
`;

await init_pool({
	auth: {
		host: 'localhost',
		port: 5432,
		user: 'test',
		password: 'test',
		database: 'test',
	},
	initial_script,
	max: 1000, // maximum number of clients in the pool
});

async function get_some(ids: number[]) {
	// `using` automatically releases the connection once the block is exited
	using conn = await pool.connect(); 
	return query(conn, 'select * from list where id = any($1)', [ids]);
}

let list = await get_some([1, 2, 3]);
console.log(list);
1.1.1

3 months ago

1.1.0

3 months ago

1.0.0

6 months ago