Skip to content

Commit

Permalink
Added test for binary copy
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Mar 6, 2024
1 parent b183250 commit 435d4f4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/postgres_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl ToSql for Vector {
#[cfg(test)]
mod tests {
use crate::Vector;
use postgres::binary_copy::BinaryCopyInWriter;
use postgres::{Client, NoTls};

#[test]
Expand Down Expand Up @@ -98,6 +99,15 @@ mod tests {
let text_res: String = text_row.get(0);
assert_eq!("[1,2,3]", text_res);

// copy
let vector_type = row.columns()[0].type_().clone();
let writer =
client.copy_in("COPY postgres_items (embedding) FROM STDIN WITH (FORMAT BINARY)")?;
let mut writer = BinaryCopyInWriter::new(writer, &[vector_type]);
writer.write(&[&Vector::from(vec![1.0, 2.0, 3.0])]).unwrap();
writer.write(&[&Vector::from(vec![4.0, 5.0, 6.0])]).unwrap();
writer.finish()?;

Ok(())
}
}

0 comments on commit 435d4f4

Please sign in to comment.