fn has_all_keys<T>(self, other: T) -> dsl::HasAllKeysJsonb<Self, T>
    where
        T: AsExpression<Array<VarChar>>,
    {
        Grouped(HasAllKeysJsonb::new(self, other.as_expression()))
    }
/// Creates a PostgreSQL `?&` expression.
///
/// This operator checks if all the strings in the right hand side array exist as top level keys in the given JSONB
///
/// # Example
///
/// ```rust
/// # include!("../../doctest_setup.rs");
/// #
/// # table! {
/// #    contacts {
/// #        id -> Integer,
/// #        name -> VarChar,
/// #        address -> Jsonb,
/// #    }
/// # }
/// #
/// # fn main() {
/// #     run_test().unwrap();
/// # }
///
/// # #[cfg(feature = "serde_json")]
/// # fn run_test() -> QueryResult<()> {
/// #     use self::contacts::dsl::*;
/// #     let conn = &mut establish_connection();
/// #     conn.execute("DROP TABLE IF EXISTS contacts").unwrap();
/// #     conn.execute("CREATE TABLE contacts (
/// #         id SERIAL PRIMARY KEY,
/// #         name VARCHAR NOT NULL,
/// #         address JSONB NOT NULL
/// #     )").unwrap();
/// #
/// let santas_address: serde_json::Value = serde_json::json!({
///     "street": "Article Circle Expressway 1",
///     "city": "North Pole",
///     "postcode": "99705",
///     "state": "Alaska"
/// });
/// diesel::insert_into(contacts)
///     .values((name.eq("Claus"), address.eq(&santas_address)))
///     .execute(conn)?;
///
/// let all_keys_exist = contacts.select(address.has_all_keys(vec!["street", "city", "postcode"])).get_result::<bool>(conn)?;
/// assert!(all_keys_exist);
///
/// let santas_with_address_postcode = contacts.select(id).filter(address.has_all_keys(vec!["street", "city", "postcode"])).get_result::<i32>(conn)?;
/// assert_eq!(1, santas_with_address_postcode);
/// #     Ok(())
/// # }
/// # #[cfg(not(feature = "serde_json"))]
/// # fn run_test() -> QueryResult<()> {
/// #     Ok(())
/// # }
/// ``````
Creates a PostgreSQL `?&` expression.
This operator checks if all the strings in the right hand side array exist as top level keys in the given JSONB
Creates a PostgreSQL ` ?& ` expression . This operator checks if all the strings in the right hand side array exist as top level keys in the given JSONB
fn has_all_keys<T>(self, other: T) -> dsl::HasAllKeysJsonb<Self, T>
    where
        T: AsExpression<Array<VarChar>>,
    {
        Grouped(HasAllKeysJsonb::new(self, other.as_expression()))
    }
fn has_all_keys < T > ( self , other : T ) -> dsl :: HasAllKeysJsonb < Self , T > where T : AsExpression < Array < VarChar > > , { Grouped ( HasAllKeysJsonb :: new ( self , other . as_expression ( ) ) ) }
Creates a PostgreSQL `?&` expression.
Creates a PostgreSQL ` ?& ` expression .
self
other
T
self
other
T
example
None
include!("../../doctest_setup.rs");
None
table! {
None
contacts {
None
id -> integer,
None
name -> varchar,
None
address -> jsonb,
None
}
None
}
None
fn main() {
None
run_test().unwrap();
None
}
None
#[cfg(feature = "serde_json")]
None
fn run_test() -> queryresult<()> {
None
use self::contacts::dsl::*;
None
let conn = &mut establish_connection();
None
conn.execute("drop table if exists contacts").unwrap();
None
conn.execute("create table contacts (
None
id serial primary key,
None
name varchar not null,
None
address jsonb not null
None
)").unwrap();
let santas_address: serde_json::Value = serde_json::json!({
"street": "Article Circle Expressway 1",
"city": "North Pole",
"postcode": "99705",
"state": "Alaska"
});
diesel::insert_into(contacts)
.values((name.eq("Claus"), address.eq(&santas_address)))
.execute(conn)?.

let all_keys_exist = contacts.select(address.has_all_keys(vec!["street", "city", "postcode"])).get_result::(conn)?;
assert!(all_keys_exist).

let santas_with_address_postcode = contacts.select(id).filter(address.has_all_keys(vec!["street", "city", "postcode"])).get_result::(conn)?;
assert_eq!(1, santas_with_address_postcode).
let santas_address : serde_json :: Value = serde_json :: json! ( { " street " : " Article Circle Expressway 1 " " city " : " North Pole " " postcode " : " 99705 " " state " : " Alaska " } ) ; diesel :: insert_into ( contacts ) . values (( name . eq ( " Claus " ) address . eq ( &santas_address ))) . execute ( conn ) ? . let all_keys_exist = contacts . select ( address . has_all_keys ( vec! [ " street " " city " " postcode " ] )) . get_result :: ( conn ) ? ; assert! ( all_keys_exist ) . let santas_with_address_postcode = contacts . select ( id ) . filter ( address . has_all_keys ( vec! [ " street " " city " " postcode " ] )) . get_result :: ( conn ) ? ; assert_eq! ( 1 santas_with_address_postcode ) .
ok(())
None
}
None
#[cfg(not(feature = "serde_json"))]
None
fn run_test() -> queryresult<()> {
None
ok(())
None
}
None