Embed an SQLite database in your PostgreSQL table. AKA multitenancy has been solved.
2.5K
Embed an SQLite database in your PostgreSQL table. AKA multitenancy has been solved.
-- Load PG extension
CREATE EXTENSION pglite_fusion;
-- Create table wit an SQLite column
CREATE TABLE people (
name TEXT NOT NULL,
database SQLITE DEFAULT execute_sqlite(
empty_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';
-- Fetch frectonz's info form db
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';
Content type
Image
Digest
sha256:664ec5668…
Size
179.5 MB
Last updated
about 2 months ago
docker pull frectonz/pglite-fusion