Skip to main content

Module repository

Module repository 

Source
Expand description

Generic repository for SeaORM entities.

PersistentRepository centralizes CRUD, counts, cursor-paginated reads, updates, and deletes for one entity type whose model implements BaseEntity. Queries are built with QueryData and parameterized with RepositoryOptions.

Cursor filtering compares id against the decoded cursor: ascending order uses id > cursor, descending uses id < cursor, and deletes always use id > cursor. On creation, uid/createdAt/updatedAt (plus createdById/ updatedById when a user id is present) is filled in; on update, updatedAt (plus updatedById when a user id is present) is refreshed. Database columns for these fields use camelCase names.

When a RepositoryOptions carries Some(txn) (see RepositoryOptions::with_transaction), the operation runs against that transaction; otherwise it uses the repository’s own connection. The QueryData transaction (set via QueryData::with_options) is honored as a fallback when the method-level options carry none.

Repositories can be shared through a process-wide registry keyed by entity type (see PersistentRepository::initialize and PersistentRepository::find), or used directly via PersistentRepository::new without registration.

use shared_framework::data::{PersistentRepository, QueryData, RepositoryOptions};

let repo = PersistentRepository::<my_entity::Entity>::new(db);
let page = repo.get_paginated_view(None, RepositoryOptions::from_ctx(ctx).join(RepositoryOptions::new().with_limit(50))).await?;
let all = repo.get_all::<shared_framework::data::NoUser>(Some(QueryData::new(my_entity::Entity::find())), None).await?;

Structs§

PersistentRepository
Generic database access for one SeaORM entity.

Functions§

new_uid
Generates a new UUID v4 for uid columns on new rows.