@velora-cms/db-adapter
v0.14.0
Published
Multi-dialect database adapter for Velora CMS (PostgreSQL, MySQL, SQLite)
Readme
@velora-cms/db-adapter
The database layer under Velora CMS: one
DatabaseAdapter interface, implemented identically for PostgreSQL,
MySQL, and SQLite, so nothing above it — @velora-cms/content-service,
@velora-cms/server, or a plugin's SimpleStorageAPI/StructuredStorageAPI
call — ever writes dialect-specific SQL or needs to know which database
is active.
npm install @velora-cms/db-adapterWho this is for
Most Velora users never touch this package: npm create velora wires up
the right adapter for you from the database you pick in setup. Reach for
it directly if you're building server-side tooling that needs to talk to
the content database in-process (a migration script, an import job), or
if you're curious what "the same behavior on three databases" actually
looks like as code.
Supported databases
Three dialects ship real, tested adapters: PostgreSQLAdapter (via
pg), MySQLAdapter (via mysql2), and SQLiteAdapter (via
better-sqlite3). A MockAdapter is also exported for tests. Every
method on DatabaseAdapter is required to behave the same way across
all three real dialects before it ships — that conformance is enforced
by a shared test suite (turbo run test:adapters) that runs the same
assertions against all three.
import { SQLiteAdapter } from "@velora-cms/db-adapter";
const adapter = new SQLiteAdapter();
await adapter.connect({ filename: "./velora.db" });
const roots = await adapter.getRootNodes({ limit: 20 });What's in it
DatabaseAdapter covers connection lifecycle, raw query/execute
plus transactions, the content tree (getChildren, getDescendants,
getAncestors, cursor-paginated, never an unbounded "load everything"
call), immutable content versioning (createContent,
insertContentVersion — no update method exists for a version, by
design), document types, templates, assets, media, the content trash/
restore lifecycle, and the plugin field-value storage tier. It also
exports applyMigrations for running per-dialect migrations and
validatePluginTableSchema/validateRowData — the guardrails behind a
plugin's opt-in StructuredStorageAPI table access.
Relationship to the rest of Velora
@velora-cms/content-service and @velora-cms/server are built
directly on this package; plugins never see it at all — they get
SimpleStorageAPI or StructuredStorageAPI from @velora-cms/plugin-sdk,
which is implemented on top of this adapter without ever handing a
plugin a raw connection.
Source & support
Source: velora-starter. Docs: https://docs.velora-cms.com. Apache-2.0.
