dberta.scheme - cieszynski/dberta.js GitHub Wiki
Scheme
Syntax
{
VERSION: {
STORENAME: DEFINITION,
STORENAME: DEFINITION,
...
}
}
where
VERSION
a number greater than 0 to specify the version to which the name of the store(s)
and the definition are applied.
STORENAME
The name of the new object store to be created. Note that it is NOT possible
to create an object store with an empty name. Also, "transaction" as store name
isn't allowed.
If you name a store in different versions the store get deleted and new created every time, so all data in the store get lost. In this situation you need a backup strategy to restore the data between different versions.
{ // BAD!
3: { // current version
user: "@id, firstname, lastname"
},
2: { // deleted
user: "@id, firstname"
},
1: { // deleted
user: "@id, name"
}
}
{ // BETTER!
// current version is
// user: "@id, firstname, lastname"
// event: "@id, date"
// order: "@id, customer, income
3: {
order: "@id, customer, income
},
2: {
event: "@id, date"
},
1: {
user: "@id, firstname, lastname"
}
}
DEFINITION
A string to define the key and possible indices. Keys and indices are separated by commas. Everything before the first comma defines the key, everything after that one or more indices.
The keypath and index names can be prefixed:
@
the key get autoincremented.
!
the index must be unique.
*
the index will add an entry in the index for each array element when the index resolves to an array.
name1+name2
To create compound keys or indeces concat the names with a plus sign.
Examples
// out-of-line key, no indeces
""
// out-of-line key, autoincrement, no indeces
"@"
// in-line key with keypath "id", autoincrement
// no indeces
"@id"
// out-of-line key
// index "firstname"
", firstname"
// in-line key
// keypath "id", autoincrement
// index "firstname"
"@id, firstname"
// in-line key with keypath "id", autoincrement,
// indeces "firstname" and "lastname"
"@id, firstname, lastname"
// in-line key with keypath "id", autoincrement,
// indeces "firstname", "lastname" and "uuid"
// "uuid" has to be unique
"@id, firstname, lastname, !uuid"
// in-line key with keypath "id", autoincrement,
// two indeces "firstname" and "lastname"
// the index will add an entry in the index for each array
// element when "firstname" resolves to an array
"@id, *firstname, lastname"
// in-line key with keypath "id", autoincrement,
// indeces "firstname" "lastname" and "firstname+lastname"
// "firstname+lastname" is a compound index
"@id, firstname, lastname, firstname+lastname"
// in-line key with keypath {my:{key:N}}, autoincrement
// index "firstname"
"@my.key, firstname"
// compound key
// index "firstname"
"firstname+lastname, firstname"