0.0.2 • Published 4 years ago

ts-postgrest-client v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Isomorphic Postgrest Client in Typescript which provides a fluent API.

npm i ts-postgrest-client

Table of contents

  1. Usage
  2. Basic usage
  3. Advanced usage
  4. API
  5. Operators

Basic usage:

const client = new PostgrestClient({
  host: 'http://localhost:3000'
})

const query = client.query('document')
  .query('documentId').notEqual('test')
  .select([
    'documentId',
    {
      'schemaId': [
        'name',
        'title',
        'settings'
      ]
    }
  ])

client.execute(query).then(async res => {
  console.log(await res.json())
})

Executing multiple queries in parallel:

const client = new PostgrestClient({
  host: 'http://localhost:3000'
})

const documentQuery = client.query('document')
  .query('documentId').notEqual('test')

const schemaQuery = client.query('schema')
  .query('schemaId').notEqual('test')

Promise.all([client.execute(documentQuery), client.execute(schemaQuery)]).then(async res => {
  console.log(await res.json())
})

Executing complex queries:

const client = new PostgrestClient({
  host: 'http://localhost:3000'
})

const schemaQuery = client.query('schema')
  .query('schemaId').notEqual(10)

const documentQuery = client.query('document')
  .query('documentId').notEqual('test')
  .addQuery(schemaQuery)

client.execute(documentQuery).then(async res => {
  console.log(await res.json())
})

API

This client aims to closely mirror the Postgrest API, http://postgrest.org/en/v6.0/api.html.

Using an operator on a query can be easily achieved via the QueryBuilders expressive methods:

const documentQuery = client.query('document')
  .query('documentId').notEqual(0).lessThan(10)

Additionally an escape hatch is provided via directly passing the Postgrest abbreviation in:

const documentQuery = client.query('document')
  .query('documentId', 'neq', 0).query('documentId', 'lt', 10)
Operators
Methodin PostgrestName
.equalseqEquals
.greaterThangtGreater than
.greaterThanOrEqualgteGreater than or equal
.lessThanltLess than
.lessThanOrEquallteLess than or equal
.notEqualneqNot equal
.likelikeLike
.ilikeilikeiLike
.ininIn
.isisIs