0.2.0 • Published 5 years ago

postgrest-syntax-builder v0.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

PostgREST Syntax Builder

CircleCI Known Vulnerabilities Maintainability codecov

npm

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

Edit PostgREST Syntax Builder 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.

0.2.0

5 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago