[draft RFC] Glob all files into an in-memory database, introducing "Astro.db" #252
lukeocodes
started this conversation in
Proposal
Replies: 1 comment 1 reply
-
+1 we also believe this is a step towards incremental building and would hope there would be adapters for this too (e.g. offload to SQLite, or some K/V store). A prior art similar is how Obsidian has an internal database that can be queried using some basic SQL, a feature like this allows for Astro and framework components to get data via these queries (think Last X blog posts) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Below is a draft of an RFC. It's very specific to my usecase and I'd like some feedback/suggestions before I submit this as an RFC.
Summary
Glob all files from a specific directory (e.g.
/content
) and load them into an in-memory javascript document oriented database (e.g. LokiJS).Example
Assuming all content in
/content/blog
had been ingested when running Astro, I see us using it like this when creating dynamic page routes.Motivation
As we're building our new site, I've noticed an extraordinary amount of globs. We also sometimes need to
import.glob.meta
for content in files where we need the filename as well as the content (JSON files). This leads to a fair amount of quite repetitive code through the codebase.For example, this is just from the blog microsite.
Loading all our blog posts:
All our authors and the filename (to use as a slug), which is also repeated for all our categories:
All unique post tags:
Not an exhaustive list. We still load the posts for each category, each tag, each author, the author and category for each post display page, and more.
Detailed design
...wip...
Drawbacks
Why should we not do this? Please consider:
Alternatives
Adoption strategy
I believe a new top-level feature on the Astro class will limit the impact on users who do not plan to implement this feature. Something like
Astro.db
provides a clear and new interface to be able to query for any content that has been loaded into the database.Please consider:
Unresolved questions
Beta Was this translation helpful? Give feedback.
All reactions