Skip to content

swim/ts-postgrest-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
Method in Postgrest Name
.equals eq Equals
.greaterThan gt Greater than
.greaterThanOrEqual gte Greater than or equal
.lessThan lt Less than
.lessThanOrEqual lte Less than or equal
.notEqual neq Not equal
.like like Like
.ilike ilike iLike
.in in In
.is is Is

About

Isomorphic Postgrest Client in Typescript providing a fluent, expressive API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published