I had to knock together an embedded database as a proof-of-concept the other day, and had a couple of passes through making some JSON queryable via SQL and SQLite (yes, I know what you’re thinking - Postgres wasn’t an option).
Obviously I’ve changed the examples from the data types and purpose of what I was doing, but hey. Let’s just say it was taking from a wide row and grabbing some particular JSON fields we cared about querying.
Anyway, brewed this up initially:
Then refactored using comp
:
This means that we can leverage some lazy behaviour to keep file loading under control and deal with larger inputs more gracefully. Finally, we end up with:
Not too shabby for a quick hack.