Skip to main content

Crate rok_db_core

Crate rok_db_core 

Source
Expand description

Core runtime of rok-db.

Most users should depend on the rok-db crate, which re-exports everything here together with the #[derive(Model)] macro.

Re-exports§

pub use join::InScope;
pub use join::IntoJoin;
pub use join::JoinOn;
pub use join::Joined;
pub use notify::Change;
pub use notify::ChangeOp;
pub use notify::ChangeStream;
pub use notify::Listener;
pub use notify::Notification;
pub use relation::BelongsTo;
pub use relation::HasMany;
pub use relation::HasOne;
pub use validate::ValidationErrors;
pub use sqlx;

Modules§

audit
A trigger-based audit log (feature json): every insert, update and delete of an audited table — through rok-db, bulk queries or raw SQL — is recorded in rok_audit_log with the old and new row as JSONB.
join
Typed joins (RFC 0001).
metrics
Metrics through the metrics facade (feature metrics). Install any recorder (Prometheus, StatsD, OpenTelemetry, …) and rok-db reports:
migration
Versioned migrations embedded in Rust code.
notify
PostgreSQL LISTEN/NOTIFY, and typed change feeds for models.
relation
Relations between models, declared with #[derive(Model)] attributes. The parent model must have a single-column primary key.
tenant
Row-level multi-tenancy for models with a #[rok(tenant)] column.
testing
Test support: a fresh, isolated database per test (feature testing).
validate
Validation of model fields, run automatically before insert, save, upsert and insert_many.
web
Web integration: serde support (feature serde) and axum responses (feature axum).

Macros§

impl_value
Make a type usable as a rok-db column value (in models, filters and set), given that it already implements sqlx’s Type and Encode for PostgreSQL plus Clone + Debug. Implements CustomType and From<T> / From<&T> for Value (Option<T> then works too).

Structs§

CacheStats
Counters describing how a QueryCache is performing.
Column
A column of model M.
Cursor
An opaque position in a keyset-paginated result, returned by Select::cursor_paginate.
CursorPage
One page of a keyset-paginated query.
CustomValue
A value of a user-defined type; see Value::custom.
Db
A pooled PostgreSQL connection handle — the entry point of rok-db.
DbBuilder
Builder for a Db connection pool, created with Db::builder.
Expr
A boolean condition on model M, used in WHERE clauses.
Insert
An INSERT of a single row built column by column, created with Model::create. Columns you don’t set get their database default; timestamp columns default to now().
InsertMany
An INSERT of whole records, created with Model::insert_many. Generated columns are skipped and timestamps are set to now().
Memoized
A Select whose results are cached, created with Select::memoize.
Order
An ORDER BY term on model M, created with Column::asc or Column::desc.
Page
One page of results, returned by Select::paginate.
PoolStats
Connection pool statistics, from Db::stats.
Projected
A SELECT of specific columns or aggregates, created with Select::select. Decode rows into tuples or any sqlx::FromRow type.
Projection
A value expression of model M that can be selected: a column, an aggregate (User::AGE.avg()), a cast or raw SQL.
QueryCache
An in-memory cache for memoized query results.
Raw
A raw SQL query with bound parameters, created with raw.
Select
A SELECT query over model M, created with Model::query or Model::filter.
Sql
A rendered SQL statement together with its bound parameters.
Tracked
A record that remembers its loaded values, so save writes only the columns you changed — or nothing at all.
Tx
An open database transaction, created with Db::begin.
TxOptions
Settings for Db::transaction_with.
Update
A bulk UPDATE over model M, created with Model::update_all or Select::update.

Enums§

CopyTarget
Where Model::copy_in runs: a pool (one connection is borrowed), a transaction or a plain connection.
Direction
Sort direction for ORDER BY.
Error
Every error rok-db can produce.
Isolation
Transaction isolation level, see TxOptions::isolation.
Value
A dynamically typed, bindable SQL value.

Traits§

CustomType
Marker for user-defined column types stored through Value::custom.
Executor
Anything that can run a query: &Db, &mut Tx, a plain sqlx &PgPool or &mut PgConnection.
Hooks
Lifecycle hooks, called around the record-level writes of Model (insert, insert_all/insert_many, upsert, save, delete, force_delete). Bulk query operations (Select::update, Select::delete, …) don’t call hooks.
IntoKey
A primary key value: a single value, or a tuple for models with a composite primary key (#[rok(primary_key)] on several fields).
IntoProjections
A list of Projections: a single column or projection, a tuple of up to 12 of them, an array or a Vec.
Model
A database-backed record.
Retryable
Errors that can tell whether retrying the transaction might succeed. Implemented for Error; implement it for your own error type (usually by delegating to a wrapped rok_db::Error) to use it with Db::transaction_with.
StreamExt
Extension traits for consuming streams (try_next, try_collect, …). An extension trait for Streams that provides a variety of convenient combinator functions.
TryStreamExt
Extension traits for consuming streams (try_next, try_collect, …). Adapters specific to Result-returning streams

Functions§

raw
Start a raw SQL query — the escape hatch for anything the query builder doesn’t express.

Type Aliases§

BoxFuture
A boxed Send future, as returned by Db::transaction closures. An owned dynamically typed Future for use in cases where you can’t statically type your result or need to add some indirection.
BoxStream
A boxed Send stream, as returned by Select::stream. An owned dynamically typed Stream for use in cases where you can’t statically type your result or need to add some indirection.
Result
Convenient alias for results returned by rok-db.