Frontmatter schema
Main source of inspiration - Astro Content Collections
Related:
Basic idea:
- folder represents table/collection
- folder name represents table name, or tag in disjoint union
- file represents row/document/tupple
- file path represents global unique ID
- slug represents per table unique ID
For each selected folder we can define schema.
Error behaviour
What to do if there is an error in one of documents?
- Report error
- then either:
- block whole database until error would be resolved
- exclude document with error from the index (until error would be resolved)
Extra fields
Options:
- allow fields that are not in schema
- remove all extra fields that are not present in schema
- optionally print warning when that happens
Shall schema be optional?
- On one side it is easier to get started if schema is optional
- On the other side one can always use
z.any()
- Astro uses convention of one schema per top level folder. But in our case this is not convinient
- Use one schema for root, with default type
undefined
and default schemaz.any()
- top level folder = type, but optional. If there is no config it would use default one (from root)
- shall we allow arbitrary paths (glob) for schemas
- what to do if more than one schema matches for file? Throw an error?
- Use one schema for root, with default type
Typescript
Let’s say we have collections:
Then frontmatter()
can be either:
or:
or:
theoretically it could also be:
But in this case field we can’t use field type
in orginial schemas.
Class
and default can be
SQL
for trivial types:
would be translated to
But for arrays we may need to use json_each()
:
would be translated to something like this:
Also need to check if there are issue with quoting.
Indexing, sorting, faceting
a
andb
- do not conflict, so we can simply putNULL
(in SQL terms) orundefined
(in JS terms) where they miss. Related: sorting can provide options forNULL FIRST
,NULL LAST
c
- present in both types, but do not conflict. So there are no issuesd
- conflicts. Even if we can build index for this mixed type, it is unclear how to sort mixed types. We can convert everything to string and sort, but would it make sense?
The simplest solution: do not allow to filter, sort, facet by mixed type columns.
Indexes
For inspiration:
- SQLite + Roaring Bitmaps
- pgfaceting + pg_roaringbitmap + pglite
- maybe https://www.sqlite.org/expridx.html
- https://dadroit.com/blog/json-querying/#section-6-how-to-use-indexing-for-query-optimization-over-json-data-in-sqlite
- LiteIndex: Memory-Efficient Schema-Agnostic Indexing for JSON documents in SQLite
Querying
One of options for querying data is to expose Drizzle ORM. But this exposes implementation details.