Read: Class 04 Data Modeling - 401-advanced-javascript-muna/amman-javascript-401d1 GitHub Wiki

Javascript Data Modeling

Data modeling in Javascript is the process of taking a real world or conceptual idea and encoding it into Javascript’s built in data types.

Modeling behaviors

  • CRUD - Basic Data Operations
  • CREATE - Add a record to a data store
  • READ - Retrieve a record from a data store
  • UPDATE - Update a record within a data store
  • DELETE - Remove a record from a data store

Interfaces & Services – The “Repository” design pattern

“A modeling technique providing common access points in an API (i.e. the CRUD methods) that is agnostic to the storage medium and techniques.”

This is a layer of abstraction that sits between the code and the actual data source.

Consider the simple example below. We have a data model that seems to use PostgreSQL to store data. In another module, we create a new instance and then .save() and maybe .delete() records through it. That client library (perhaps it’s an express server) does not know (or care) how the Location actually works. It just calls the CRUD style methods that it provides. If at some later date, the developer of the Location data model changes the database from PostgreSQL to something else … so long as the methods are the same, any other apps that use Location will work without any modification.

This represents a service that is loosely coupling the dependencies (specific data services) through behaviors