@molecule/api-project-archive-external-state-duckdb
Provider bond · project-archive-external-state · API (Node) · v1.1.0 · Apache-2.0
DuckDB external-state capture for project archives — copies a project's configured .duckdb database files (and their .wal siblings) into the archive and writes them back on restore
npm install @molecule/api-project-archive-external-state-duckdbnpm · Source on GitHub · Implements @molecule/api-project-archive
How it works
@molecule/api-project-archive-external-state-duckdb is a provider bond on the API (Node) side: it implements the project-archive-external-state core interface (@molecule/api-project-archive) with a concrete vendor or library behind it.
Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.
import { setExternalStateProvider } from '@molecule/api-project-archive'
import { createDuckdbExternalStateProvider } from '@molecule/api-project-archive-external-state-duckdb'
setExternalStateProvider(
createDuckdbExternalStateProvider({
databasePaths: (projectId) => [`/var/lib/app/${projectId}/app.duckdb`],
}),
)Works with: @molecule/api-project-archive
Reference
Capture and restore a project's DuckDB databases for
@molecule/api-project-archive.
It byte-copies the configured .duckdb files (and their .wal siblings)
into the archive, and writes them back on restore. That is the whole
package.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
import { setExternalStateProvider } from '@molecule/api-project-archive'
import { createDuckdbExternalStateProvider } from '@molecule/api-project-archive-external-state-duckdb'
setExternalStateProvider(
createDuckdbExternalStateProvider({
databasePaths: (projectId) => [`/var/lib/app/${projectId}/app.duckdb`],
}),
)
Type
provider
Installation
npm install @molecule/api-project-archive-external-state-duckdb @molecule/api-project-archive
API
Interfaces
DuckdbExternalStateConfig
How this deployment finds a project's DuckDB databases.
interface DuckdbExternalStateConfig {
/**
* The filesystem paths of every DuckDB database belonging to `projectId`.
*
* **This is a DECLARATION, not a search.** An empty array means the project
* genuinely owns none — and it is the ONLY way to say that. A path that is
* listed but missing is an ERROR, never an absence: a path template one
* directory off would otherwise capture nothing, report success, and let the
* caller destroy the only copy. Nothing else in a deployment reads this
* setting, so a wrong path has no other symptom.
*
* @param projectId - The project being archived or restored.
* @returns Its database file paths; `[]` when it owns none.
*/
databasePaths: (projectId: string) => readonly string[] | Promise<readonly string[]>
}
Functions
createDuckdbExternalStateProvider(config)
Create the provider.
function createDuckdbExternalStateProvider(
config: DuckdbExternalStateConfig,
): ProjectExternalStateProvider
config— How to find a project's database files.
Returns: A provider ready to bond with setExternalStateProvider.
Constants
KIND
Recorded on every record this provider produces; routes restores back here.
const KIND: 'duckdb'
Core Interface
Implements @molecule/api-project-archive interface.
Injection Notes
Requirements
Peer dependencies:
@molecule/api-project-archive^1.0.1
Runtime Dependencies
@molecule/api-project-archive
If the database file lives inside the project's source tree and is
committed, you do not need this package — whatever archives the source tree
already carries it, and capturing it here duplicates the bytes. It exists for
a database kept OUTSIDE the tree, or one the project's .gitignore excludes.
A byte copy, not EXPORT DATABASE, deliberately. DuckDB holds a
per-process WRITE lock on an open database file, so the archiver cannot open
a live read-write database at all — a copy is the only whole-file read
available. The .wal sibling is captured with the main file and replayed by
DuckDB on the next open, so the pair is the database's current state. For the
cleanest copy, stop the app (or run CHECKPOINT) first.
A configured path with no file is an ERROR, not an absence. A path
template one directory off would otherwise capture nothing and report
success, and the caller destroys the project on a successful capture. Only
an empty databasePaths result declares that a project owns no database.
Never two writers on one file. DuckDB allows one read-write process per database file; restore only writes files, so it is safe, but the restored file must not be open elsewhere while the app that owns it boots.