iet-db-macros
Derives entity metadata used by the TimescaleDB repository machinery.
iet-db-macrostoolingEntity derive macrosHow to use it
#[derive(Persistent)] reads a struct's #[persistent(...)] attributes to emit the iet_core::persistence::Persistent metadata used to generate DDL and queries (table, columns, keys, defaults, checks, indexes, foreign keys). #[derive(TimescaleEntity)] adds row decoding plus a generated field enum for typed filters and write mappings. Both are attribute-driven and expect real column types (String, Uuid, i64, bool, DateTime, or an explicit kind).
// crates/integrations/iet-auth-session-timescale/src/entity.rs
use Persistent;
Combine both derives when you want typed filters; from examples/htmx-starter/crates/project-impl-timescale/src/entity.rs:
// examples/htmx-starter/crates/project-impl-timescale/src/entity.rs
pub
time_column+chunk_secondsdeclare a TimescaleDB hypertable;softdeletes adddeleted_atunlesshard_deleteis set.#[field(operators = "...")]whitelistsEqual,Less,Contains,In,IsNull, and friends; without it non-writable fields are skipped.
How it works
Persistent walks the #[persistent(...)] attributes and emits the iet_core::persistence::Persistent metadata constants; TimescaleEntity reads #[entity(fields = ...)] and #[field(...)] to emit row decoding and a generated field enum implementing the query traits.
flowchart LR P["struct with persistent attributes"] --> DP["derive Persistent"] DP --> IP["impl iet_core persistence Persistent"] IP --> C["TABLE / COLUMNS / PRIMARY_KEY / INDEXES / FOREIGN_KEYS"] E["struct with entity and field attributes"] --> DE["derive TimescaleEntity"] DE --> IE["impl Entity and EntityRow"] DE --> FE["generated field enum"] FE --> FI["Column / WriteField / EntityFields / FilterField"]
What it implements
- Concrete mechanism; see the public API below.
What's inside
Modules
src/entity.rssrc/lib.rssrc/persistent.rs
Public API
(root)
pub fn entity(input: proc_macro::TokenStream) -> proc_macro::TokenStreampub fn persistent(input: proc_macro::TokenStream) -> proc_macro::TokenStream
entity
pub fn expand(input: TokenStream) -> TokenStream
persistent
pub fn expand(input: TokenStream) -> TokenStream
Depends on
- No other framework crate: it stands alone.
External crates: proc-macro2, quote, syn
Used by
iet-auth-acl-timescaleiet-auth-basic-timescaleiet-auth-identity-timescaleiet-auth-profiles-timescaleiet-auth-rbac-timescaleiet-auth-revocations-timescaleiet-auth-session-timescale
In this repository
examples/htmx-starterexamples/skills-only-appexamples/skills-only-app-task-tracker
Source: crates/macros/iet-db-macros