pub struct OrderByClause {
pub field: String,
pub direction: OrderDirection,
pub field_type: OrderByFieldType,
pub native_column: Option<String>,
}Expand description
ORDER BY clause with optional type and native column information.
The SQL generator uses field_type to emit the correct type cast for
JSONB-extracted values, and native_column to bypass JSONB extraction
entirely when the view exposes a dedicated typed column.
§Sort correctness by source
| Source | Text fields | Numeric fields | Date fields |
|---|---|---|---|
| JSONB (no cast) | Correct | Wrong (lexicographic) | Correct (ISO-8601) |
| JSONB (with cast) | Correct | Correct | Correct |
| Native column | Correct | Correct | Correct + indexable |
Fields§
§field: StringField to order by (GraphQL camelCase name).
direction: OrderDirectionSort direction.
field_type: OrderByFieldTypeField type for SQL cast generation. Text (default) means no cast.
native_column: Option<String>Native column name if the view exposes this field as a typed column. When set, ORDER BY uses this column directly instead of JSONB extraction, enabling index support and correct typing without casts.
Implementations§
Source§impl OrderByClause
impl OrderByClause
Sourcepub fn new(field: String, direction: OrderDirection) -> OrderByClause
pub fn new(field: String, direction: OrderDirection) -> OrderByClause
Create a new OrderByClause with default field type (text) and no native column.
Sourcepub fn storage_key(&self) -> String
pub fn storage_key(&self) -> String
Convert the GraphQL camelCase field name to the JSONB snake_case storage key.
§Examples
use fraiseql_db::OrderByClause;
use fraiseql_db::OrderDirection;
let clause = OrderByClause::new("createdAt".to_string(), OrderDirection::Asc);
assert_eq!(clause.storage_key(), "created_at");Sourcepub fn validate_field_name(field: &str) -> Result<(), FraiseQLError>
pub fn validate_field_name(field: &str) -> Result<(), FraiseQLError>
Validate that a field name matches the GraphQL identifier pattern [_A-Za-z][_0-9A-Za-z]*.
This is a security boundary: field names are interpolated into SQL data->>'field'
expressions. Any character outside the GraphQL identifier set must be rejected before
the OrderByClause is constructed.
§Errors
Returns FraiseQLError::Validation if the field contains invalid characters.
Sourcepub fn from_graphql_json(
value: &Value,
) -> Result<Vec<OrderByClause>, FraiseQLError>
pub fn from_graphql_json( value: &Value, ) -> Result<Vec<OrderByClause>, FraiseQLError>
Parse orderBy from a GraphQL variables JSON value.
Accepts two formats:
- Object:
{ "name": "DESC", "created_at": "ASC" } - Array:
[{ "field": "name", "direction": "DESC" }]
Direction strings are case-insensitive.
§Errors
Returns FraiseQLError::Validation for invalid structure or direction values.
Trait Implementations§
Source§impl Clone for OrderByClause
impl Clone for OrderByClause
Source§fn clone(&self) -> OrderByClause
fn clone(&self) -> OrderByClause
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OrderByClause
impl Debug for OrderByClause
Source§impl<'de> Deserialize<'de> for OrderByClause
impl<'de> Deserialize<'de> for OrderByClause
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<OrderByClause, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<OrderByClause, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for OrderByClause
impl PartialEq for OrderByClause
Source§impl Serialize for OrderByClause
impl Serialize for OrderByClause
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for OrderByClause
impl StructuralPartialEq for OrderByClause
Auto Trait Implementations§
impl Freeze for OrderByClause
impl RefUnwindSafe for OrderByClause
impl Send for OrderByClause
impl Sync for OrderByClause
impl Unpin for OrderByClause
impl UnsafeUnpin for OrderByClause
impl UnwindSafe for OrderByClause
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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 more