Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@supabase/postgrest-js

Package Overview
Dependencies
Maintainers
2
Versions
135
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@supabase/postgrest-js - npm Package Compare versions

Comparing version 0.1.1 to 0.3.0

lib/Builder.js

2

lib/index.js

@@ -1,1 +0,1 @@

'use strict';Object.defineProperty(exports,'__esModule',{value:!0}),exports.PostgrestClient=void 0;var _createClass=function(){function a(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,'value'in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),_BaseApi=require('./BaseApi'),_BaseApi2=_interopRequireDefault(_BaseApi),_BaseRequest=require('./BaseRequest'),_BaseRequest2=_interopRequireDefault(_BaseRequest);function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')}var PostgrestClient=function(){function a(b){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};_classCallCheck(this,a),this.restUrl=b,this.additionalParameters=c}return _createClass(a,[{key:'from',value:function from(a){var b=this,c=this.restUrl+'/'+a+'?';Object.keys(this.additionalParameters).forEach(function(a){c=''+c+a+'='+b.additionalParameters[a]+'&'});var d=c.slice(0,-1),e=new _BaseApi2.default(d);return e}},{key:'rpc',value:function rpc(a){var b=this,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,d=this.restUrl+'/rpc/'+a+'?';Object.keys(this.additionalParameters).forEach(function(a){d=''+d+a+'='+b.additionalParameters[a]+'&'});var e=d.slice(0,-1),f=new _BaseRequest2.default('post',e);return null!=c&&f.send(c),f}}]),a}();exports.PostgrestClient=PostgrestClient;
"use strict";function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.PostgrestClient=void 0;var _Builder=_interopRequireDefault(require("./Builder")),_Request=_interopRequireDefault(require("./Request")),Helpers=_interopRequireWildcard(require("./utils/Helpers"));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;return _getRequireWildcardCache=function(){return a},a}function _interopRequireWildcard(a){if(a&&a.__esModule)return a;if(null===a||"object"!==_typeof(a)&&"function"!=typeof a)return{default:a};var b=_getRequireWildcardCache();if(b&&b.has(a))return b.get(a);var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a)if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;f&&(f.get||f.set)?Object.defineProperty(c,e,f):c[e]=a[e]}return c["default"]=a,b&&b.set(a,c),c}function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}var PostgrestClient=function(){function a(b){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};_classCallCheck(this,a),this.restUrl=b,this.queryString=null,c.queryParams&&(this.queryString=Helpers.objectToQueryString(c.queryParams))}return _createClass(a,[{key:"from",value:function from(a){var b="".concat(this.restUrl,"/").concat(a);return this.queryString&&(b+="?".concat(this.queryString)),new _Builder["default"](b)}},{key:"rpc",value:function rpc(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,c="".concat(this.restUrl,"/rpc/").concat(a);this.queryString&&(c+="?".concat(this.queryString));var d=new _Request["default"]("post",c);return null!=b&&d.send(b),d}}]),a}();exports.PostgrestClient=PostgrestClient;

@@ -1,1 +0,1 @@

'use strict';Object.defineProperty(exports,'__esModule',{value:!0}),exports.Eq=Eq,exports.Gt=Gt,exports.Lt=Lt,exports.Gte=Gte,exports.Lte=Lte,exports.Like=Like,exports.Ilike=Ilike,exports.Is=Is,exports.In=In,exports.Not=Not;function Eq(a,b){return a+'=eq.'+b}function Gt(a,b){return a+'=gt.'+b}function Lt(a,b){return a+'=lt.'+b}function Gte(a,b){return a+'=gte.'+b}function Lte(a,b){return a+'=lte.'+b}function Like(a,b){var c=b.replace(/%/g,'*');return a+'=like.'+c}function Ilike(a,b){var c=b.replace(/%/g,'*');return a+'=ilike.'+c}function Is(a,b){return a+'=is.'+b}function In(a,b){return a+'=in.'+b.join(',')}function Not(a,b){return a+'=not.'+b}
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports._eq=_eq,exports._gt=_gt,exports._lt=_lt,exports._gte=_gte,exports._lte=_lte,exports._like=_like,exports._ilike=_ilike,exports._is=_is,exports._in=_in,exports._not=_not;function _eq(a,b){return"".concat(a,"=eq.").concat(b)}function _gt(a,b){return"".concat(a,"=gt.").concat(b)}function _lt(a,b){return"".concat(a,"=lt.").concat(b)}function _gte(a,b){return"".concat(a,"=gte.").concat(b)}function _lte(a,b){return"".concat(a,"=lte.").concat(b)}function _like(a,b){var c=b.replace(/%/g,"*");return"".concat(a,"=like.").concat(c)}function _ilike(a,b){var c=b.replace(/%/g,"*");return"".concat(a,"=ilike.").concat(c)}function _is(a,b){return"".concat(a,"=is.").concat(b)}function _in(a,b){return"".concat(a,"=in.").concat(b.join(","))}function _not(a,b){return"".concat(a,"=not.").concat(b)}
{
"name": "@supabase/postgrest-js",
"version": "0.1.1",
"version": "0.3.0",
"description": "PostgREST JS client",
"main": "./lib/index.js",
"scripts": {
"build": "cross-env BABEL_ENV=production babel src --out-dir lib",
"clean": "rimraf lib",
"test": "npm run cover",
"cover": "nyc --check-coverage npm run test:unit",
"deploy": "npm version patch && npm publish --access=public",
"docs": "node_modules/.bin/jsdoc --configure .jsdoc.json --verbose",
"prepublish": "npm run clean && npm run build",
"pretty": "prettier --write \"./**/*.{js,json,yml,md,vue,css,scss}\"",
"test:integration": "mocha -r @babel/register -r babel-polyfill test/integration/**/*.js",
"test:unit": "mocha -r @babel/register -r babel-polyfill test/unit/**/*.js",
"test:prod": "cross-env BABEL_ENV=production npm run test",
"test:only": "mocha --require babel-core/register --require babel-polyfill --recursive",
"test:watch": "npm test -- --watch",
"test:examples": "node examples/",
"cover": "nyc --check-coverage npm run test:only",
"build": "cross-env BABEL_ENV=production babel src --out-dir lib",
"prepublish": "npm run clean && npm run build",
"deploy": "npm version patch && npm publish --access=public"
"test": "npm run cover"
},

@@ -40,11 +42,17 @@ "files": [

"devDependencies": {
"babel-cli": "^6.26.0",
"@babel/cli": "^7.8.3",
"@babel/core": "^7.8.3",
"@babel/preset-env": "^7.8.3",
"@babel/register": "^7.8.3",
"@supabase/doctest-js": "0.0.10",
"@supabase/jsdoc-template": "^0.1.0",
"babel-plugin-add-module-exports": "^1.0.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-minify": "^0.3.0",
"chai": "^4.1.2",
"chai": "^4.2.0",
"cross-env": "^5.2.1",
"mocha": "^6.1.3",
"jsdoc": "^3.6.3",
"mocha": "^6.2.2",
"nyc": "^13.3.0",
"prettier": "^1.19.1",
"rimraf": "^2.6.2"

@@ -51,0 +59,0 @@ },

# Postgrest JS
## Commands
- `npm run clean` - Remove `lib/` directory
- `npm test` - Run tests with linting and coverage results.
- `npm test:only` - Run tests without linting or coverage.
- `npm test:watch` - You can even re-run tests on file changes!
- `npm test:prod` - Run tests with minified code.
- `npm run test:examples` - Test written examples on pure JS for better understanding module usage.
- `npm run lint` - Run ESlint with airbnb-config
- `npm run cover` - Get coverage report for your code.
- `npm run build` - Babel will transpile ES6 => ES5 and minify the code.
- `npm run prepublish` - Hook for npm. Do all the checks before publishing your module.
Isomorphic JavaScript client for [PostgREST](https://postgrest.org). The goal of this library is to make an "ORM-like" restful interface.
**Contents**
- [Usage](#usage)
- [Install](#install)
- [Initialize](#initialize)
- [GET](#get)
- [POST](#post)
- [PATCH](#patch)
- [DELETE](#delete)
- [Usage online](#usage-online)
- [Contributing](#contributing)
- [License](#license)
- [Credits](#credits)
## Publishing
Bump the semver.
## Usage
### Install
```sh
npm publish --access=public
```
npm install --save @supabase/postgrest-js
```
### Initialize
```js
import { PostgrestClient } from ' @supabase/postgrest-js'
// Point to your own PostgREST server (or use ours, but go easy..)
const worldUrl = 'https://world.supabase.co/rest/v1'
const queryParams = { apikey: 'public-key-bOYapLADERfE' }
let client = new PostgrestClient(worldUrl, { queryParams })
```
### GET
```js
// Basic
let { body: countries } = await client
.from('countries')
.select('*')
// Getting specific columns
let { body: countries } = await client
.from('countries')
.select('name')
// Query foreign tables
let { body: countries } = await client
.from('countries')
.select(`
name,
cities (
name
)
`)
// Filter foreign tables
let { body: countries } = await client
.from('countries')
.select(`
name,
cities (
name
)
`)
.filter('name', 'eq', 'New Zealand')
.filter('cities.name', 'eq', 'Auckland')
// Ordering
let { body: countries } = await client
.from('countries')
.select('name')
.order('name')
// Pagination
let { body: countries } = await client
.from('countries')
.select('name')
.range(0, 10)
// Match
let { body: countries } = await client
.from('countries')
.match({ 'continent': 'Asia' })
// Equal
let { body: countries } = await client
.from('countries')
.eq('name', 'New Zealand')
// Greater than
let { body: countries } = await client
.from('countries')
.gt('id', 20)
// Less than
let { body: countries } = await client
.from('countries')
.lt('id', 20)
// Greater than or equal
let { body: countries } = await client
.from('countries')
.gte('id', 20)
// Less than or equal
let { body: countries } = await client
.from('countries')
.lte('id', 20)
// String search - case sensitive
let { body: countries } = await client
.from('countries')
.like('name', '%Zeal%')
// String search - case insensitive
let { body: countries } = await client
.from('countries')
.ilike('name', '%Zeal%')
// Exact equality (null, true, false)
let { body: countries } = await client
.from('countries')
.is('name', null)
// In list
let { body: countries } = await client
.from('countries')
.in('name', ['China', 'France'])
// Not equal
let { body: countries } = await client
.from('countries')
.not('name', 'China')
```
### POST
You can insert records using `insert()`. Insert accepts an array of objects so that you can batch insert.
```js
let { status } = await client
.from('messages')
.insert([{ message: 'Hello World 👋'])
```
### PATCH
You can update records using `update()`.
```js
let { status } = await client
.from('messages')
.eq('message', 'Hello World 👋')
.update({ message: 'Goodbye World 👋' })
```
### DELETE
You can delete records using `delete()`.
```js
let { status } = await client
.from('messages')
.eq('message', 'Goodbye World 👋')
.delete()
```
## Usage online
To see details examples of usage, see the Supabase docs:
- [Reading](https://supabase.io/docs/library/get)
- [Creating](https://supabase.io/docs/library/post)
- [Creating](https://supabase.io/docs/library/post)
- [Deleting](https://supabase.io/docs/library/delete)
- [Stored Procedures](https://supabase.io/docs/library/stored-procedures)
## Contributing
- Fork the repo on GitHub
- Clone the project to your own machine
- Commit changes to your own branch
- Push your work back up to your fork
- Submit a Pull request so that we can review your changes and merge
## License
This repo is liscenced under MIT.
## Credits
- https://github.com/calebmer/postgrest-client - originally forked and adapted from @calebmer's library

@@ -1,41 +0,37 @@

import BaseApi from './BaseApi'
import BaseRequest from './BaseRequest'
/**
* JS Client for querying postgres
*
* @class
* @param {string} path The path representing the database table.
* @param {object} [options]
* @param {object} [options.queryParams] Optional query params that you want to append to your URL
*/
import Builder from './Builder'
import Request from './Request'
import * as Helpers from './utils/Helpers'
class PostgrestClient {
constructor(restUrl, additionalParameters = {}) {
constructor(restUrl, options = {}) {
this.restUrl = restUrl
this.additionalParameters = additionalParameters
this.queryString = null
if (options.queryParams) this.queryString = Helpers.objectToQueryString(options.queryParams)
}
from(tableName){
let path = `${this.restUrl}/${tableName}?`
Object.keys(this.additionalParameters).forEach(param => {
path =`${path}${param}=${this.additionalParameters[param]}&`
})
// We want to remove the last '&'
let pathCleaned = path.slice(0,-1)
let api = new BaseApi(pathCleaned)
return api
from(tableName) {
let url = `${this.restUrl}/${tableName}`
if (this.queryString) url += `?${this.queryString}`
return new Builder(url)
}
rpc(functionName, functionParameters = null){
let path =`${this.restUrl}/rpc/${functionName}?`
Object.keys(this.additionalParameters).forEach(param => {
path =`${path}${param}=${this.additionalParameters[param]}&`
})
// We want to remove the last '&'
let pathCleaned = path.slice(0,-1)
let request = new BaseRequest('post', pathCleaned)
if(functionParameters != null) request.send(functionParameters)
rpc(functionName, functionParameters = null) {
let url = `${this.restUrl}/rpc/${functionName}`
if (this.queryString) url += `?${this.queryString}`
let request = new Request('post', url)
if (functionParameters != null) request.send(functionParameters)
return request
}
}
export { PostgrestClient }

@@ -1,43 +0,189 @@

export function Eq(columnName, filterValue) {
/** @module Filters **/
/**
* All exports are prefixed with an underscore to avoid collisions with reserved keywords (eg: "in")
*/
/**
* Finds all rows whose value on the stated columnName exactly matches the specified filterValue.
* @param {string} columnName Name of the database column
* @param { string | integer | boolean } filterValue Value to match
* @name eq
* @function
* @returns {string}
*
* @example
* _eq('name', 'New Zealand')
* //=>
* 'name=eq.New Zealand'
*/
export function _eq(columnName, filterValue) {
return `${columnName}=eq.${filterValue}`
}
export function Gt(columnName, filterValue) {
/**
* Finds all rows whose value on the stated columnName is greater than the specified filterValue.
* @param {string} columnName Name of the database column
* @param { string | integer | boolean } filterValue Value to match
* @name gt
* @function
* @returns {string}
*
* @example
* _gt('id', 20)
* //=>
* 'id=gt.20'
*/
export function _gt(columnName, filterValue) {
return `${columnName}=gt.${filterValue}`
}
export function Lt(columnName, filterValue) {
/**
* Finds all rows whose value on the stated columnName is less than the specified filterValue.
* @param {string} columnName Name of the database column
* @param { string | integer | boolean } filterValue Value to match
* @name lt
* @function
* @returns {string}
*
* @example
* _lt('id', 20)
* //=>
* 'id=lt.20'
*/
export function _lt(columnName, filterValue) {
return `${columnName}=lt.${filterValue}`
}
export function Gte(columnName, filterValue) {
/**
* Finds all rows whose value on the stated columnName is greater than or equal to the specified filterValue.
* @param {string} columnName Name of the database column
* @param { string | integer | boolean } filterValue Value to match
* @name gte
* @function
* @returns {string}
*
* @example
* _gte('id', 20)
* //=>
* 'id=gte.20'
*/
export function _gte(columnName, filterValue) {
return `${columnName}=gte.${filterValue}`
}
export function Lte(columnName, filterValue) {
/**
* Finds all rows whose value on the stated columnName is less than or equal to the specified filterValue.
* @param {string} columnName Name of the database column
* @param { string | integer | boolean } filterValue Value to match
* @name lte
* @function
* @returns {string}
*
* @example
* _lte('id', 20)
* //=>
* 'id=lte.20'
*/
export function _lte(columnName, filterValue) {
return `${columnName}=lte.${filterValue}`
}
export function Like(columnName, stringPattern) {
/**
* Finds all rows whose value in the stated columnName matches the supplied pattern (case sensitive).
* @param {string} columnName Name of the database column
* @param { string } stringPattern String pattern to compare to
* @name like
* @function
* @returns {string}
*
* @example
* _like('name', '%United%')
* //=>
* 'name=like.*United*'
*
* @example
* _like('name', '%United States%')
* //=>
* 'name=like.*United States*'
*/
export function _like(columnName, stringPattern) {
let stringPatternEnriched = stringPattern.replace(/%/g, '*')
return `${columnName}=like.${stringPatternEnriched}`
}
export function Ilike(columnName, stringPattern) {
/**
* Finds all rows whose value in the stated columnName matches the supplied pattern (case insensitive).
* @param {string} columnName Name of the database column
* @param { string } stringPattern String pattern to compare to
* @name ilike
* @function
* @returns {string}
*
* @example
* _ilike('name', '%United%')
* //=>
* 'name=ilike.*United*'
*
* @example
* _ilike('name', '%United states%')
* //=>
* 'name=ilike.*United states*'
*/
export function _ilike(columnName, stringPattern) {
let stringPatternEnriched = stringPattern.replace(/%/g, '*')
return `${columnName}=ilike.${stringPatternEnriched}`
}
export function Is(columnName, filterValue) {
/**
* A check for exact equality (null, true, false), finds all rows whose value on the state columnName exactly match the specified filterValue.
* @param {string} columnName Name of the database column
* @param { string | integer | boolean } filterValue Value to match
* @name is
* @function
* @returns {string}
*
* @example
* _is('name', null)
* //=>
* 'name=is.null'
*/
export function _is(columnName, filterValue) {
return `${columnName}=is.${filterValue}`
}
export function In(columnName, filterArray) {
/**
* Finds all rows whose value on the stated columnName is found on the specified filterArray.
* @param {string} columnName Name of the database column
* @param { string | integer | boolean } filterValue Value to match
* @name in
* @function
* @returns {string}
*
* @example
* _in('name', ['China', 'France'])
* //=>
* 'name=in.China,France'
*/
export function _in (columnName, filterArray) {
return `${columnName}=in.${filterArray.join(',')}`
}
export function Not(columnName, filterValue) {
/**
* Finds all rows whose value on the stated columnName is found on the specified filterArray.
* @param {string} columnName Name of the database column
* @param { string | integer | boolean } filterValue Value to match
* @name not
* @function
* @returns {string}
*
* @example
* _not('name', 'China')
* //=>
* 'name=not.China'
*/
export function _not(columnName, filterValue) {
return `${columnName}=not.${filterValue}`
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc