Closed jamessewell closed 1 year ago
copy_in just returns a Sink of bytes - you can write a CSV into that.
I'm also looking to do this, I have a Vec<u8>
that I want to send to that sink but can't find a method that accepts that, which one could I use?
The sink consumes types implementing the Buf
trait. The simplest thing to do would be to convert your Vec into Bytes: Bytes::from(my_vec)
.
Through which method should I do that? Or can you perhaps provide a tiny example, my current code looks like:
let file = File::open("data.tsv").await.unwrap();
let mut reader = BufReader::new(file);
let copy_in = client.copy_in("COPY person (name, age) FROM STDIN WITH (HEADER MATCH)").await.unwrap();
pin_mut!(copy_in);
let mut buffer = [0; 8192];
loop {
let bytes_read = reader.read(&mut buffer).await.unwrap();
if bytes_read == 0 {
break;
}
copy_in.<how to send here with &buffer[..bytes_read]>.await.unwrap();
}
copy_in.finish().await.unwrap();
Is there still a way of doing the above from async code?
I can only seem to find working examples for the binary protocol (I don't know the column defs so I can't use this).