pub trait JsonExprExt<'a>: Expr<'a, PostgresValue<'a>> + Sized {
// Provided methods
fn json_get(
self,
key: &'a str,
) -> SQLExpr<'a, PostgresValue<'a>, <Self::SQLType as JsonType>::Field, Null, Self::Aggregate, Self::Sources>
where Self::SQLType: JsonType { ... }
fn json_get_idx(
self,
index: i32,
) -> SQLExpr<'a, PostgresValue<'a>, <Self::SQLType as JsonType>::Field, Null, Self::Aggregate, Self::Sources>
where Self::SQLType: JsonType { ... }
fn json_get_text(
self,
key: &'a str,
) -> SQLExpr<'a, PostgresValue<'a>, Text, Null, Self::Aggregate, Self::Sources>
where Self::SQLType: JsonType { ... }
fn json_get_text_idx(
self,
index: i32,
) -> SQLExpr<'a, PostgresValue<'a>, Text, Null, Self::Aggregate, Self::Sources>
where Self::SQLType: JsonType { ... }
fn json_get_path(
self,
path: &'a str,
) -> SQLExpr<'a, PostgresValue<'a>, <Self::SQLType as JsonType>::Field, Null, Self::Aggregate, Self::Sources>
where Self::SQLType: JsonType { ... }
fn json_get_path_text(
self,
path: &'a str,
) -> SQLExpr<'a, PostgresValue<'a>, Text, Null, Self::Aggregate, Self::Sources>
where Self::SQLType: JsonType { ... }
fn jsonb_contains<R>(
self,
other: R,
) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, <Self::Aggregate as AggregateKind>::Or<R::Aggregate>, (Arg<Self::Nullable, Self::Sources>, Arg<R::Nullable, R::Sources>)>
where Self::SQLType: JsonbType,
R: Expr<'a, PostgresValue<'a>>,
R::SQLType: JsonbOperand { ... }
fn jsonb_contained<R>(
self,
other: R,
) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, <Self::Aggregate as AggregateKind>::Or<R::Aggregate>, (Arg<Self::Nullable, Self::Sources>, Arg<R::Nullable, R::Sources>)>
where Self::SQLType: JsonbType,
R: Expr<'a, PostgresValue<'a>>,
R::SQLType: JsonbOperand { ... }
fn jsonb_exists_key(
self,
key: &'a str,
) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, Self::Aggregate, Arg<Self::Nullable, Self::Sources>>
where Self::SQLType: JsonbType { ... }
}Expand description
Method forms of the JSON operators, available on every PostgreSQL expression.
Each method calls the free function of the same name and has the same
operand rules (JsonType, JsonbType, JsonbOperand).
?| and ?& have no method form; use jsonb_exists_any and
jsonb_exists_all.
§Examples
use drizzle_core::{ToSQL, expr::raw_non_null};
use drizzle_postgres::expr::JsonExprExt;
use drizzle_postgres::values::PostgresValue;
use drizzle_types::postgres::types::Jsonb;
let settings = raw_non_null::<PostgresValue, Jsonb>("settings");
let theme = settings.json_get_path_text("{ui,theme}");
assert_eq!(theme.to_sql().sql(), "settings #>> CAST ($1 AS TEXT[])");Provided Methods§
Sourcefn json_get(
self,
key: &'a str,
) -> SQLExpr<'a, PostgresValue<'a>, <Self::SQLType as JsonType>::Field, Null, Self::Aggregate, Self::Sources>
fn json_get( self, key: &'a str, ) -> SQLExpr<'a, PostgresValue<'a>, <Self::SQLType as JsonType>::Field, Null, Self::Aggregate, Self::Sources>
Gets an object field by key (->), keeping the JSON type. See json_get.
Sourcefn json_get_idx(
self,
index: i32,
) -> SQLExpr<'a, PostgresValue<'a>, <Self::SQLType as JsonType>::Field, Null, Self::Aggregate, Self::Sources>
fn json_get_idx( self, index: i32, ) -> SQLExpr<'a, PostgresValue<'a>, <Self::SQLType as JsonType>::Field, Null, Self::Aggregate, Self::Sources>
Gets an array element by index (->), keeping the JSON type. See json_get_idx.
Sourcefn json_get_text(
self,
key: &'a str,
) -> SQLExpr<'a, PostgresValue<'a>, Text, Null, Self::Aggregate, Self::Sources>
fn json_get_text( self, key: &'a str, ) -> SQLExpr<'a, PostgresValue<'a>, Text, Null, Self::Aggregate, Self::Sources>
Gets an object field by key as text (->>). See json_get_text.
Sourcefn json_get_text_idx(
self,
index: i32,
) -> SQLExpr<'a, PostgresValue<'a>, Text, Null, Self::Aggregate, Self::Sources>
fn json_get_text_idx( self, index: i32, ) -> SQLExpr<'a, PostgresValue<'a>, Text, Null, Self::Aggregate, Self::Sources>
Gets an array element by index as text (->>). See json_get_text_idx.
Sourcefn json_get_path(
self,
path: &'a str,
) -> SQLExpr<'a, PostgresValue<'a>, <Self::SQLType as JsonType>::Field, Null, Self::Aggregate, Self::Sources>
fn json_get_path( self, path: &'a str, ) -> SQLExpr<'a, PostgresValue<'a>, <Self::SQLType as JsonType>::Field, Null, Self::Aggregate, Self::Sources>
Gets the value at a path (#>), keeping the JSON type. See json_get_path.
Sourcefn json_get_path_text(
self,
path: &'a str,
) -> SQLExpr<'a, PostgresValue<'a>, Text, Null, Self::Aggregate, Self::Sources>
fn json_get_path_text( self, path: &'a str, ) -> SQLExpr<'a, PostgresValue<'a>, Text, Null, Self::Aggregate, Self::Sources>
Gets the value at a path as text (#>>). See json_get_path_text.
Sourcefn jsonb_contains<R>(
self,
other: R,
) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, <Self::Aggregate as AggregateKind>::Or<R::Aggregate>, (Arg<Self::Nullable, Self::Sources>, Arg<R::Nullable, R::Sources>)>
fn jsonb_contains<R>( self, other: R, ) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, <Self::Aggregate as AggregateKind>::Or<R::Aggregate>, (Arg<Self::Nullable, Self::Sources>, Arg<R::Nullable, R::Sources>)>
Tests whether self contains other (@>, jsonb only). See jsonb_contains.
Sourcefn jsonb_contained<R>(
self,
other: R,
) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, <Self::Aggregate as AggregateKind>::Or<R::Aggregate>, (Arg<Self::Nullable, Self::Sources>, Arg<R::Nullable, R::Sources>)>
fn jsonb_contained<R>( self, other: R, ) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, <Self::Aggregate as AggregateKind>::Or<R::Aggregate>, (Arg<Self::Nullable, Self::Sources>, Arg<R::Nullable, R::Sources>)>
Tests whether self is contained in other (<@, jsonb only). See jsonb_contained.
Sourcefn jsonb_exists_key(
self,
key: &'a str,
) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, Self::Aggregate, Arg<Self::Nullable, Self::Sources>>
fn jsonb_exists_key( self, key: &'a str, ) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, Self::Aggregate, Arg<Self::Nullable, Self::Sources>>
Tests whether a top-level key exists (?, jsonb only). See jsonb_exists_key.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".