pckg-orm
v0.0.5
Published
A simple JS ORM
Downloads
6
Readme
pckg/orm
A simple JS ORM that just works with pckg.
Usage
Require pckg-orm
package with npm
or yarn
.
$ yarn add pckg-orm
Entities
Entities represent full or partial collection of records.
import {Entity} from "pckg-orm/src/orm";
export class Countries extends Entity {
constructor(repository) {
super(repository);
this.$record = Country;
this.$path = 'countries';
}
}
Fetching
You can fetch and filter items.
await = new Countries()
.where('continent', 'EU')
.orderBy('title', 'ASC')
.limit(10, 20)
.all();
Records
Records represent a single item from collection.
import {Record} from "pckg-orm/src/orm;
export class Country extends Record {
constructor(props) {
super(props);
this.$entity = Countries;
}
}
Save, update, delete and clone.
You can manage your items with default actions that all return a Promise
.
let country = new Country({
title: 'Slovenia',
iso2: 'si',
iso3: 'svn',
phone: '00386',
});
await country.save(); // or insert()
country.continent = 'EU';
await country.save(); // or update()
await country.delete();
Repositories
Repositories represent a remote or local data source where entities are fetched from and records are saved to. They define a querying layer.
Rest
Get records - GET /api/countries?continent=EU
Insert record -POST - /api/countries
Update record - POST - /api/countries/id
PUT /api/countries/id
PATCH /api/countries/id
Delete record - DELETE /api/countries/id
HTTPQL
GET /api/httpql
+ X-Pckg-Orm- headers
POST /api/httpql
+ countries:update
, countries:delete
, countries:insert
actions