use oxisql_postgres::{PgConnection, TlsMode};
const PG_CONN_STR: &str = "host=localhost port=5432 user=postgres";
#[tokio::test]
#[ignore = "requires a live PostgreSQL server"]
async fn test_copy_in_and_out() {
let conn = PgConnection::connect(PG_CONN_STR, TlsMode::Disabled)
.await
.expect("connect");
conn.copy_in_text("", &[], std::iter::empty::<Vec<String>>())
.await
.expect_err("empty columns should fail");
use oxisql_core::Connection;
conn.execute_batch(
"CREATE TEMP TABLE oxisql_copy_test (\
id TEXT NOT NULL,\
name TEXT NOT NULL,\
note TEXT NOT NULL\
)",
)
.await
.expect("CREATE TEMP TABLE");
let rows: Vec<Vec<String>> = vec![
vec!["1".into(), "Alice".into(), "plain text".into()],
vec!["2".into(), "Bob".into(), "with\nnewline".into()],
vec![
"3".into(),
"Carol".into(),
"with\ttab and \\backslash".into(),
],
];
let count = conn
.copy_in_text(
"oxisql_copy_test",
&["id", "name", "note"],
rows.clone().into_iter(),
)
.await
.expect("copy_in_text");
assert_eq!(count, 3, "expected 3 rows inserted");
let out = conn
.copy_out_text("oxisql_copy_test", &["id", "name", "note"])
.await
.expect("copy_out_text");
assert_eq!(out.len(), 3, "expected 3 rows returned");
let mut sorted_in = rows;
sorted_in.sort();
let mut sorted_out = out;
sorted_out.sort();
assert_eq!(sorted_in, sorted_out, "round-trip mismatch");
}