json-db-orm
TypeScript icon, indicating that this package has built-in type declarations

0.2.14 • Public • Published

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()

Dependencies (1)

Dev Dependencies (5)

Package Sidebar

Install

npm i json-db-orm

Weekly Downloads

0

Version

0.2.14

License

MIT

Unpacked Size

48.6 kB

Total Files

44

Last publish

Collaborators

  • zander