pub struct PaginatedQuery<T> { /* private fields */ }Expand description
Builder pour les requêtes paginées avec tri, recherche et filtres WHERE.
§Exemples
ⓘ
// Simple
PaginatedQuery::<MediaFile>::new("SELECT * FROM media_file")
.allowed_sorts(&["id", "filename", "created", "size"])
.default_sort("id")
.execute(pool, params)
.await
// Avec WHERE
PaginatedQuery::<CommentListItem>::new(
"SELECT c.id, c.comment, u.username FROM comment c LEFT JOIN users u ON c.user_id = u.id"
)
.where_eq("c.content_id", content_id.into())
.default_sort("c.created")
.default_order("ASC")
.execute(pool, params)
.await
// Avec recherche
PaginatedQuery::<UserListItem>::new("SELECT u.id, u.username FROM users u")
.allowed_sorts(&["id", "username", "email", "created"])
.sort_prefix("u")
.search_columns(&["u.username", "u.email"])
.execute(pool, params)
.awaitImplementations§
Source§impl<T> PaginatedQuery<T>
impl<T> PaginatedQuery<T>
Sourcepub fn new(base_sql: &str) -> Self
pub fn new(base_sql: &str) -> Self
Crée un nouveau builder à partir d’une requête SELECT de base (sans ORDER BY/LIMIT).
Sourcepub fn allowed_sorts(self, sorts: &[&str]) -> Self
pub fn allowed_sorts(self, sorts: &[&str]) -> Self
Colonnes de tri autorisées (whitelist pour éviter l’injection SQL).
Sourcepub fn default_sort(self, sort: &str) -> Self
pub fn default_sort(self, sort: &str) -> Self
Colonne de tri par défaut.
Sourcepub fn default_order(self, order: &str) -> Self
pub fn default_order(self, order: &str) -> Self
Direction de tri par défaut (“ASC” ou “DESC”).
Sourcepub fn sort_prefix(self, prefix: &str) -> Self
pub fn sort_prefix(self, prefix: &str) -> Self
Préfixe de table pour le ORDER BY (ex: “u” → ORDER BY u.id).
Sourcepub fn search_columns(self, columns: &[&str]) -> Self
pub fn search_columns(self, columns: &[&str]) -> Self
Colonnes à rechercher avec LIKE (activé si params.search est renseigné).
Sourcepub fn where_eq(self, column: &str, value: WhereValue) -> Self
pub fn where_eq(self, column: &str, value: WhereValue) -> Self
Ajoute une condition WHERE (col = ?).
Sourcepub fn where_gte(self, column: &str, value: WhereValue) -> Self
pub fn where_gte(self, column: &str, value: WhereValue) -> Self
Ajoute une condition WHERE (col >= ?).
Sourcepub fn where_lte(self, column: &str, value: WhereValue) -> Self
pub fn where_lte(self, column: &str, value: WhereValue) -> Self
Ajoute une condition WHERE (col <= ?).
Sourcepub fn count_from(self, sql: &str) -> Self
pub fn count_from(self, sql: &str) -> Self
Surcharge la requête COUNT (utile si le FROM est complexe). Par défaut, le COUNT est déduit automatiquement de la requête de base.
Auto Trait Implementations§
impl<T> Freeze for PaginatedQuery<T>
impl<T> RefUnwindSafe for PaginatedQuery<T>where
T: RefUnwindSafe,
impl<T> Send for PaginatedQuery<T>where
T: Send,
impl<T> Sync for PaginatedQuery<T>where
T: Sync,
impl<T> Unpin for PaginatedQuery<T>where
T: Unpin,
impl<T> UnsafeUnpin for PaginatedQuery<T>
impl<T> UnwindSafe for PaginatedQuery<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more
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>
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 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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn propagate_header(self, header: HeaderName) -> PropagateHeader<Self>where
Self: Sized,
fn propagate_header(self, header: HeaderName) -> PropagateHeader<Self>where
Self: Sized,
Propagate a header from the request to the response. Read more
Source§fn compression(self) -> Compression<Self>where
Self: Sized,
fn compression(self) -> Compression<Self>where
Self: Sized,
Compresses response bodies. Read more
Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
High level tracing that classifies responses using HTTP status codes. Read more
Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
High level tracing that classifies responses using gRPC headers. Read more
Source§fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
Source§fn override_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn override_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
Insert a header into the request. Read more
Source§fn append_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn append_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
Append a header into the request. Read more
Source§fn insert_request_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn insert_request_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
Insert a header into the request, if the header is not already present. Read more
Source§fn override_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn override_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
Insert a header into the response. Read more
Source§fn append_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn append_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
Append a header into the response. Read more
Source§fn insert_response_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn insert_response_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
Insert a header into the response, if the header is not already present. Read more
Source§fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M,
) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M,
) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
Add request id header and extension. Read more
Source§fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
Add request id header and extension, using
x-request-id as the header name. Read moreSource§fn propagate_request_id(
self,
header_name: HeaderName,
) -> PropagateRequestId<Self>where
Self: Sized,
fn propagate_request_id(
self,
header_name: HeaderName,
) -> PropagateRequestId<Self>where
Self: Sized,
Propgate request ids from requests to responses. Read more
Source§fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
Self: Sized,
fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
Self: Sized,
Propgate request ids from requests to responses, using
x-request-id as the header name. Read moreSource§fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>where
Self: Sized,
fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>where
Self: Sized,
Intercept requests with over-sized payloads and convert them into
413 Payload Too Large responses. Read more