1.2.3 • Published 4 years ago

@wrserver/data v1.2.3

Weekly downloads
-
License
-
Repository
github
Last release
4 years ago

WRServer/Data

License Email Donate Donate

@wrserver data module, holding a new concept of Model as a Table, to interface json file as a db-like model.

Installing

Install this library is easy by cloning the repo. You can install trhought npm too:

Local installation

npm install @wrserver/data

Global installation

npm install -g @wrserver/data

We recomend to use the entire base package (core, crypt, data, auth, mail)

Data Model

This module add the DataModel to the WRServer Set of elements. The DataModel is usefull to manage files throught the DataService that allow to load/save json (encrypted or not) files.

Create a custom DataModel

import { Model, Column, Connection } from '@wrserver/core';
import { DataService, DataModel } from '@wrserver/data';

@Model
export class MyModel extends DataModel {
    //Use @Column.<TYPE>(defaultValue) for define a Db Column
    //Care that the defaultValue is evaluated once.
    //If it is an object reference every model will inherith the same reference.
    @Column.ID()
    public id: number;
    @Column.String()
    public stringType: string;
    @Column.Number(1)
    public numberType: number;
    @Column.Boolean(true)
    public booleanType: boolean;
    @Column.Array(()=>[0,1,2])
    public arrayType: number[];
    @Column.Date(()=>new Date())
    public dateType: Date;
    @Column.Model(MyModel2, () => new MyModel2(... params ...))
    public modelType: MyModel2;

    //NOT MAPPED PARAMETERS
    public otherParam1: boolean;
    public otherParam2: Date;

    public sendable(): any{ return { id: this.id, name: this.name, email: this.email, role: this.role }; }
}

DataService Usage

At Module defition

import { DataService, DataModule } from '@wrserver/data';

export class MyModule extends Module {
    //... controller, models, etc. ...
    public services: ServiceType[] = [ DataService, ... Other Services ... ];
    public dependencies: ModuleType[] = [ DataModule, ... Other Modules ... ];
    //... rest of code ...
}

At Server definition (settings)

import { WRServer }from '@wrserver/core';
import { DataModule } from '@wrserver/data';

//REMEMBER: don't use this static methods inside module definitions
DataModule.withDir(<directory>).withEncrypt(true|false)
            .withAlgorithm(<algorithm>).withCadence(<seconds autosave>)
            
//Server definition
let server: WRServer = new WRServer(...)

Contacts

If you like the project feel free to contact me on my Email.

Something gone wrong? Feel free to rise an issue!

Did you like this project and it was usefull? Help me improve my work:

Donate Donate

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago