Data Model

Data Model is the definition of all database tables, their columns, the relationship between tables. One can also refer to these as the object model or domain model. It also includes other metadata such as the definition of code-value pairs.

The following diagram shows the object model. In a typical implementation, each class is equivalent to one or more tables in the database. Each class and its representation are specified using a JSON file. When the model is deployed on the server, it interprets JSON files and creates database tables, adds integrity checks (length, indexed, non-null, …). The server automatically publishes CRUD API, pagination API, getting and saving associated objects, retrieving object graph.

data-relations.png

The salient points of the above object models are:

  • “User” buys a policy. During purchase, user specifies an email.
  • If no “Account” exists with the given email, an “Account” is created.
  • “Policy” is associated with the Account. An account can have multiple policies.
  • “Policy” is associated with “Note”, “Doc” and “Claim” classes.

Take a quick peek at one of the class named "Policy" (more details will follow in another section)

{
  "name" : "Policy",
  "attributes" : [
    {
      "name" : "id",
      "type" : "biginteger",
      "persistent" : true,
      "primaryKey" : true,
      "systemAttr" : true
    },
    {
      "name" : "parentId",
      "type" : "biginteger",
      "indexed" : true,
      "persistent" : true
    },
    {
      "name" : "policyNumber",
      "type" : "string",
      "length" : 36,
      "persistent" : true
    },
    {
      "name" : "title",
      "type" : "string",
      "persistent" : true
    },
    {
    },
    {
    }
  ],
  "associations" : [
    {
      "name" : "files",
      "type" : "MANY_TO_ONE",
      "dir" : "CLS1_TO_CLS2",
      "class2Name" : "File",
      "orderBy" : "createdAt desc",
      "size" : 10,
      "start" : 1,
      "where" : "parentId='{{{id}}}'"
    },
    {
      "name" : "logs",
      "type" : "MANY_TO_ONE",
      "dir" : "CLS1_TO_CLS2",
      "class2Name" : "AuditLog",
      "orderBy" : "createdAt desc",
      "size" : 10,
      "start" : 1,
      "where" : "parentId='{{{id}}}'"
    },
    {
      "name" : "claims",
      "type" : "MANY_TO_ONE",
      "dir" : "CLS1_TO_CLS2",
      "class2Name" : "Claim",
      "orderBy" : "createdAt desc",
      "size" : 10,
      "start" : 1,
      "where" : "parentId='{{id}}}'"
    }
  ],
  "displayName" : "Policy",
  "nameInDS" : "Policy_tbl",
  "primaryKeyGenerator" : "serial",
  "tableCreateable" : true
}