Live data from Hacker News

SQLite as a Document Database (2020)

dgl.cx

11–20 of 63 posts

Re: SQLite as a Document Database (2020)

#13

Why don’t you use MongoDB? MongoDB is web scale. https://youtu.be/b2F-DItXtZs?is=HlayyJ_DPb8NzbS4 (lol! couldn’t resist)

Wait, are all of those shared online?

That was the part I really missed from my Google days.

That, insane achievement badges, and terrible-ideas-discuss (if anyone at Google is reading this, I have one word for you: dirigibles). It was like /r/NonCredibleDefense but for Google.

Re: SQLite as a Document Database (2020)

#15
A long time ago, I wrote an ORM to serialize/deserialize object data seamlessly into SQLite, with massive arrays of floats being stored as blobs.

In code, I could effectively mark which class members need to be stored/restored, and optionally provide a custom serialization function for them if needed.

The latter was effectively never necessary, because all the bases types and multi-dimensional arrays were handled by templates.

Really wish I open-sourced that thing then, but the corporate bureaucracy around that was tricky.

I remember sufficiently little about implementation details now that I think I can get to writing it again, without producing a copypasta of that code - and maybe I should :)

Re: SQLite as a Document Database (2020)

#19

Why do people say document database when they really just mean json database?

The 1st edition CouchDB book from 2010 explained it like this:

> We write software to improve our lives and the lives of others. Usually this involves taking some mundane information—such as contacts, invoices, or receipts—and manipulating it using a computer application. CouchDB is a great fit for common applications like this because it embraces the natural idea of evolving, self-contained documents as the very core of its data model.

> Self-Contained Data

> An invoice contains all the pertinent information about a single transaction—the seller, the buyer, the date, and a list of the items or services sold. As shown in Figure 1, “Self-contained documents”, there’s no abstract reference on this piece of paper that points to some other piece of paper with the seller’s name and address. Accountants appreciate the simplicity of having everything in one place. And given the choice, programmers appreciate that, too.

> Yet using references is exactly how we model our data in a relational database! Each invoice is stored in a table as a row that refers to other rows in other tables—one row for seller information, one for the buyer, one row for each item billed, and more rows still to describe the item details, manufacturer details, and so on and so forth.

https://guide.couchdb.org/editions/1/en/why.html

Iow, a document database stands in contrast to a relational db in that these JSON things we store in them are more stand-alone “documents” compared to storing data in rows and columns in a relational db like PostgreSQL or SQLite.

Re: SQLite as a Document Database (2020)

#20
obviously the example is contrived, but it seems strange me that they are not storing the json in its own column - just extracting a single key from it and storing in a generated column. Why not do that in the app code if youre just going to discard the rest of the json?

Here's an example i saw yesterday from mariadb, which is improving its json support in its upcoming releases.

https://mariadb.com/docs/server/ha-and-performance/optimizat...

``` CREATE TABLE t1 (json_data JSON); INSERT INTO t1 VALUES('{"column1": 1234}'); INSERT INTO t1 ... ```

In order to do efficient queries over data in JSON, you can add a virtual column, and an index on that column:

``` ALTER TABLE t1 ADD COLUMN vcol1 INT AS (cast(json_value(json_data, '$.column1') AS INTEGER)), ADD INDEX(vcol1);

```

Post reply on HN