Skip to main content

Crate jerrycan_db

Crate jerrycan_db 

Source
Expand description

Database extension: one URL-driven Db over SQLite and Postgres (sea-orm’s DatabaseConnection), module-owned dual-dialect migrations, and a deterministic ?$n translator (placeholders are library-owned; ours is quote-blind and safe because generated SQL never embeds string literals).

Re-exports§

pub use sea_orm;
pub use sea_query;
pub use sea_query_binder;
pub use sqlx;

Structs§

Db
The database dependency: a cloneable connection handle. Register app-wide with App::new().extend(db) (or .provide(db)extend is the §6 seam).
Migration
One migration, both dialects. Generated apps embed these via the tool-owned app/src/migrations.rs; modules own the .sql files (spec §5 anatomy).
OwnedMigration
Runtime-loaded migration (CLI jerrycan db migrate reads module files from disk). The owned twin of Migration; both delegate to the same runner.

Enums§

Backend
Which engine the connection speaks. Generated code branches on this for the few statements that genuinely differ (insert-id strategies, DDL).

Constants§

MIGRATION_ADVISORY_KEY
The reserved 64-bit Postgres advisory-lock key that serializes a migration run. Concurrent migrators (e.g. several app nodes booting at once) all take pg_advisory_xact_lock(MIGRATION_ADVISORY_KEY) at the top of the migration transaction; the first holder applies the DDL and the others block, then proceed and find every migration already recorded (applying nothing). The lock auto-releases at COMMIT. Distinct from jerrycan_jobsJOBS_CRON_ADVISORY_KEY so a migration and a cron tick never contend. Value is an arbitrary jerrycan-migrate magic constant (“jCmig” + 0001).

Functions§

db_error
Map any sea-orm error to a stable JC code without leaking internals; the underlying detail goes to stderr for the operator. Unique-key violations are the client’s fault (a re-POSTed id), not a server fault — they map to 409 JC0409 so duplicate writes can’t pollute 5xx alerting.
translate_placeholders
?$1, $2, … for Postgres; identity for SQLite. Quote-blind by design: generated SQL never embeds string literals (binds carry all values).