{"id":18373746,"url":"https://github.com/prest/prest-node","last_synced_at":"2025-04-06T19:32:24.677Z","repository":{"id":40709657,"uuid":"294259129","full_name":"prest/prest-node","owner":"prest","description":"NodeJS client for pRest","archived":false,"fork":false,"pushed_at":"2023-03-05T12:05:54.000Z","size":700,"stargazers_count":5,"open_issues_count":6,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-14T05:33:38.398Z","etag":null,"topics":["hacktoberfest","nodejs","posgresql","prest","prest-node"],"latest_commit_sha":null,"homepage":"https://prest.github.io/prest-node/","language":"TypeScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prest.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-09-10T00:16:34.000Z","updated_at":"2023-04-14T06:26:53.000Z","dependencies_parsed_at":"2023-09-24T05:24:40.531Z","dependency_job_id":null,"html_url":"https://github.com/prest/prest-node","commit_stats":{"total_commits":26,"total_committers":4,"mean_commits":6.5,"dds":"0.15384615384615385","last_synced_commit":"b92ffa762d0acbadeb06a1afedc36b244de8e80f"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prest%2Fprest-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prest%2Fprest-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prest%2Fprest-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prest%2Fprest-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prest","download_url":"https://codeload.github.com/prest/prest-node/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247142444,"owners_count":20890732,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","nodejs","posgresql","prest","prest-node"],"created_at":"2024-11-06T00:11:57.990Z","updated_at":"2025-04-06T19:32:21.372Z","avatar_url":"https://github.com/prest.png","language":"TypeScript","readme":"# @postgresrest/node\nThis is a nodejs' client to use _p_**Rest** api.\n\n[![Actions Status](https://github.com/prest/prest-node/workflows/Test,%20Build%20and%20Deploy/badge.svg)](https://github.com/prest/prest-node/actions) [![Coverage Status](https://coveralls.io/repos/github/prest/prest-node/badge.svg?branch=master)](https://coveralls.io/github/prest/prest-node?branch=master)\n\n## Issues\n\n\u003e The [issue listing](https://github.com/prest/prest/issues?q=is%3Aissue+is%3Aopen+label%3Aclient%2Fnode) should be kept in the [\"main\" repository (_api server_)](https://github.com/prest/prest), centralizing all demands helps us give visibility to all products\n\n\n## Resume\n- Introduction\n  - Motivation\n  - How Install / Setup\n- Basic API\n  - databases()\n  - schemas()\n  - tables()\n  - show()\n- Table API\n  - What is a TableConnector entity?\n  - query()\n\n\n-------------------\n\n\n## Introduction\n### Motivation\n_p_**Rest** 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 _p_**Rest** api across javascript applications.\n\n### How Install\nYou can install using NPM\n`npm install @postgresrest/node --save`\n\nor yarn\n`yarn add @postgresrest/node -S`\n\nAfter it, you should create a instance of PRestAPI:\n```typescript\nimport PRestApi from '@postgresrest/node';\n\nconst cli = new PRestApi('myhost');\n```\n\nor if you want you can use custom fetcher with any fetch tool you'd like:\n\n```typescript\nimport axios from 'axios';\n\nconst fetcher = (uri, method) =\u003e axios[method](uri).then(({data}) =\u003e data);\nconst cli = new PRestApi('myhost', fetcher);\n```\n\n-------------------\n\n\n\n## Basic API\nYou can find all routes that we consume in this section [here](https://docs.postgres.rest/query-statements/#select---get)\n\n### databases(): Promise\u003cPRestDatabase[]\u003e\n`cli.databases()` will reflect the `/databases` _p_**Rest** 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).\n\n### schemas(): Promise\u003cPRestSchema[]\u003e\n`cli.schemas()` will reflect the `/schemas` _p_**Rest** 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).\n\n### tables(): Promise\u003cPRestTable[]\u003e\n`cli.tables()` will reflect the `/tables` _p_**Rest** 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).\n\n### tablesByDBInSchema(...entries: string[]): Promise\u003cPRestTable[]\u003e\nIt will reflect the `/tables` _p_**Rest** 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).\n\nUsage sample:\n```typescript\nconst structure = await cli.tablesByDBInSchema('db', 'schema', 'table');\nconst structure = await cli.tablesByDBInSchema('db.schema.table');\n```\n\n### show(...entries: string[]): Promise\u003cPRestTableShowItem[]\u003e\nIt will reflect the `/show/DATABASE/SCHEMA/TABLE` _p_**Rest** 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).\n\nUsage sample:\n```typescript\nconst structure = await cli.show('db', 'schema', 'table');\nconst structure = await cli.show('db.schema.table');\n```\n\n### tableConnection\u003cT\u003e(...entries: string[]): TableConnector\u003cT\u003e\nIt will return a [TableConnector] instance to manipulate table actions.\n\nUsage sample:\n```typescript\nconst structure = cli.tableConnection('db', 'schema', 'table');\nconst structure = cli.tableConnection('db.schema.table');\n```\n\n\n-------------------\n\n\n## Table API\n### What is a TableConnector entity?\nTo 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]()\n\n### query\nIt will reflect `/DATABASE/SCHEMA/TABLE` prest endpoint.\n\nUsage sample:\n```typescript\nconst data = await cli.tableConnection('db', 'schema', 'table').query();\n```\n\n### create\nIt will reflect `/DATABASE/SCHEMA/TABLE` prest endpoint with `POST` method\n\nUsage sample:\n```typescript\nconst data = await cli.tableConnection('db', 'schema', 'table').create({ foo: 'bar' });\n```\n\n### update\nIt will reflect `/DATABASE/SCHEMA/TABLE` prest endpoint with `PATCH` method\n\nUsage sample:\n```typescript\nconst data = await cli.tableConnection('db', 'schema', 'table').update('myid', { foo: 'fizz' });\n```\n\n### delete\nIt will reflect `/DATABASE/SCHEMA/TABLE` prest endpoint with `DELETE` method\n\nUsage sample:\n```typescript\nconst data = await cli.tableConnection('db', 'schema', 'table').delete('myid');\n```\n\n-------------------\n\n\n## Ideas\n\n\u003e Add and `PRestOptions` structure to `PRestApi` object, to automatic add some kind of options like: `_renderer=xml`\n\n\u003e Create a `PRestQuery` to format this query statements (https://docs.postgres.rest/query-statements) in a simple structure:\n\n```typescript\nconst query = new PRestQuery();\nquery.eq('x');\nquery.like('x');\nquery.pagination({ size: 2, page: 1 });\n\ncli.query(query) // ?$eq=x\u0026$like=x\u0026_page=1\u0026_page_size=2\n\n```\n\n\u003e Create a .view() method to reflect .query() method (abstract it)\n\n\u003e Create a .batch() method\n\n\u003e Send this Readme to a more complete documentation (remove actual typedoc)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprest%2Fprest-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprest%2Fprest-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprest%2Fprest-node/lists"}