Skip to content

Stores

Where an app keeps what it keeps: memory, SQLite or PostgreSQL, with the same MongoDB semantics in all three, and blobs in the store, in files or in a bucket.

On this page 5

An app keeps everything in one store: in memory, in SQLite or in PostgreSQL. Moving from one to another changes one line.

Three stores, one behavior

memory is the reference. sqlite and postgres keep the same MongoDB semantics, and one conformance suite, stores/tests/, holds all three to it.

stores/README.md describes each one. It lists exactly which parts of the MongoDB collection API they support, and how.

ImportWhat it has
copilotz/stores/memorymemoryStore(): in memory, the reference
copilotz/stores/sqlitesqliteStore({ path }): node:sqlite or bun:sqlite, one file
copilotz/stores/postgrespostgresStore({ url, schema, tenant }) (a server, or PGlite in the process), postgresPool, copyTenant…
copilotz/stores/latencywithLatency(store, ms): a store with round trips, to measure

SQLite

SQLite opens node:sqlite on Node and Deno, and bun:sqlite on Bun. It also takes any database with the same small API, through sqliteStore({ path, open }), such as a Durable Object's.

PostgreSQL

The PostgreSQL store runs on Ominipg: a server for a postgres:// URL, or PGlite in the process. PGlite needs @electric-sql/pglite installed beside Copilotz.

A PostgreSQL store holds one tenant, an org. Many tenants share a schema, and the store itself keeps each apart. An org's rows copy elsewhere unchanged with copyTenant.

Blobs

Blobs are strings over 16 KiB and the files people send. They live in the store by default. They can also go elsewhere:

ImportWhat it has
copilotz/blobs/filesfileBlobs({ dir }): blobs as files
copilotz/blobs/httphttpBlobs({ url, headers }): blobs in a bucket (S3, GCS, R2…)
copilotz/blobs/gcsgcsBlobs({ bucket, prefix }): blobs in a Google Cloud Storage bucket, as the instance's service account