0.2.0 • Published 5 years ago
postgrest-syntax-builder v0.2.0
PostgREST Syntax Builder
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
Install
npm install --save postgrest-syntax-builder
or
yarn add postgrest-syntax-builder
Usage
Live example
Input
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)',
]
Utility
A reduce
function that transform this:
p.reduce(...examples)
into this:
{
age: 'gt.1',
limit: 30,
'not.and': '(age=gt.18,age=lt.24)'
}
Development
Building from source
yarn build
Run test
yarn test
Run example
After the project is built, you can test each built target.
With browser (ES module & UMD)
yarn example
With node (CommonJS)
node example
Publishing
This project uses CircleCI to test, build and publish to npm registry. This workflow will be triggered whenever a new version tag is made.