Giter Site home page Giter Site logo

prest-node's Introduction

@postgresrest/node

This is a nodejs' client to use pRest api.

Actions Status Coverage Status

Issues

The issue listing should be kept in the "main" repository (api server), centralizing all demands helps us give visibility to all products

Resume

  • Introduction
    • Motivation
    • How Install / Setup
  • Basic API
    • databases()
    • schemas()
    • tables()
    • show()
  • Table API
    • What is a TableConnector entity?
    • query()

Introduction

Motivation

pRest is a GoLang service that's simplify and accelerate development, instant, realtime, high-performance on any Postgres application, existing or new. To extends this functionalities we decided to a client in javascript/typescript to make easiest the life of someone that wants to consume pRest api across javascript applications.

How Install

You can install using NPM npm install @postgresrest/node --save

or yarn yarn add @postgresrest/node -S

After it, you should create a instance of PRestAPI:

import PRestApi from '@postgresrest/node';

const cli = new PRestApi('myhost');

or if you want you can use custom fetcher with any fetch tool you'd like:

import axios from 'axios';

const fetcher = (uri, method) => axios[method](uri).then(({data}) => data);
const cli = new PRestApi('myhost', fetcher);

Basic API

You can find all routes that we consume in this section here

databases(): Promise<PRestDatabase[]>

cli.databases() will reflect the /databases pRest endpoint. It will return all databases from your Postgres instance, you are able to use PRestDatabase type too (if you are in a Typescript environment).

schemas(): Promise<PRestSchema[]>

cli.schemas() will reflect the /schemas pRest endpoint. It will return all schemas from your Postgres instance, you are able to use PRestSchema type too (if you are in a Typescript environment).

tables(): Promise<PRestTable[]>

cli.tables() will reflect the /tables pRest endpoint. It will return all tables from your Postgres instance, you are able to use PRestTable type too (if you are in a Typescript environment).

tablesByDBInSchema(...entries: string[]): Promise<PRestTable[]>

It will reflect the /tables pRest endpoint. It will return all tables from your Postgres instance, you are able to use PRestTable type too (if you are in a Typescript environment).

Usage sample:

const structure = await cli.tablesByDBInSchema('db', 'schema', 'table');
const structure = await cli.tablesByDBInSchema('db.schema.table');

show(...entries: string[]): Promise<PRestTableShowItem[]>

It will reflect the /show/DATABASE/SCHEMA/TABLE pRest endpoint. It will return the structure of a specific table in a specific database and schema, you are able to use PRestTableShowItem type too (if you are in a Typescript environment).

Usage sample:

const structure = await cli.show('db', 'schema', 'table');
const structure = await cli.show('db.schema.table');

tableConnection(...entries: string[]): TableConnector

It will return a [TableConnector] instance to manipulate table actions.

Usage sample:

const structure = cli.tableConnection('db', 'schema', 'table');
const structure = cli.tableConnection('db.schema.table');

Table API

What is a TableConnector entity?

To simplify the API consume, we created a entity to control query and batches by a table namespace. This object could be retrived using the method tableConnection

query

It will reflect /DATABASE/SCHEMA/TABLE prest endpoint.

Usage sample:

const data = await cli.tableConnection('db', 'schema', 'table').query();

create

It will reflect /DATABASE/SCHEMA/TABLE prest endpoint with POST method

Usage sample:

const data = await cli.tableConnection('db', 'schema', 'table').create({ foo: 'bar' });

update

It will reflect /DATABASE/SCHEMA/TABLE prest endpoint with PATCH method

Usage sample:

const data = await cli.tableConnection('db', 'schema', 'table').update('myid', { foo: 'fizz' });

delete

It will reflect /DATABASE/SCHEMA/TABLE prest endpoint with DELETE method

Usage sample:

const data = await cli.tableConnection('db', 'schema', 'table').delete('myid');

Ideas

Add and PRestOptions structure to PRestApi object, to automatic add some kind of options like: _renderer=xml

Create a PRestQuery to format this query statements (https://docs.postgres.rest/query-statements) in a simple structure:

const query = new PRestQuery();
query.eq('x');
query.like('x');
query.pagination({ size: 2, page: 1 });

cli.query(query) // ?$eq=x&$like=x&_page=1&_page_size=2

Create a .view() method to reflect .query() method (abstract it)

Create a .batch() method

Send this Readme to a more complete documentation (remove actual typedoc)

prest-node's People

Contributors

avelino avatar dependabot[bot] avatar guidiego avatar quentincaffeino avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

lgtm-migrator

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.