json-db-orm
A simple orm for node-json-db
Features
- [x] supports node-json-db
- [x] TypeScript and JavaScript support
- [x] validator
- [x] default value or function
Installation
npm install json-db-orm
npm install reflect-metadata
TypeScript Configuration
tsconfig.json
{
"emitDecoratorMetadata": true,
"experimentalDecorators": true
}
Basic Use
import {Store, Schema, ListSchema, AutoIncrementPrimary, Field} from 'json-db-orm';
Store.root = "" // your database path
@Schema("record")
class Record extends ListSchema{
@AutoIncrementPrimary()
id: number;
@Field({validate: (v: string)=>v.length <= 32})
message: string;
@Field({default: ()=>new Date().getTime()})
ts: number;
}
import {Schema, Store, Field, Primary, KeySchema} from 'json-db-orm';
import {dirname, join, resolve} from 'path';
Store.root = resolve(dirname(__filename), "data")
@Schema("user")
class User extends KeySchema{
@Primary()
id: number;
@Field()
name: string;
}
let user = new User();
user.id = 1;
user.name = "test"
user.save()