What I’m trying to do:
Begin the design of some Anvil-centric database support logic.
SQL databases have great built-in support for enforcing constraints at multiple levels:
- individual column values (e.g., the value in column
age
cannot be NULL; it must be a whole number in the range 0 to 120). - entire rows (e.g., the value in column
from_date
must be strictly less than the value in columnuntil_date
) - between rows in the same table (e.g., values in column
customer_id
must be unique in this table) - between rows in different tables (e.g.,
customer_id
in theorders
table must have a corresponding row in thecustomers
table; no anonymous or fictitious orders are allowed) - within a column value (e.g., a JSON-valued column – a SimpleObject, if you prefer – should conform to a specific JSON Schema).
This alleviates much of the pain of the Garbage-In, Garbage-Out principle: it’s that much harder for garbage to get in, in the first place.
Anvil has almost no enforcement mechanisms for such constraints. On the other hand, it has some other, incredible features:
- Multiple Apps per account
- Multiple databases per App
- Sharing of tables between databases, both within and between Apps.
Unquestionably, this makes it hard to even express a constraint. How do you reliably identify even a single column, much less a value buried deep in a SimpleObject column?
Oddly enough, there may an existing framework we can use, to write down such references. It’s even intended to be machine-parseable, which is critical if we want to build automation on top of it. It’s the Uniform Resource Identifier, or URI. It’s expressly intended for identifying locations within a hierarchical system, which our databases surely are.
The contents of your browser’s address bar provides an example of a URI.
What do you think so far?