←back to thread

175 points frectonz | 10 comments | | HN request time: 0.623s | source | bottom

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. aerzen ◴[] No.42183560[source]
Ok, hear me out: what if we make something that takes a postgres database dir, tars it together and encodes it as a binary blob in SQLite?

We could have SQLite within postgres within sqlite within postgres! Is it practical or even slightly useful? Of course not - but it's SQL databases all the way down. Not that this is a good thing in itself.

replies(7): >>42183593 #>>42183707 #>>42183733 #>>42185175 #>>42186156 #>>42186434 #>>42186712 #
2. frectonz ◴[] No.42183593[source]
My next project
3. c0balt ◴[] No.42183707[source]
Take it one step further, the table-oriented database(tm) , embed clickhouse, MongoDB, Redis and PostgreSQL to ensure you have more flexibility than anyone can utilize efficiently. The one database to rule them all.
replies(1): >>42188798 #
4. imhoguy ◴[] No.42183733[source]
No need for `tar`, there is "SQLite Archive" https://www.sqlite.org/sqlar.html
5. p4bl0 ◴[] No.42185175[source]
We need to go deeper” (https://i.kym-cdn.com/photos/images/newsfeed/000/384/176/d2f...)
6. vivzkestrel ◴[] No.42186156[source]
next stop: mongodb inside sqlite inside postgresql
7. traeregan ◴[] No.42186434[source]
This is some kind of RDBMS mutant CRUDucken.
replies(1): >>42188867 #
8. eastbound ◴[] No.42186712[source]
Giving @Transactional(NESTED) a whole new meaning.
9. luismedel ◴[] No.42188798[source]
Now you only need support for qcow columns which you can mount in your embedded engines....et volia, enjoy your storage and compute separation.
10. sgarland ◴[] No.42188867[source]
‘Tis the season.