
<p style="text-align: center;">
  <img src="https://sqb.panates.com/img/github-hero.webp" width="1280" alt="SQB" />
</p>

<br>

[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![CI Tests][ci-test-image]][ci-test-url]
[![Test Coverage][coveralls-image]][coveralls-url]

## About SQB

SQB is an extensible, multi-dialect SQL query builder and Database connection wrapper for NodeJS.

## About @sqb/postgres

This package is a SQB `Adapter` for PostgreSQL, backed by [`postgrejs`](https://github.com/panates/postgrejs),
a pure-JS driver with no native bindings. It supports cursors, working schemas, and fetching
`date`/`timestamp` columns as raw strings instead of `Date` objects (`fetchAsString`).

Since Postgres supports `RETURNING` natively on `INSERT`, `UPDATE` and `DELETE`,
`INSERT ... RETURNING` / `UPDATE ... RETURNING` need no follow-up `SELECT` — affected rows are
read directly from the statement response, the same as every other query.

## Installation

```bash
$ npm install @sqb/postgres --save
```

## Usage

```ts
import '@sqb/postgres';
import { SqbClient } from '@sqb/connect';

const client = new SqbClient({
  driver: 'postgrejs',
  host: 'localhost',
  port: 5432,
  user: 'postgres',
  database: 'mydb',
});
```

## Node Compatibility

- node >= 20.x

### License

SQB is available under [MIT](LICENSE) license.

[npm-image]: https://img.shields.io/npm/v/@sqb/postgres.svg
[npm-url]: https://npmjs.org/package/@sqb/postgres
[downloads-image]: https://img.shields.io/npm/dm/@sqb/postgres.svg
[downloads-url]: https://npmjs.org/package/@sqb/postgres
[ci-test-image]: https://github.com/panates/sqb/actions/workflows/test.yml/badge.svg
[ci-test-url]: https://github.com/panates/sqb/actions/workflows/test.yml
[coveralls-image]: https://coveralls.io/repos/github/sqbjs/sqb/badge.svg?branch=master
[coveralls-url]: https://coveralls.io/github/sqbjs/sqb?branch=master
