Skip to main content

CrudServiceAdapter

Struct CrudServiceAdapter 

Source
pub struct CrudServiceAdapter<R, E, C, U>
where R: CrudRepository<E> + Send + Sync, E: PersistentEntity, C: Send + Sync, U: Send + Sync,
{ /* private fields */ }
Expand description

Adapter that wraps a CrudRepository to implement CrudService

This enables using any repository implementation with the BackboneCrudHandler to automatically generate all 12 HTTP endpoints.

§Type Parameters

  • R: Repository implementing CrudRepository<E>
  • E: Entity type (must implement PersistentEntity)
  • C: Create DTO type
  • U: Update DTO type

Implementations§

Source§

impl<R, E, C, U> CrudServiceAdapter<R, E, C, U>
where R: CrudRepository<E> + Send + Sync, E: PersistentEntity, C: Send + Sync, U: Send + Sync,

Source

pub fn new<F1, F2>( repository: Arc<R>, entity_name: &'static str, create_mapper: F1, update_mapper: F2, ) -> Self
where F1: Fn(C) -> E + Send + Sync + 'static, F2: Fn(&mut E, U) + Send + Sync + 'static,

Create a new adapter with custom mappers

Source

pub fn repository(&self) -> &R

Get a reference to the underlying repository

Trait Implementations§

Source§

impl<R, E, C, U> CrudService<E, C, U> for CrudServiceAdapter<R, E, C, U>
where R: CrudRepository<E> + Send + Sync + 'static, E: PersistentEntity + Clone + 'static, C: Send + Sync + 'static, U: Send + Sync + 'static,

Source§

type Error = AdapterError

Error type for service operations
Source§

fn entity_name() -> &'static str

Entity name for error messages (e.g., “User”, “Role”)
Source§

fn list<'life0, 'async_trait>( &'life0 self, page: u32, limit: u32, _filters: HashMap<String, String>, ) -> Pin<Box<dyn Future<Output = Result<(Vec<E>, u64), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List entities with pagination and filters Read more
Source§

fn aggregate<'life0, 'life1, 'async_trait>( &'life0 self, spec: &'life1 AggregateSpec, filters: HashMap<String, String>, ) -> Pin<Box<dyn Future<Output = Result<AggregateResult, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Group and reduce the rows list would return, under the same filters. Read more
Source§

fn table_name(&self) -> Option<&str>

The schema-qualified table this service reads, when it has one. Read more
Source§

fn create<'life0, 'async_trait>( &'life0 self, dto: C, ) -> Pin<Box<dyn Future<Output = Result<E, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Create a new entity Read more
Source§

fn get_by_id<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<E>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get entity by ID Read more
Source§

fn update<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, dto: U, ) -> Pin<Box<dyn Future<Output = Result<Option<E>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Full update of entity Read more
Source§

fn partial_update<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, _fields: HashMap<String, Value>, ) -> Pin<Box<dyn Future<Output = Result<Option<E>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Partial update with specific fields Read more
Source§

fn soft_delete<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<bool, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Soft delete entity Read more
Source§

fn bulk_create<'life0, 'async_trait>( &'life0 self, items: Vec<C>, ) -> Pin<Box<dyn Future<Output = Result<Vec<E>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Bulk create multiple entities Read more
Source§

fn upsert<'life0, 'async_trait>( &'life0 self, dto: C, ) -> Pin<Box<dyn Future<Output = Result<E, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Upsert (create or update) Read more
Source§

fn list_deleted<'life0, 'async_trait>( &'life0 self, page: u32, limit: u32, ) -> Pin<Box<dyn Future<Output = Result<(Vec<E>, u64), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List deleted entities (trash) Read more
Source§

fn restore<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<E>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Restore soft-deleted entity Read more
Source§

fn empty_trash<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<u64, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Permanently delete all soft-deleted entities Read more
Source§

fn get_deleted_by_id<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<E>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get deleted entity by ID (from trash) Read more
Source§

fn permanent_delete<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<bool, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Permanently delete a single soft-deleted entity by ID Read more
Source§

fn list_deleted_filtered<'life0, 'async_trait>( &'life0 self, page: u32, limit: u32, filters: HashMap<String, String>, ) -> Pin<Box<dyn Future<Output = Result<(Vec<E>, u64), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List deleted entities with filters Read more
Source§

fn count_active<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<u64, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Count active (non-deleted) entities Read more
Source§

fn count_deleted<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<u64, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Count deleted entities in trash Read more
Hydrate ?include= relations: fetch rows from table by id list, as JSON. Default: no expansion. GenericCrudService delegates to its repository.
Source§

fn list_with_info<'life0, 'async_trait>( &'life0 self, page: u32, limit: u32, filters: HashMap<String, String>, ) -> Pin<Box<dyn Future<Output = Result<(Vec<Entity>, PaginationInfo), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

list, carrying the pagination info (cursor positions included) so the HTTP layer can surface keyset paging. Default: the tuple form — generated services override this with the repository’s cursors.
Source§

fn count_active_filtered<'life0, 'async_trait>( &'life0 self, filters: HashMap<String, String>, ) -> Pin<Box<dyn Future<Output = Result<u64, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Count active entities MATCHING the caller’s filters. Read more
Source§

fn bulk_soft_delete<'life0, 'async_trait>( &'life0 self, ids: Vec<String>, ) -> Pin<Box<dyn Future<Output = Result<u64, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Soft-delete many entities by id. Returns the number affected. Read more
Source§

fn bulk_restore<'life0, 'async_trait>( &'life0 self, ids: Vec<String>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Entity>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Restore many soft-deleted entities by id. Returns the restored rows. Read more
Source§

fn bulk_permanent_delete<'life0, 'async_trait>( &'life0 self, ids: Vec<String>, ) -> Pin<Box<dyn Future<Output = Result<u64, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Permanently delete many soft-deleted entities by id. Read more
Source§

fn restore_all<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<u64, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Restore every soft-deleted entity. Returns the number restored. Read more
Source§

fn bulk_update<'life0, 'async_trait>( &'life0 self, items: Vec<(String, UpdateDto)>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Entity>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Full-update many entities. Each item is (id, UpdateDto). Read more
Source§

fn bulk_partial_update<'life0, 'async_trait>( &'life0 self, items: Vec<(String, HashMap<String, Value>)>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Entity>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Partial-update many entities. Each item is (id, field_map). Read more

Auto Trait Implementations§

§

impl<R, E, C, U> !RefUnwindSafe for CrudServiceAdapter<R, E, C, U>

§

impl<R, E, C, U> !UnwindSafe for CrudServiceAdapter<R, E, C, U>

§

impl<R, E, C, U> Freeze for CrudServiceAdapter<R, E, C, U>
where Arc<R>: Freeze, Box<dyn Fn(C) -> E + Send + Sync>: Freeze, Box<dyn Fn(&mut E, U) + Send + Sync>: Freeze,

§

impl<R, E, C, U> Send for CrudServiceAdapter<R, E, C, U>
where Arc<R>: Send, Box<dyn Fn(C) -> E + Send + Sync>: Send, Box<dyn Fn(&mut E, U) + Send + Sync>: Send,

§

impl<R, E, C, U> Sync for CrudServiceAdapter<R, E, C, U>
where Arc<R>: Sync, Box<dyn Fn(C) -> E + Send + Sync>: Sync, Box<dyn Fn(&mut E, U) + Send + Sync>: Sync,

§

impl<R, E, C, U> Unpin for CrudServiceAdapter<R, E, C, U>
where Arc<R>: Unpin, Box<dyn Fn(C) -> E + Send + Sync>: Unpin, Box<dyn Fn(&mut E, U) + Send + Sync>: Unpin,

§

impl<R, E, C, U> UnsafeUnpin for CrudServiceAdapter<R, E, C, U>
where Arc<R>: UnsafeUnpin, Box<dyn Fn(C) -> E + Send + Sync>: UnsafeUnpin, Box<dyn Fn(&mut E, U) + Send + Sync>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more