A database where one entity can be many things
OmniCore.Database is a document database with its own storage engine, and the HTTP API every other part of OmniCore talks to. Its defining idea: an entity isn't limited to one type.
The model
Fields, perspectives and entities
A field is a named, typed value in a global catalogue. A perspective (an interface) is an ordered set of fields, each required or optional. An entity is a JSON document that implements any number of perspectives.
Fields are shared: if an entity is both a Contact and a Customer, its first name is one value that both forms show. Removing a perspective keeps the values, and adding it back restores them.
What the database does for you
Validation on every write
Every perspective an entity names must exist, every field must hold its type, and every required field must be set. All problems are reported together, and nothing is written if any check fails.
Referential integrity
One-to-many, many-to-one and one-to-one relationships between perspectives, checked on every add, update and delete. Deleting an entity that others refer to is refused.
Optimistic concurrency
Every entity has a version, sent as an ETag. Send it back with If-Match and a stale write is refused instead of overwriting someone else's change.
A query language
Filter with = != < <= > >= ~=, &, | and parentheses; sort, select and page. Values are converted to the field's type when the query is parsed, so mistakes are reported, not silently empty.
Aggregation
Grouped totals with cnt, sum, avg, min and max, a $having filter and sorting over the results, all under the caller's permissions.
Views
Named, searchable, sortable tables over one perspective. A view reports problems when the schema changes under it, rather than failing in surprising ways.
Resources
Files stored beside the data: images, scripts, stylesheets and web part packages, public or for signed-in users, with ETags and range requests.
Plugins
Code that runs in the background after changes are saved, in its own load context, so it can be replaced without a restart.
A storage engine written for this model
Not a layer over another database: the record format, the log and the indexes are OmniCore's own.
An append-only record log
Every write is appended to one log file, the source of truth. Writes are flushed to disk before the server answers, unless you choose speed over power-cut safety.
B+ tree field indexes
Index any field but a Json one. Queries use indexes to narrow the candidates and to sort, and Explain shows exactly what a query will do.
Compaction and recovery
Compaction rewrites the log with only live data and rebuilds the indexes. At start-up the log is replayed, and a torn final write is discarded.