Menu

📰
0

SQLite as a document database

dgl.cx·about 1 month ago
#MulV372G
Reading 0:00
15s threshold

SQLite has had JSON support for a while. However recently it added a killer feature: generated columns . (This was added in 3.31.0, released 2020-01-22.) This makes it possible to insert JSON straight into SQLite and then have it extract data and index them, i.e. you can treat SQLite as a document database. This has been possible with PostgreSQL and obviously is what something like Elastic provides but having it available in an embedded database is very nice for lightweight stuff. Let's get started: $ sqlite3 SQLite version 3.31.1 2020-01-27 19:55:54 Connected to a transient in-memory database. sqlite> CREATE TABLE t ( body TEXT, d INT GENERATED ALWAYS AS (json_extract(body, '$.d')) VIRTUAL); sqlite> insert into t values(json('{"d":"42"}')); sqlite> select * from t WHERE d = 42; {"d":"42"}|42 It's that simple, the d column is extracted from the provided JSON.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More