pub struct ResourceQuery<'a> {
pub resource: &'a ResourceDefinition,
pub pool: &'a PgPool,
}Expand description
Dynamic query executor for a resource defined by a ResourceDefinition.
Generates and executes parameterized SQL queries against a PgPool,
returning results as ResourceRow (JSON objects).
§SQL injection safety
All user-controllable input (filter values, search term, cursor, pagination
offset/limit, insert/update body) is passed only as bound parameters via
BindValue and query.bind(). Table and column names in the SQL string
come solely from ResourceDefinition (trusted schema). Filter/sort field
names are allow-listed (FilterSet::from_query_params, SortParam::parse).
See db_integration tests test_sql_injection_* for verification.
Fields§
§resource: &'a ResourceDefinition§pool: &'a PgPoolImplementations§
Source§impl<'a> ResourceQuery<'a>
impl<'a> ResourceQuery<'a>
pub fn new(resource: &'a ResourceDefinition, pool: &'a PgPool) -> Self
Sourcepub async fn find_by_id(&self, id: &Uuid) -> Result<ResourceRow, ShaperailError>
pub async fn find_by_id(&self, id: &Uuid) -> Result<ResourceRow, ShaperailError>
Find a single record by its primary key.
Sourcepub async fn find_all(
&self,
filters: &FilterSet,
search: Option<&SearchParam>,
sort: &SortParam,
page: &PageRequest,
) -> Result<(Vec<ResourceRow>, Value), ShaperailError>
pub async fn find_all( &self, filters: &FilterSet, search: Option<&SearchParam>, sort: &SortParam, page: &PageRequest, ) -> Result<(Vec<ResourceRow>, Value), ShaperailError>
Find all records with filtering, searching, sorting, and pagination.
Returns (rows, cursor_page) for cursor pagination or (rows, offset_page) for offset.
Sourcepub async fn insert(
&self,
data: &Map<String, Value>,
) -> Result<ResourceRow, ShaperailError>
pub async fn insert( &self, data: &Map<String, Value>, ) -> Result<ResourceRow, ShaperailError>
Insert a new record. Returns the inserted row.
Sourcepub async fn update_by_id(
&self,
id: &Uuid,
data: &Map<String, Value>,
) -> Result<ResourceRow, ShaperailError>
pub async fn update_by_id( &self, id: &Uuid, data: &Map<String, Value>, ) -> Result<ResourceRow, ShaperailError>
Update a record by primary key. Returns the updated row.
Sourcepub async fn soft_delete_by_id(
&self,
id: &Uuid,
) -> Result<ResourceRow, ShaperailError>
pub async fn soft_delete_by_id( &self, id: &Uuid, ) -> Result<ResourceRow, ShaperailError>
Soft-delete a record by setting deleted_at to now.
Sourcepub async fn hard_delete_by_id(
&self,
id: &Uuid,
) -> Result<ResourceRow, ShaperailError>
pub async fn hard_delete_by_id( &self, id: &Uuid, ) -> Result<ResourceRow, ShaperailError>
Hard-delete a record permanently.
Auto Trait Implementations§
impl<'a> Freeze for ResourceQuery<'a>
impl<'a> !RefUnwindSafe for ResourceQuery<'a>
impl<'a> Send for ResourceQuery<'a>
impl<'a> Sync for ResourceQuery<'a>
impl<'a> Unpin for ResourceQuery<'a>
impl<'a> UnsafeUnpin for ResourceQuery<'a>
impl<'a> !UnwindSafe for ResourceQuery<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request