ts-postgrest-client
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i ts-postgrest-client

Weekly Downloads

2

Version

0.0.2

License

MIT

Unpacked Size

27.2 kB

Total Files

18

Last publish

Collaborators

  • miws