Expand description
Facade crate re-exporting core traits and macros for the storeit-rs library.
This crate provides the main public API. It re-exports all necessary traits and procedural macros so that you only need to add this single crate as a dependency in your application.
§Example: Deriving Entity
The #[derive(Entity)] macro generates compile-time metadata about your entity,
including a default RowAdapter implementation.
ⓘ
// This is a non-runnable snippet to avoid pulling backend-specific adapter impls
// into doctest scope. See the runnable examples under `storeit/examples/`.
use storeit::{Entity, Fetchable}; // `Fetchable` must be in scope to access associated constants.
// The macro automatically deduces the table name (`users`) by pluralizing
// the snake_case version of the struct name.
#[derive(Entity, Clone, Debug)]
pub struct User {
// Mark the ID field. The key type (`i64`) and column name ("id") are deduced.
#[fetch(id)]
pub id: Option<i64>,
// You can override column names.
#[fetch(column = "email_address")]
pub email: String,
}
// The `Entity` derive generates metadata constants via the `Fetchable` trait:
assert_eq!(User::TABLE, "users");
assert_eq!(User::SELECT_COLUMNS, &["id", "email_address"]);
// It also generates a `RowAdapter` struct named `UserRowAdapter`.
// This line is a compile-time check that the struct was created.
let _adapter = UserRowAdapter;§Example: Generating a Repository
A runnable example showcasing the #[repository] macro can be found in the
/examples directory of the workspace. It is more comprehensive than a doctest
can be, as it involves multiple crates and backend-specific features.
Modules§
- backends
- transactions
- Backend-agnostic transaction abstractions modeled after Spring’s TransactionTemplate. This module defines only generic types and traits. Backends provide implementations.
Enums§
- Param
Value - A backend-agnostic representation of a database parameter value.
This is used to pass entity field values from generated code to backend adapters
without making
storeit_coredependent on a specific database driver. - Repo
Error - Lightweight, backend-agnostic error type for repository operations.
Traits§
- Fetchable
- Marker trait for types that can be fetched from a database.
Implemented via
#[derive(Fetchable)]proc-macro instoreit_macros. - Identifiable
- Trait for entities that have an identifiable key. This trait exposes the key type and column name so macros can introspect it.
- Insertable
- Trait for types whose fields can be extracted for an INSERT statement.
This is implemented by the
#[derive(Fetchable)]macro. - Repository
- A trait describing a minimal, asynchronous repository interface for an entity
Tidentified by keyK. This is intentionally DB-agnostic. Concrete backends provide implementations. - RowAdapter
- A tiny adapter for mapping a backend-specific row type into an entity
T. Backends (e.g., rusqlite, mysql_async, tokio_postgres) can implement this for their row representations. - Updatable
- Trait for types whose fields can be extracted for an UPDATE statement.
This is implemented by the
#[derive(Fetchable)]macro.
Type Aliases§
- Repo
Result - Convenience alias for results returned by repository methods.