Mantra official documentation
06-entities-ids.md
06 Red Entities rows ids
Red Entities automatically adds the property "ID" (upper case) to each entity it creates.
Given the sample schema:
const sampleSchema = {
entities: [
{
name : "users",
fields: [
{ name : "mail", type : "string" },
{ name : "password", type : "string" },
{ name : "created", type : "datetime"}
],
indexes: [ ["mail"], ["created"] ],
restrictions: {
unique: [ ["mail"] ]
}
}
]
}
, when it is created by Red Entities, a field named as "ID" will be added of type "string".
Thus, the property "PRIMARY KEY" is added to ID field as well within the "CREATE TABLE" sql sentence.
By default, each new field is added with a new ID that consists of a random string (generated by shortid library).
On the other hand, given
const db = await RedEntities.Entities(sampleSchema);
, you can get new IDs with
const netId = db.NewID();