This library implement the "Tables and Views" section listed here: http://postgrest.org/en/v5.1/api.html
- horizontal filtering
- vertical filtering
- ordering
- limits and pagination
npm install --save postgrest-syntax-builder
or
yarn add postgrest-syntax-builder
Live example
import p from 'postgrest-syntax-builder'
// Input
const result = [
p('age').gt(1),
p.limit(30),
p.not(
p.and(
p('age').gt(18),
p('age').lt(24),
)
),
]
// `result` is evaluated to an array of PostgrestSyntaxBuilder objects
[
{ param: 'age', value: 'gt.1' },
{ param: 'limit', value: '30' },
{ param: 'not.and', value: '(age=gt.18,age=lt.24)' },
]
// PostgrestSyntaxBuilder object extends the native String object, thus it can also be treated and used as String
[
'age=gt.1',
'limit=30',
'not.and=(age=gt.18,age=lt.24)',
]
A reduce
function that transform this:
p.reduce(...examples)
into this:
{
age: 'gt.1',
limit: 30,
'not.and': '(age=gt.18,age=lt.24)'
}
yarn build
yarn test
After the project is built, you can test each built target.
yarn example
node example
This project uses CircleCI to test, build and publish to npm registry. This workflow will be triggered whenever a new version tag is made.