Skip to content

Commit

Permalink
Implement PgHasArrayType for JSON types in the serde_json crate
Browse files Browse the repository at this point in the history
  • Loading branch information
abreis committed Feb 22, 2022
1 parent eaf41fd commit 97b68a4
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions sqlx-core/src/postgres/types/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use crate::postgres::{
};
use crate::types::{Json, Type};
use serde::{Deserialize, Serialize};
use serde_json::value::RawValue as JsonRawValue;
use serde_json::Value as JsonValue;

// <https://www.postgresql.org/docs/12/datatype-json.html>

Expand Down Expand Up @@ -34,6 +36,26 @@ impl<T> PgHasArrayType for Json<T> {
}
}

impl PgHasArrayType for JsonValue {
fn array_type_info() -> PgTypeInfo {
PgTypeInfo::JSONB_ARRAY
}

fn array_compatible(ty: &PgTypeInfo) -> bool {
array_compatible::<JsonValue>(ty)
}
}

impl PgHasArrayType for JsonRawValue {
fn array_type_info() -> PgTypeInfo {
PgTypeInfo::JSONB_ARRAY
}

fn array_compatible(ty: &PgTypeInfo) -> bool {
array_compatible::<JsonRawValue>(ty)
}
}

impl<'q, T> Encode<'q, Postgres> for Json<T>
where
T: Serialize,
Expand Down

0 comments on commit 97b68a4

Please sign in to comment.