https://github.com/fbn/pg-tuple-types
composite tuple types support for node-postgres
https://github.com/fbn/pg-tuple-types
Last synced: about 1 year ago
JSON representation
composite tuple types support for node-postgres
- Host: GitHub
- URL: https://github.com/fbn/pg-tuple-types
- Owner: FbN
- Created: 2022-04-27T20:19:19.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-04-28T06:54:33.000Z (about 4 years ago)
- Last Synced: 2025-03-08T11:33:50.198Z (over 1 year ago)
- Language: JavaScript
- Size: 432 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
pg-tuple-types
========
Add node-postgres support for:
* composite tuples
* arrays of tuples
## Installing
```
$ yarn add pg-tuple-types
```
## Usage
```js
import pg from 'pg'
import { initTypes } from 'pg-tuple-types'
const { Client } = pg
const sql = new Client()
sql.connect()
;(async () => {
// load types definitions from DB schema
await initTypes(pg.types)(sql)
const customer = await sql.query(`select
customer._c,
array_agg(cart)
from
(
select
customer _c
from
customer
limit 2) customer
join cart on
(cart.customer_id = (customer._c).id)
group by
customer._c`)
console.log(JSON.stringify(customer.rows, null, ' '))
})().finally(() => sql.end())
```
## License
Copyright © 2022 [Fabiano Taioli](http://fbn.github.io/);
Released under the MIT license.