Skip to main content

JsonExprExt

Trait JsonExprExt 

Source
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§

Source

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,

Gets an object field by key (->), keeping the JSON type. See json_get.

Source

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,

Gets an array element by index (->), keeping the JSON type. See json_get_idx.

Source

fn json_get_text( self, key: &'a str, ) -> SQLExpr<'a, PostgresValue<'a>, Text, Null, Self::Aggregate, Self::Sources>
where Self::SQLType: JsonType,

Gets an object field by key as text (->>). See json_get_text.

Source

fn json_get_text_idx( self, index: i32, ) -> SQLExpr<'a, PostgresValue<'a>, Text, Null, Self::Aggregate, Self::Sources>
where Self::SQLType: JsonType,

Gets an array element by index as text (->>). See json_get_text_idx.

Source

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,

Gets the value at a path (#>), keeping the JSON type. See json_get_path.

Source

fn json_get_path_text( self, path: &'a str, ) -> SQLExpr<'a, PostgresValue<'a>, Text, Null, Self::Aggregate, Self::Sources>
where Self::SQLType: JsonType,

Gets the value at a path as text (#>>). See json_get_path_text.

Source

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,

Tests whether self contains other (@>, jsonb only). See jsonb_contains.

Source

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,

Tests whether self is contained in other (<@, jsonb only). See jsonb_contained.

Source

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,

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".

Implementors§

Source§

impl<'a, E: Expr<'a, PostgresValue<'a>>> JsonExprExt<'a> for E