toasty_core/stmt/func_json_extract.rs
1use super::{Expr, ExprFunc, Type};
2
3/// Extracts the value at a key path from a document-stored value.
4///
5/// Produced when a query filters on a field inside a `#[document]` embed:
6/// `User::FIELDS.preferences().theme()` lowers to a `JsonExtract` over the
7/// `preferences` document column with `path = ["theme"]`. The SQL serializer
8/// renders it per dialect — `col->'a'->>'b'` on PostgreSQL, `json_extract(col,
9/// '$.a.b')` on SQLite / MySQL.
10#[derive(Clone, Debug, PartialEq)]
11pub struct FuncJsonExtract {
12 /// The document value to extract from — typically a column reference.
13 pub base: Box<Expr>,
14
15 /// The key path from the document root to the extracted field, in order.
16 pub path: Vec<String>,
17
18 /// The type of the extracted value (the leaf field's type).
19 pub ty: Type,
20}
21
22impl From<FuncJsonExtract> for ExprFunc {
23 fn from(value: FuncJsonExtract) -> Self {
24 Self::JsonExtract(value)
25 }
26}
27
28impl From<FuncJsonExtract> for Expr {
29 fn from(value: FuncJsonExtract) -> Self {
30 Self::Func(value.into())
31 }
32}