npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@postgresrest/node

v0.3.0

Published

This is a nodejs' client to use _p_**Rest** api.

Downloads

5

Readme

@postgresrest/node

This is a nodejs' client to use pRest api.

Actions Status Coverage Status

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)