Embed an SQLite database in your PostgreSQL table. AKA multitenancy has been solved.
Nix
833
53 commits
updated Aug 13, 2026
Embed an SQLite database in your PostgreSQL table. AKA multitenancy has been solved.
Run a PostgreSQL 18 database that has pglite-fusion already installed.
docker run --network=host frectonz/pglite-fusion
pglite-fusion is also distributed with other PostgreSQL versions.
docker run --network=host frectonz/pglite-fusion:pg14
docker run --network=host frectonz/pglite-fusion:pg15
docker run --network=host frectonz/pglite-fusion:pg16
docker run --network=host frectonz/pglite-fusion:pg17
docker run --network=host frectonz/pglite-fusion:pg18
Connect to the PostgreSQL database using psql.
psql postgresql://postgres@localhost:5432/
Here's some demo usage.
-- Load PG extension
CREATE EXTENSION pglite_fusion;
-- Create a table with an SQLite column
CREATE TABLE people (
name TEXT NOT NULL,
database SQLITE DEFAULT init_sqlite('CREATE TABLE todos (task TEXT)')
);
-- Insert a row into the people table
INSERT INTO people VALUES ('frectonz');
-- Create a todo for "frectonz"
UPDATE people
SET database = execute_sqlite(
database,
'INSERT INTO todos VALUES (''solve multitenancy'')'
)
WHERE name = 'frectonz';
-- Create a todo for "frectonz"
UPDATE people
SET database = execute_sqlite(
database,
'INSERT INTO todos VALUES (''buy milk'')'
)
WHERE name = 'frectonz';
-- Fetch frectonz's info
SELECT
name,
(
SELECT json_agg(get_sqlite_text(sqlite_row, 0))
FROM query_sqlite(
database,
'SELECT * FROM todos'
)
) AS todos
FROM
people
WHERE
name = 'frectonz';
git clone [email protected]:frectonz/pglite-fusion.git
cd pglite-fusion
nix develop
cargo pgrx init --pg18 download # this will take some time, since you are compiling postgres from source
cargo pgrx run # this will drop you into a psql repl, you can then follow the example shown above
Every function is parallel-safe except for import_sqlite_from_file and export_sqlite_to_file.
empty_sqliteCreates an empty SQLite database and returns it as a binary object. This can be used to initialize an empty SQLite database in a PostgreSQL column.
SELECT empty_sqlite();
query_sqliteExecutes a SQL query on a SQLite database stored as a binary object and returns the result as a table of JSON-encoded rows. This function is useful for querying SQLite databases stored in PostgreSQL columns.
sqlite: The SQLite database to query, stored as a binary object.query: The SQL query string to execute on the SQLite database.SELECT * FROM query_sqlite(
database,
'SELECT * FROM todos'
);
execute_sqliteExecutes a SQL statement (such as INSERT, UPDATE, or DELETE) on a SQLite database stored as a binary object. The updated SQLite database is returned as a binary object, allowing further operations on it.
sqlite: The SQLite database to execute the SQL query on, stored as a binary object.query: The SQL statement to execute on the SQLite database.UPDATE people
SET database = execute_sqlite(
database,
'INSERT INTO todos VALUES (''solve multitenancy'')'
)
WHERE name = 'frectonz';
init_sqliteCreates an SQLite database with an initialization query already applied on it. This can be used to initialize a SQLite database with the expected tables already created.
query: The SQL statement to execute on the SQLite database.
CREATE TABLE people (
name TEXT NOT NULL,
database SQLITE DEFAULT init_sqlite('CREATE TABLE todos (task TEXT)')
);
get_sqlite_textExtracts a text value from a specific column in a row returned by query_sqlite. Use this function to retrieve text values from query results.
sqlite_row: A row from the results of query_sqlite.index: The index of the column to extract from the row.SELECT get_sqlite_text(sqlite_row, 0)
FROM query_sqlite(database, 'SELECT * FROM todos');
get_sqlite_integerExtracts an integer value from a specific column in a row returned by query_sqlite. Use this function to retrieve integer values from query results.
sqlite_row: A row from the results of query_sqlite.index: The index of the column to extract from the row.SELECT get_sqlite_integer(sqlite_row, 1)
FROM query_sqlite(database, 'SELECT * FROM todos');
get_sqlite_realExtracts a real (floating-point) value from a specific column in a row returned by query_sqlite. Use this function to retrieve real number values from query results.
sqlite_row: A row from the results of query_sqlite.index: The index of the column to extract from the row.SELECT get_sqlite_real(sqlite_row, 2)
FROM query_sqlite(database, 'SELECT * FROM todos');
list_sqlite_tablesLists all table names present in the SQLite database.
sqlite: A SQLite database stored as a binary blob.SELECT table_name FROM list_sqlite_tables(database);
sqlite_schemaRetrieves the SQL schema of each table in the SQLite database, the CREATE TABLE statements for each table in the SQLite database.
sqlite: A SQLite database stored as a binary blob.SELECT schema_sql FROM sqlite_schema(database);
import_sqlite_from_fileLoads a SQLite database from a file into PostgreSQL.
path: The file path of the SQLite database to load.SELECT import_sqlite_from_file('/tmp/mydb.sqlite');
export_sqlite_to_fileSaves the SQLite database to a file on disk.
sqlite: The SQLite database.path: The file path where the database should be saved.SELECT export_sqlite_to_file(database, '/tmp/mydb.sqlite');
vacuum_sqliteRuns the SQLite VACUUM command to optimize storage by reclaiming unused space.
sqlite: The SQLite database.SELECT vacuum_sqlite(database);
count_sqlite_rowsCounts the number of rows in a specified table within the SQLite database.
sqlite: The SQLite database.table: The name of the table to count rows from.SELECT count_sqlite_rows(database, 'users');
617 followers · starred Nov 2024
480 followers · starred Nov 2024
1,186 followers · starred Nov 2024
598 followers · starred Nov 2024
Embed an SQLite database in your PostgreSQL table. AKA multitenancy has been solved.
Nix
833
53 commits
updated Aug 13, 2026
Embed an SQLite database in your PostgreSQL table. AKA multitenancy has been solved.
Run a PostgreSQL 18 database that has pglite-fusion already installed.
docker run --network=host frectonz/pglite-fusion
pglite-fusion is also distributed with other PostgreSQL versions.
docker run --network=host frectonz/pglite-fusion:pg14
docker run --network=host frectonz/pglite-fusion:pg15
docker run --network=host frectonz/pglite-fusion:pg16
docker run --network=host frectonz/pglite-fusion:pg17
docker run --network=host frectonz/pglite-fusion:pg18
Connect to the PostgreSQL database using psql.
psql postgresql://postgres@localhost:5432/
Here's some demo usage.
-- Load PG extension
CREATE EXTENSION pglite_fusion;
-- Create a table with an SQLite column
CREATE TABLE people (
name TEXT NOT NULL,
database SQLITE DEFAULT init_sqlite('CREATE TABLE todos (task TEXT)')
);
-- Insert a row into the people table
INSERT INTO people VALUES ('frectonz');
-- Create a todo for "frectonz"
UPDATE people
SET database = execute_sqlite(
database,
'INSERT INTO todos VALUES (''solve multitenancy'')'
)
WHERE name = 'frectonz';
-- Create a todo for "frectonz"
UPDATE people
SET database = execute_sqlite(
database,
'INSERT INTO todos VALUES (''buy milk'')'
)
WHERE name = 'frectonz';
-- Fetch frectonz's info
SELECT
name,
(
SELECT json_agg(get_sqlite_text(sqlite_row, 0))
FROM query_sqlite(
database,
'SELECT * FROM todos'
)
) AS todos
FROM
people
WHERE
name = 'frectonz';
git clone [email protected]:frectonz/pglite-fusion.git
cd pglite-fusion
nix develop
cargo pgrx init --pg18 download # this will take some time, since you are compiling postgres from source
cargo pgrx run # this will drop you into a psql repl, you can then follow the example shown above
Every function is parallel-safe except for import_sqlite_from_file and export_sqlite_to_file.
empty_sqliteCreates an empty SQLite database and returns it as a binary object. This can be used to initialize an empty SQLite database in a PostgreSQL column.
SELECT empty_sqlite();
query_sqliteExecutes a SQL query on a SQLite database stored as a binary object and returns the result as a table of JSON-encoded rows. This function is useful for querying SQLite databases stored in PostgreSQL columns.
sqlite: The SQLite database to query, stored as a binary object.query: The SQL query string to execute on the SQLite database.SELECT * FROM query_sqlite(
database,
'SELECT * FROM todos'
);
execute_sqliteExecutes a SQL statement (such as INSERT, UPDATE, or DELETE) on a SQLite database stored as a binary object. The updated SQLite database is returned as a binary object, allowing further operations on it.
sqlite: The SQLite database to execute the SQL query on, stored as a binary object.query: The SQL statement to execute on the SQLite database.UPDATE people
SET database = execute_sqlite(
database,
'INSERT INTO todos VALUES (''solve multitenancy'')'
)
WHERE name = 'frectonz';
init_sqliteCreates an SQLite database with an initialization query already applied on it. This can be used to initialize a SQLite database with the expected tables already created.
query: The SQL statement to execute on the SQLite database.
CREATE TABLE people (
name TEXT NOT NULL,
database SQLITE DEFAULT init_sqlite('CREATE TABLE todos (task TEXT)')
);
get_sqlite_textExtracts a text value from a specific column in a row returned by query_sqlite. Use this function to retrieve text values from query results.
sqlite_row: A row from the results of query_sqlite.index: The index of the column to extract from the row.SELECT get_sqlite_text(sqlite_row, 0)
FROM query_sqlite(database, 'SELECT * FROM todos');
get_sqlite_integerExtracts an integer value from a specific column in a row returned by query_sqlite. Use this function to retrieve integer values from query results.
sqlite_row: A row from the results of query_sqlite.index: The index of the column to extract from the row.SELECT get_sqlite_integer(sqlite_row, 1)
FROM query_sqlite(database, 'SELECT * FROM todos');
get_sqlite_realExtracts a real (floating-point) value from a specific column in a row returned by query_sqlite. Use this function to retrieve real number values from query results.
sqlite_row: A row from the results of query_sqlite.index: The index of the column to extract from the row.SELECT get_sqlite_real(sqlite_row, 2)
FROM query_sqlite(database, 'SELECT * FROM todos');
list_sqlite_tablesLists all table names present in the SQLite database.
sqlite: A SQLite database stored as a binary blob.SELECT table_name FROM list_sqlite_tables(database);
sqlite_schemaRetrieves the SQL schema of each table in the SQLite database, the CREATE TABLE statements for each table in the SQLite database.
sqlite: A SQLite database stored as a binary blob.SELECT schema_sql FROM sqlite_schema(database);
import_sqlite_from_fileLoads a SQLite database from a file into PostgreSQL.
path: The file path of the SQLite database to load.SELECT import_sqlite_from_file('/tmp/mydb.sqlite');
export_sqlite_to_fileSaves the SQLite database to a file on disk.
sqlite: The SQLite database.path: The file path where the database should be saved.SELECT export_sqlite_to_file(database, '/tmp/mydb.sqlite');
vacuum_sqliteRuns the SQLite VACUUM command to optimize storage by reclaiming unused space.
sqlite: The SQLite database.SELECT vacuum_sqlite(database);
count_sqlite_rowsCounts the number of rows in a specified table within the SQLite database.
sqlite: The SQLite database.table: The name of the table to count rows from.SELECT count_sqlite_rows(database, 'users');
617 followers · starred Nov 2024
480 followers · starred Nov 2024
1,186 followers · starred Nov 2024
598 followers · starred Nov 2024