#[non_exhaustive]pub enum Field {
JsonbField(String),
DirectColumn(String),
JsonbPath(Vec<String>),
}Expand description
Represents a field reference in a WHERE clause or ORDER BY
Supports both JSONB payload fields and direct database columns, with automatic type casting and proper SQL generation.
§Examples
use fraiseql_wire::operators::Field;
// JSONB field: (data->>'name')
let _ = Field::JsonbField("name".to_string());
// Direct column: created_at
let _ = Field::DirectColumn("created_at".to_string());
// Nested JSONB: (data->'user'->>'name')
let _ = Field::JsonbPath(vec!["user".to_string(), "name".to_string()]);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
JsonbField(String)
A field extracted from the JSONB data column with text extraction (->>)
The value is extracted as text and wrapped in parentheses.
Generated SQL: (data->>'field_name')
DirectColumn(String)
A direct database column (not from JSONB)
Uses the native type stored in the database.
Generated SQL: column_name
JsonbPath(Vec<String>)
A nested path within the JSONB data column
The path is traversed left-to-right, with intermediate steps using -> (JSON navigation)
and the final step using ->> (text extraction).
All extracted values are text and wrapped in parentheses.
Generated SQL: (data->'path[0]'->...->>'path[n]')
Implementations§
Source§impl Field
impl Field
Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Validate field name to prevent SQL injection
Allows: alphanumeric, underscore Disallows: quotes, brackets, dashes, special characters
§Errors
Returns an error string if any field name (or path segment) contains characters other than alphanumeric and underscore.