Expand description
arcature-data — the Arcature high-level data layer over arcature-db.
AP2.1-6 (ADR-0006): a high-level model/query experience for ordinary CRUD
over SeaORM, preserving the SeaORM and SQLx escape hatches. No new database
engine, no ORM, no hidden global pool, no task-local connection, and no
request-global DB. Every public API takes the Db handle (or the
DatabaseConnection / PgPool it exposes) by reference — ownership is
explicit on every call.
§What this crate owns
- Explicit-ownership query ergonomics over SeaORM entities: a typed
Query<E>bound to a&Db, reached on the golden path asEntity::query(&db)via the blanketQueryModeltrait (no application trait implementation required — it works for any SeaORMEntity). - Vertical slices: find by primary key, filter, order, paginate
(
Page<T>), eager-load typed relations, and CRUD — all carrying the&Dbso the caller never re-passesdb.orm()on every terminal call. - Typed transactions (
Transaction) over the SeaORM and SQLx paths, with explicit ownership and no hidden nesting/savepoint magic. - Development/CI N+1 detection behind the
n1Cargo feature: a request-scoped tracker (n1::Tracker) that records query events with source attribution and reports likely relation N+1 patterns. Zero production hot-path overhead when the feature is off — the tracker, the recording calls, and the analyzer arecfg-gated out of the default build. - Migration lint (
classify/classify_statements) — a deterministic, database-free classifier of real PostgreSQL migration risks (destructive drops, unsafeNOT NULL, type narrowing, dangerous renames, blocking indexes).
§What this crate does not own
It does not open a connection pool (it borrows Db), it does not
reimplement SeaORM’s query builder or relation engine, it does not add a
second transaction abstraction with hidden savepoints, and it does not
introduce any global, thread-local, or task-local state. Raw SeaORM and
SQLx remain first-class escape hatches via db.orm() / db.sqlx().
This crate is an internal workspace member (publish = false); its
public surface is re-exported through the arcature facade behind the
existing db feature. ADR-0006 authorizes no new public crate for
AP2.1-6 — arcature-data is not an independent crates.io release unit.
§Raw Axum usage
Db is Clone + Send + Sync + 'static (from arcature-db); this crate
adds no state of its own. Query<E> borrows &Db for the duration of the
query, so it composes with normal Axum state without a runtime dependency:
use arcature_data::QueryModel;
let posts = post::Entity::query(db)
.filter(post::Column::Active.eq(true))
.order_by_desc(post::Column::CreatedAt)
.all()
.await?;§Security note
Every query carries an explicit &Db; there is no hidden pool the
framework resolves on the caller’s behalf. Migration lint output is
side-effect-free and never reads environment variables or connects to a
database; the N+1 tracker is request-scoped and constructed explicitly.
Structs§
- Db
- The certified
arcature-dbengine, re-exported so downstream code targets the Arcature-pinned types through this crate.Dbis the explicit ownership handle every API in this crate borrows. The Arcature database handle: one PostgreSQL connection pool with two first-class data paths. - Finding
- One migration lint finding: a classified risk in a single statement.
- Lint
Report - The aggregated lint report for a set of SQL statements.
- Page
- A page of results from a paginated query.
- Paginated
- A paginated query awaiting a page number and a fetch.
- Query
- A typed query bound to an explicit
&Db, over a SeaORM entityE. - Relation
- A typed reference to a related entity
R, for eager loading. - SqlStatement
- A single SQL statement, normalized for classification.
- Transaction
- Typed transactions over the explicit
&Db— SeaORM and SQLx paths.
Enums§
- Data
Error - The error returned by the high-level data layer.
- Lint
Category - A category of real PostgreSQL migration risk (PROGRAM.md AP2.1-6).
- Lint
Severity - The severity of a migration lint finding.
- Pagination
Error - An invalid pagination argument (AGENTS.md §18: typed, not a string).
Traits§
- Query
Model - The golden-path entry point: every SeaORM
EntitygainsEntity::query(&db).
Functions§
- classify
- Classify a single script string (split into statements first).
- classify_
statements - Classify a set of
SqlStatements and return aLintReport. - delete
- Delete an existing row from its
ActiveModel. Returns asea_orm::DeleteResultcarrying the number of affected rows. - find_
by_ pk - Find a single row by its primary key.
- insert
- Insert a new row from an
ActiveModel. Returns the inserted model with database-generated fields (auto-increment PKs, defaults) populated. - of
- Reference the related entity
Rfor eager loading. Generic overRso the caller can name it explicitly: - update
- Update an existing row from an
ActiveModel. Returns the updated model.