Build urls for PostgREST
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.
$ npm install --save postgrest-url
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.
npm test -s
# run tests on changes
npm run watch -- -s
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
MIT © Hugo Dias