sackets
sackets
is an easy to use and highly extendable typed mongo db like query based TypeScript ActiveRecord library for browser and node js with code generation
Quick Start
- Install with npm
npm install sackets --save
- Create a
models.js
(ormodels.json
if you prefer json) file for meta information of your models similar to the following
moduleexports = "Item": "id": "number" // required "name": "string" "price": "number" "category": "Category" // belongs to "toString": "name" // string representation of Item object "Category": "id": "number" "name": "string" "items": "ItemCollection" // has many "toString": "name" ;
- Create a
modelsgen.js
file in your project with the following content
var generator = ;var models = ; // get the model meta created abovevar path = ; generator;
- Run modelsgen script with node
node modelsgen.js
- Files will be generated as following
- app - models - base - Categoryts // Generated every time overwriting the existing. Contains generated code based on the meta information - Itemts - indexts - Categoryts // Generated first time only, if not exists. Contains your custom code - CategoryCollectionts - Itemts - ItemCollectionts - indexts // barrel file exporting all the models
- Place your custom code in
app/models/Item.ts
for single item queries or inapp/models/ItemCollection.ts
for item collection queries
// app/models/ItemCollection.ts;;
- Use the code in your components or services
;
Note:
Unlike other frameworks, sackets self-fills the object(s) which makes it a perfect data handling library for data binding frameworks like Angular.
{{ item.name }} {{ item.price }}