Skip to main content

SearchableCrudServiceAdapter

Struct SearchableCrudServiceAdapter 

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

Adapter for repositories that implement SearchableRepository

This adapter provides full filter support in the list method by leveraging the SearchableRepository::search method.

§Example

ⓘ
use backbone_core::persistence::{InMemoryRepository, SearchableCrudServiceAdapter};

let repo = Arc::new(InMemoryRepository::<User>::new());
let service = SearchableCrudServiceAdapter::new(
    repo,
    "User",
    |dto: CreateUserDto| User::from(dto),
    |entity: &mut User, dto: UpdateUserDto| entity.apply_update(dto),
);

Implementations§

Source§

impl<R, E, C, U> SearchableCrudServiceAdapter<R, E, C, U>
where R: SearchableRepository<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 searchable 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 SearchableCrudServiceAdapter<R, E, C, U>
where R: SearchableRepository<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
Source§

fn violations_of(err: &Self::Error) -> Option<Vec<Violation>>

The named rules a refused write broke, when the error carries them, so the response can list them beside the sentence. None by default.
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
Source§

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

What bulk_partial_update would do, with nothing written: each row as it is and as it would become, or why the write would refuse it. Ok(None) (the default) means this service has no dry run, and the route says so instead of guessing. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<R, E, C, U> UnsafeUnpin for SearchableCrudServiceAdapter<R, E, C, U>
where Arc<R>: UnsafeUnpin, Box<dyn Fn(C) -> E + Sync + Send>: UnsafeUnpin, Box<dyn Fn(&mut E, U) + Sync + Send>: 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