Idea

...but not always

(when your app has useless layer)

Advantages and Disadvantages

Advantages

  • One place for DB related code
  • Database agnostic interface for client
  • Common contract for all models
  • Unit testing
  • Reduces the amount of code

Complex scenarios

  • Caching mechanisms
  • Audit logging
  • Providing record level security system

Disadvantages

  • Performance
  • Hidden specific feature DB
  • You should know what happen behind the scene
  • N+1 issue

Kinds

  • Manual implementation
  • One DB engine
  • OData solutions
  • Adapter based

Manual

(most flexible, but require time and qualification)

One DB engine

  • Mongoose (MongoDb)
  • Sequelize (SQL)
  • Nohm (Redis)

OData solutions

  • JayData
  • Breeze.js

Adapter based

(you could use any DB at the same time)

Js-Data

Why do I like it?

Main concept

Features

  • Async and Sync methods
  • Model lifecycle and hooks
  • Events and Change Detection
  • Static and instance methods, computed properties
  • Query syntax
  • Relations
  • Validations