pub struct Json<T>(pub T)
where
T: ?Sized;
Expand description
Json for json and jsonb fields
Will attempt to cast to type passed in as the generic.
[dependencies]
serde_json = { version = "1.0", features = ["raw_value"] }
ยงExample
#[derive(Deserialize)]
struct Book {
name: String
}
#[derive(sqlx::FromRow)]
struct Author {
name: String,
books: sqlx::types::Json<Book>
}
Can also be used to turn the json/jsonb into a hashmap
use std::collections::HashMap;
use serde::Deserialize;
#[derive(Deserialize)]
struct Book {
name: String
}
#[derive(sqlx::FromRow)]
struct Library {
id: String,
dewey_decimal: sqlx::types::Json<HashMap<String, Book>>
}
Tuple Fieldsยง
ยง0: T
Trait Implementationsยง
sourceยงimpl<'de, T> Deserialize<'de> for Json<T>where
T: Deserialize<'de> + ?Sized,
impl<'de, T> Deserialize<'de> for Json<T>where
T: Deserialize<'de> + ?Sized,
sourceยงfn deserialize<__D>(
__deserializer: __D
) -> Result<Json<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Json<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceยงimpl<T> Encode<'_, MySql> for Json<T>where
T: Serialize,
impl<T> Encode<'_, MySql> for Json<T>where
T: Serialize,
sourceยงfn encode(self, buf: &mut <DB as HasArguments<'q>>::ArgumentBuffer) -> IsNullwhere
Self: Sized,
fn encode(self, buf: &mut <DB as HasArguments<'q>>::ArgumentBuffer) -> IsNullwhere
Self: Sized,
Writes the value of
self
into buf
in the expected format for the database.fn produces(&self) -> Option<<DB as Database>::TypeInfo>
fn size_hint(&self) -> usize
sourceยงimpl<T> Encode<'_, Sqlite> for Json<T>where
T: Serialize,
impl<T> Encode<'_, Sqlite> for Json<T>where
T: Serialize,
sourceยงfn encode_by_ref(&self, buf: &mut Vec<SqliteArgumentValue<'_>>) -> IsNull
fn encode_by_ref(&self, buf: &mut Vec<SqliteArgumentValue<'_>>) -> IsNull
sourceยงfn encode(self, buf: &mut <DB as HasArguments<'q>>::ArgumentBuffer) -> IsNullwhere
Self: Sized,
fn encode(self, buf: &mut <DB as HasArguments<'q>>::ArgumentBuffer) -> IsNullwhere
Self: Sized,
Writes the value of
self
into buf
in the expected format for the database.fn produces(&self) -> Option<<DB as Database>::TypeInfo>
fn size_hint(&self) -> usize
sourceยงimpl<'q, T> Encode<'q, Postgres> for Json<T>where
T: Serialize,
impl<'q, T> Encode<'q, Postgres> for Json<T>where
T: Serialize,
sourceยงfn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull
fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull
sourceยงfn encode(self, buf: &mut <DB as HasArguments<'q>>::ArgumentBuffer) -> IsNullwhere
Self: Sized,
fn encode(self, buf: &mut <DB as HasArguments<'q>>::ArgumentBuffer) -> IsNullwhere
Self: Sized,
Writes the value of
self
into buf
in the expected format for the database.fn produces(&self) -> Option<<DB as Database>::TypeInfo>
fn size_hint(&self) -> usize
sourceยงimpl<T> PartialEq for Json<T>
impl<T> PartialEq for Json<T>
sourceยงimpl<T> PartialOrd for Json<T>where
T: PartialOrd + ?Sized,
impl<T> PartialOrd for Json<T>where
T: PartialOrd + ?Sized,
1.0.0 ยท sourceยงfn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresourceยงimpl<T> PgHasArrayType for Json<T>
impl<T> PgHasArrayType for Json<T>
fn array_type_info() -> PgTypeInfo
fn array_compatible(ty: &PgTypeInfo) -> bool
sourceยงimpl<T> Serialize for Json<T>
impl<T> Serialize for Json<T>
sourceยงfn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
sourceยงimpl<T> Type<MySql> for Json<T>
impl<T> Type<MySql> for Json<T>
sourceยงfn type_info() -> MySqlTypeInfo
fn type_info() -> MySqlTypeInfo
Returns the canonical SQL type for this Rust type. Read more
sourceยงfn compatible(ty: &MySqlTypeInfo) -> bool
fn compatible(ty: &MySqlTypeInfo) -> bool
Determines if this Rust type is compatible with the given SQL type. Read more
sourceยงimpl<T> Type<Postgres> for Json<T>
impl<T> Type<Postgres> for Json<T>
sourceยงfn type_info() -> PgTypeInfo
fn type_info() -> PgTypeInfo
Returns the canonical SQL type for this Rust type. Read more
sourceยงfn compatible(ty: &PgTypeInfo) -> bool
fn compatible(ty: &PgTypeInfo) -> bool
Determines if this Rust type is compatible with the given SQL type. Read more
sourceยงimpl<T> Type<Sqlite> for Json<T>
impl<T> Type<Sqlite> for Json<T>
sourceยงfn type_info() -> SqliteTypeInfo
fn type_info() -> SqliteTypeInfo
Returns the canonical SQL type for this Rust type. Read more
sourceยงfn compatible(ty: &SqliteTypeInfo) -> bool
fn compatible(ty: &SqliteTypeInfo) -> bool
Determines if this Rust type is compatible with the given SQL type. Read more
impl<T> Copy for Json<T>
impl<T> Eq for Json<T>
impl<T> StructuralPartialEq for Json<T>where
T: ?Sized,
Auto Trait Implementationsยง
impl<T: ?Sized> Freeze for Json<T>where
T: Freeze,
impl<T: ?Sized> RefUnwindSafe for Json<T>where
T: RefUnwindSafe,
impl<T: ?Sized> Send for Json<T>where
T: Send,
impl<T: ?Sized> Sync for Json<T>where
T: Sync,
impl<T: ?Sized> Unpin for Json<T>where
T: Unpin,
impl<T: ?Sized> UnwindSafe for Json<T>where
T: UnwindSafe,
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
sourceยงimpl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
sourceยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
sourceยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
sourceยงfn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.