ng-db-helper
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

NgDbHelperModule

This module is an ORM with plugable connector to share model and logic on multiple environnement.

This module simplify persistence with relationnal databases. As there is many platforms or devices, this module bring possibility to manage connectors. It allows integrators to have a better code portability.

It can be used with cordova-sqlite-storage, websql or other relationnal database if you implement your own connector.

See Usage documentation

See complete api documentation

See example project: Todos App

See examples of code below

Declaration:

 
@Table({name: 'todos'})
export class Todo extends DbHelperModel {
 
  @PrimaryKey({autoIncremented: true})
  public id: number;
 
  @Column()
  public name: string;
 
  @Column(type'number')
  public dueDate: number;
 
  @Column(type'boolean')
  public isDone: boolean;
 
  @ForeignModel(Category)
  public category: Category;
}
 

Use in a component:

 
@Component({
  selector: 'mgto-todos',
  template: '',
  styles: ''
})
class TodosPage implements OnInit {
  public todoQueryResult: QueryResult<Todo>;
 
  public ngOnInit() {
    // retrieve not done and not passed todos, you may put this in a service
    Select(Todo).where({isDone: false, and__dueDate__lt: (new Date()).getTime()}).exec()
      .subscribe((qr: QueryResult<Todo>) => {
        this.todoQueryResult = qr;
      }, (err) => {
        // manage error
      });
  }
 
  public checkTodo(todo: Todo) {
    todo.isDone = !todo.isDone;
    todo.save().subscribe(() => {
      // isDone did change and is saved
    }, (err) => {
      // manage error
      // cancel done change
      todo.isDone = !todo.isDone;
    });
  }
}
 

Prerequisites

Your application must be an angular project. Then choose the kind of database supported by the target device of your app. This module support can be configured to support Websql or cordova-sqlite-storage or both on specific conditions.

If you have other need and this need is to use a relationnal database, see the connector API and you will be able to build your own connector and keep using this API design.

Installing

This module is available on official npm registry, with command line from your project, use the command below:

 
npm install ng-db-helper --save
 

The module is now a part of your dependancies and is ready to be used. See Usage to learn about how easy it is !

Done and Todos

Contact me to suggest missing things on this todo list!

  • Queries
    • select
    • insert
    • update
    • delete
    • Manage join tables
    • Sub queries management to clauses
    • Sub clause group
    • Composite clause to compaire tuple of column with tuple of values
    • Allow semantic clause complexity
    • Batch queries
  • Models
    • Table annotation
    • Column annotation
    • Foreign models
    • Add foreign delete constraint
    • Many to many link
    • Manage more types like Date
    • add formatter functions
    • constraint management
    • Create a base service with usefull generic functions
    • Observe model change
  • Connectors
    • standard interface
    • plugable connector on init config
    • cordova-sqlite-storage connector
    • Websql connector
    • Hybrid connector detecting cordova-sqlite-storage or Websql connector support and activate it
    • Batch queries
    • Default connector configuration
  • Design
    • Pass some possible values for field to enum

Authors

  • Olivier Margarit

License

This project is licensed under the MIT License - see LICENSE file for details.

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i ng-db-helper

    Weekly Downloads

    0

    Version

    0.3.1

    License

    MIT

    Unpacked Size

    243 kB

    Total Files

    45

    Last publish

    Collaborators

    • margarito