https://github.com/pyramation/pg-query-string
sql query string builder
https://github.com/pyramation/pg-query-string
Last synced: about 1 year ago
JSON representation
sql query string builder
- Host: GitHub
- URL: https://github.com/pyramation/pg-query-string
- Owner: pyramation
- License: mit
- Created: 2020-09-22T03:58:55.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-10-02T06:08:15.000Z (over 5 years ago)
- Last Synced: 2025-03-12T08:44:51.038Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 32.2 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pg-query-string [](https://travis-ci.org/pyramation/pg-query-string)
```sh
npm install pg-query-string
```
Thanks to https://github.com/hiddentao/squel
This is essentially squel, however a few changes:
* built with babel instead of gulp
* hard-coded to postgres
* added type coersions
* classes handy for testing
```js
import { Table, Schema } from 'pg-query-string';
const schema = new Schema('my-schema');
const table = schema.table('users', {
id: 'uuid',
username: 'text',
email: 'email',
password: 'password',
active: 'boolean',
tags: 'text[]'
});
table.update(
{
active: true,
tags: ['pyramation']
},
{
id: 1
}
);
```
Which produces the following object
```
Object {
"text": "UPDATE \\"my-schema\\".users SET active = $1::boolean, tags = ($2::text[]) WHERE (id = $3::uuid)",
"values": Array [
true,
Array [
"pyramation",
],
1,
],
}
```