←back to thread

175 points frectonz | 4 comments | | HN request time: 0.802s | source

pglite-fusion is a PostgreSQL extension that allows you to embed SQLite databases into your PostgreSQL tables by enabling the creation of columns with the `SQLITE` type. This means every row in the table can have an embedded SQLite database.

In addition to the PostgreSQL `SQLITE` type, pglite-fusion provides the `query_sqlite`` function for querying SQLite databases and the `execute_sqlite` function for updating them. Additional functions are listed in the project’s README.

The pglite-fusion extension is written in Rust using the pgrx framework [1].

----

Implementation Details

The PostgreSQL `SQLITE` type is stored as a CBOR-encoded `Vec<u8>`. When a query is made, this `Vec<u8>` is written to a random file in the `/tmp` directory. SQLite then loads the file, performs the query, and returns the result as a table containing a single row with an array of JSON-encoded values.

The `execute_sqlite` function follows a similar process. However, instead of returning query results, it returns the contents of the SQLite file (stored in `/tmp`) as a new `SQLITE` instance.

[1] https://github.com/pgcentralfoundation/pgrx

1. zekenie ◴[] No.42183353[source]
I’m trying to think through when I’d reach for this over jsonb… I guess the fact that there’s an enforced schema? And that you could do aggregations on your SQLite db? Or maybe if you wanted to send the whole delete db to a client??
replies(1): >>42183675 #
2. sgarland ◴[] No.42183675[source]
> enforced schema

I have bad news for you [0] about SQLite’s view on schema consistency.

[0]: https://www.sqlite.org/quirks.html

replies(1): >>42186047 #
3. Tostino ◴[] No.42186047[source]
I love using the database as the source of truth for data consistency, and constraining your data to only be allowed in your database as long as it's in a valid state.

It's easy enough to replicate those constraints to the client if you want the client to do ahead of time validation, but your source of truth lives in the database...

I wouldn't survive with SQLite.

replies(1): >>42187284 #
4. sgarland ◴[] No.42187284{3}[source]
You can make it behave with its STRICT mode, but that’s fairly recent, and it’s also just upsetting that it has to exist in the first place.

Completely agree that the DB should be the arbiter of validity. Constraints are a good thing.