Add ltree, lquery and ltxtquery support

This commit is contained in:
Matt Oliver
2022-03-03 00:06:46 -06:00
parent a638adaf79
commit 944b72974f
6 changed files with 131 additions and 16 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "postgres-protocol"
version = "0.6.3"
version = "0.6.4"
authors = ["Steven Fackler <sfackler@gmail.com>"]
edition = "2018"
description = "Low level Postgres protocol APIs"

View File

@@ -1059,3 +1059,19 @@ impl Inet {
self.netmask
}
}
/// Serializes a Postgres l{tree,query,txtquery} string
#[inline]
pub fn ltree_to_sql(v: &str, buf: &mut BytesMut) {
// A version number is prepended to an Ltree string per spec
buf.put_u8(1);
// Append the rest of the query
buf.put_slice(v.as_bytes());
}
/// Deserialize a Postgres l{tree,query,txtquery} string
#[inline]
pub fn ltree_from_sql(buf: &[u8]) -> Result<&str, StdBox<dyn Error + Sync + Send>> {
// Remove the version number from the front of the string per spec
Ok(str::from_utf8(&buf[1..])?)
}