Skip to content

Commit

Permalink
Add support for Postgres lquery arrays
Browse files Browse the repository at this point in the history
An lquery array can be used with the `?` operator for "Does ltree match
any lquery in array?"

Documentation: https://www.postgresql.org/docs/current/ltree.html#LTREE-OPS-FUNCS

Closes #2246
  • Loading branch information
philipcristiano committed Oct 9, 2024
1 parent 028084b commit 9a222d5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sqlx-postgres/src/types/lquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::decode::Decode;
use crate::encode::{Encode, IsNull};
use crate::error::BoxDynError;
use crate::types::Type;
use crate::{PgArgumentBuffer, PgTypeInfo, PgValueFormat, PgValueRef, Postgres};
use crate::{PgArgumentBuffer, PgHasArrayType, PgTypeInfo, PgValueFormat, PgValueRef, Postgres};
use bitflags::bitflags;
use std::fmt::{self, Display, Formatter};
use std::io::Write;
Expand Down Expand Up @@ -161,6 +161,12 @@ impl Type<Postgres> for PgLQuery {
}
}

impl PgHasArrayType for PgLQuery {
fn array_type_info() -> PgTypeInfo {
PgTypeInfo::with_name("_lquery")
}
}

impl Encode<'_, Postgres> for PgLQuery {
fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> Result<IsNull, BoxDynError> {
buf.extend(1i8.to_le_bytes());
Expand Down

0 comments on commit 9a222d5

Please sign in to comment.