pub struct JsonPathRef<'a> {
pub column: Cow<'a, str>,
pub segments: SmallVec<[PathSegmentRef<'a>; 8]>,
pub as_text: bool,
}Expand description
A zero-copy JSON path expression that borrows strings where possible.
This is a more efficient alternative to JsonPath when you’re working
with string literals or borrowed data and don’t need to store the path.
§Example
use prax_query::zero_copy::{JsonPathRef, PathSegmentRef};
use prax_query::sql::DatabaseType;
// All string data is borrowed - no allocations
let path = JsonPathRef::new("data")
.field("user")
.field("profile")
.index(0);
// Generate SQL without owning the strings
let sql = path.to_sql(DatabaseType::PostgreSQL);
assert!(sql.contains("data"));Fields§
§column: Cow<'a, str>The column name containing JSON (borrowed).
segments: SmallVec<[PathSegmentRef<'a>; 8]>Path segments (may contain borrowed or owned strings).
as_text: boolWhether to return text (::text in PostgreSQL).
Implementations§
Source§impl<'a> JsonPathRef<'a>
impl<'a> JsonPathRef<'a>
Sourcepub fn from_path(column: &'a str, path: &str) -> Self
pub fn from_path(column: &'a str, path: &str) -> Self
Create from a JSONPath string (e.g., “$.user.name”).
Note: This may allocate for parsed field names.
Sourcepub fn field_owned(self, name: String) -> Self
pub fn field_owned(self, name: String) -> Self
Add a field access segment (owned).
Sourcepub fn is_zero_copy(&self) -> bool
pub fn is_zero_copy(&self) -> bool
Check if this path uses only borrowed data (no allocations).
Sourcepub fn to_sql(&self, db_type: DatabaseType) -> String
pub fn to_sql(&self, db_type: DatabaseType) -> String
Generate SQL for this path.
Trait Implementations§
Source§impl<'a> Clone for JsonPathRef<'a>
impl<'a> Clone for JsonPathRef<'a>
Source§fn clone(&self) -> JsonPathRef<'a>
fn clone(&self) -> JsonPathRef<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'a> Debug for JsonPathRef<'a>
impl<'a> Debug for JsonPathRef<'a>
Auto Trait Implementations§
impl<'a> Freeze for JsonPathRef<'a>
impl<'a> RefUnwindSafe for JsonPathRef<'a>
impl<'a> Send for JsonPathRef<'a>
impl<'a> Sync for JsonPathRef<'a>
impl<'a> Unpin for JsonPathRef<'a>
impl<'a> UnwindSafe for JsonPathRef<'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
Mutably borrows from an owned value. Read more