Skip to content

Commit

Permalink
Improved test
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Mar 16, 2024
1 parent 8b11596 commit f10ea0e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/postgres_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl ToSql for Vector {
mod tests {
use crate::Vector;
use postgres::binary_copy::BinaryCopyInWriter;
use postgres::types::{Kind, Type};
use postgres::{Client, NoTls};

#[test]
Expand Down Expand Up @@ -100,7 +101,7 @@ mod tests {
assert_eq!("[1,2,3]", text_res);

// copy
let vector_type = row.columns()[0].type_().clone();
let vector_type = vector_type(&mut client)?;
let writer =
client.copy_in("COPY postgres_items (embedding) FROM STDIN WITH (FORMAT BINARY)")?;
let mut writer = BinaryCopyInWriter::new(writer, &[vector_type]);
Expand All @@ -110,4 +111,14 @@ mod tests {

Ok(())
}

fn vector_type(client: &mut Client) -> Result<Type, postgres::Error> {
let row = client.query_one("SELECT pg_type.oid, nspname AS schema FROM pg_type INNER JOIN pg_namespace ON pg_namespace.oid = pg_type.typnamespace WHERE typname = 'vector'", &[])?;
Ok(Type::new(
"vector".into(),
row.get("oid"),
Kind::Simple,
row.get("schema"),
))
}
}

0 comments on commit f10ea0e

Please sign in to comment.