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.
| Import | What it has |
|---|---|
copilotz/stores/memory | memoryStore(): in memory, the reference |
copilotz/stores/sqlite | sqliteStore({ path }): node:sqlite or bun:sqlite, one file |
copilotz/stores/postgres | postgresStore({ url, schema, tenant }) (a server, or PGlite in the process), postgresPool, copyTenant… |
copilotz/stores/latency | withLatency(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:
| Import | What it has |
|---|---|
copilotz/blobs/files | fileBlobs({ dir }): blobs as files |
copilotz/blobs/http | httpBlobs({ url, headers }): blobs in a bucket (S3, GCS, R2…) |
copilotz/blobs/gcs | gcsBlobs({ bucket, prefix }): blobs in a Google Cloud Storage bucket, as the instance's service account |
Related
- Maintenance: SQL over HTTP, for operators who can't reach the database.
- Build Compass, Chapter 5: what the store's tables hold, and why the store has one writer at a time.
- Build Compass, Chapter 36: PostgreSQL and file blobs.