Preview of new JSON default format for Datasette I really liked that, so I’ve implemented it here as well.Įach entry (and quotation and link) now gets a block in the sidebar that looks like this:Īs a long-time fan of faceted search interfaces I really like this upgrade-it helps indicate at a glance the kind of content I have stashed away in my blog’s archive. I noticed that Will Larson’s blog shows little numbers next to the tags indicating how many times they have been used. This defaults to returning results as a JSON array, but you can add -csv or -tsv or other options to get the results back in different output formats. $ sqlite-utils first.db -attach second second.db ' select * from table_in_first union all select * from second.table_in_second ' Here’s an illustrative example query that performs a UNION across the sqlite_master metadata table in two databases: The demo now exposes two databases using this feature. Run Datasette with the new -crossdb option and the first ten databases passed to Datasette will be ATTACHed to an in-memory database available at the /_memory URL. In the end, I decided on the simplest option that would unlock the feature. It took me quite a while to settle on a design-SQLite defaults to only allowing ten databases to be attached together, and I needed to figure out how multiple connected databases would fit with the design of the rest of Datasette. I’ve wanted to add support for cross-database queries to Datasette since May 2018. You can then join against them, combine them with UNION and generally treat them as if they were another table in your first connected database. Run the following SQL: ATTACH 'other.db' AS other Īnd now you can reference tables in that database as other.tablename. The secret sauce is the ATTACH DATABASE command. All you need is a disk volume and you can create as many SQLite databases as you like.Ī lesser known feature of SQLite is that you can run queries, including joins, across tables from more than one database. I really love this characteristic-it makes them easy to create, copy and move around. SQLite databases are single files on disk. I released Datasette 0.55 and sqlite-utils 3.6 this week with a common theme across both releases: supporting cross-database joins. Cross-database queries in SQLite (and weeknotes)
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |