-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Context
Making cross version CRUD operations (due to inheritance) is a bit odd.
The state implementation is split into two views state (active) and state_all (across all versions)to a) avoid accidental all version queries and b) because specifying the version_id in every query is annoying.
We had two options to achieve a and b:
- One unified view that filters the
version_idcolumn by default for the active version - Split both views and avoid a default filter.
We choose option 2 as we believed option 1, albeit a nicer DX, would break SQL standards of defining a default filter. For example, the implicit active_version filter will likely not show up in a SQL explain prompt.
Problems
Global entities
some entities are global (change_author), which leads to a weird api chaos of inserting into state_all instead of state instead of just defaulting the version_id to global.
// insert some entity which is global by default (changes, versions, etc)
await lix.db
.insertInto("change")
.values({
id: "c0"
})
.execute();
// 😵💫 confusion moment "why do i need to use _all api here?"
await lix.db
.insertInto("change_author_all")
.values([
{
change_id: "c0",
account_id: account.id,
lixcol_version_id: "global",
},
])
.execute();A better API would be to directly insert into change_author and either manually specifying the version_id (but without the state_all confusion)
//
await lix.db
.insertInto("change_author")
.values([
{
change_id: "c0",
account_id: account.id,
lixcol_version_id: "global",
},
])
.execute();
Or even better, specify a default version_id on the schema. Then, no version id needs to be specified at all.
export const LixChangeAuthorSchema = {
"x-lix-key": "lix_change_author",
"x-lix-version": "1.0",
+ "x-lix-default_version-id": "global",
...
}