DEM is a database structure been wrote in JSON format. DEM is designed for distributed development of a project database. DEM can describe whole database or just a part of them. DEM should be used with classic relational DBMS (MariaDB/MySQL, Postgres, ...), it is not for NoSQL DBs.
DEM is like XML mapping in Doctrine or in Hibernate but is focused on database structure only (PHP/Java objects structure is skipped).
{"DEM": {}}
Every node in DEM is a branch (user, sale) or nested branch (user/group, sale/order).
{
"DEM": {
"user": {
"group": {}
},
"sale": {
"order": {}
}
}
}
Path is a chain of branches starting from DEM node. Path in DEM is like a path in filesystem - absolute (starts with '/') or relative (starts with './', '../' or just a name).
/user/user/groupsale../order
All DEM nodes are branches except . nodes & .comment nodes. . nodes contain main information about database
structure. Assignment of this information depends from it placement in the DEM.
Any node named as .comment is a comment string:
{
"DEM": {
".comment": "This is demo DEM.",
"branch": {
".comment": "This is demo branch."
}
}
}
. node directly under the DEM is a string and means that described structure should be placed into appropriate
branch in common DEM when some DEM structures are merged:
{
"DEM": {
".": "/vendor/module/submodule",
"customer": {}
}
}
This DEM will be converted into:
{
"DEM": {
"vendor": {
"module": {
"submodule": {
"customer": {}
}
}
}
}
}
before merge.
DEM[.] always started from root. So
{ "DEM": { ".": "vendor/module/submodule" } }
is equal to
{ "DEM": { ".": "/vendor/module/submodule" } }
We can create many modules with DEMs inside (and with own mounting points), then combine all of them into one DEM structure. This allows us to create a single database from many DEMs.
If DEM[.] is omitted then all branches from this DEM will be mounted into the root.
branch[.] contains information about entity (table). Path to this branch is a table name:
{
"DEM": {
".": "/user",
"group": {
".": {}
}
}
}
Entity with name /user/group in DEM corresponds to table with name user_group in DB.
. structure:
".": {
"desc": "", // description: been converted to table comment;
"attr": {}, // attributes: table columns;
"index": {}, // indexes: unique & search;
"relation": {} // relations: foreign keys;
}
. node of a branch contains all information that is needed for table creation. Only branches with . node are converted into tables:
{
"DEM": {
".": "core",
"user": {
".": {},
"registry": {
".": {}
},
"group": {
"acl": {
".": {}
}
}
}
}
}
This means that 3 tables will be created:
core_usercore_user_registrycore_user_group_acl
Entity attribute is a table column. Table column has (Doctrine, Hibernate) own attributes:
-
name
-
comment
-
type
-
default
-
nullable
-
length
-
scale
-
precision
{ "DEM": { ".": "core", "user": { ".": {
"attr": { "id": { "type": "identity", "desc": "Eatery ID" }, "name": { "type": "string", "desc": "Eatery's default name (if not i18n)." } } } }}
Currently these types are available:
- binary
- boolean
- datetime
- decimal
- identity
- integer
- reference
- text
{
"DEM": {
".": "/vendor/module",
"user": {
".": {
"desc": "User data.",
"attr": {
"id": {
"desc": "Entity ID.",
"increment": true
},
"group_ref": {
"desc": "User Group reference.",
"reference": true
}
},
"index": {
},
"relation": {
"./group": {
"own": ["group_ref"],
"foreign": ["id"],
"on": {"delete": "restrict", "update": "restrict"}
}
}
},
"group": {
".": {
"desc": "User Group data.",
"attr": {
"id": {
"desc": "Entity ID.",
"increment": true
}
}
}
}
}
}
}