Code Monkey home page Code Monkey logo

postgrest-url's Introduction

postgrest-url Build Status codecov NPM Version NPM Downloads NPM License

Build urls for PostgREST

postgrest-url is a small library focused in the construction of urls for PostgREST. Based on query definition written in object notation the library outputs a safe url.

Install

$ npm install --save postgrest-url

Usage

var level = {
    'levels:level': {
        id: 'eq.1',
        limit: 10,
        offset: 3
    }
};
var zone = {
    'zones:zone': {
        id: 'eq.1',
        limit: 10,
        offset: 3
    }
};

url(level);
// level?id=eq.1&limit=10&offset=3

url(zone);
// zone?id=eq.1&limit=10&offset=3

url({
    space: {
        id: 'eq.1',
        select: ['*', level]
    }
});
// space?select=*,levels:level{*}&id=eq.1&level.id=eq.1&level.limit=10&level.offset=3

url({
    space: {
        id: 'eq.1',
        select: ['*', level, zone]
    }
});

// space?select=*,levels:level{*},zones:zone{*}&id=eq.1&level.id=eq.1&level.limit=10&level.offset=3&zone.id=eq.1&zone.limit=10&zone.offset=3

url({
    space: {
        id: 'eq.1',
        select: ['*', {
            'levels:level': {
                id: 'eq.1',
                limit: 10,
                offset: 3,
                order: 'age.asc',
                select: ['*', zone]
            }
        }]
    }
});
// space?select=*,levels:level{*,zones:zone{*}}&id=eq.1&level.id=eq.1&level.limit=10&level.offset=3&level.order=age.asc&level.zone.id=eq.1&level.zone.limit=10&level.zone.offset=3

Check the code in the test folder for more.

Build and test

npm test -s
# run tests on changes
npm run watch -- -s

Release

https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#commit
https://github.com/conventional-changelog/standard-version

npm run commmit -- -a
npm run release

Todo

  • add docs and examples
  • urlencode where necessary
  • jsonb stuff
  • add browser test to travis

License

MIT © Hugo Dias

postgrest-url's People

Contributors

hugomrdias avatar

Watchers

James Cloos avatar  avatar

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.