#[non_exhaustive]pub struct CopyIn<'a> { /* private fields */ }Expand description
A writer for a COPY IN operation.
Created via Connection::copy_in. Data is sent to the server in
chunks. The operation must be completed with finish
or cancelled with cancel.
Implementations§
Source§impl<'a> CopyIn<'a>
impl<'a> CopyIn<'a>
Sourcepub fn format(&self) -> u8
pub fn format(&self) -> u8
The overall format code for this COPY operation.
0 = text, 1 = binary.
Sourcepub fn column_formats(&self) -> &[u16]
pub fn column_formats(&self) -> &[u16]
Per-column format codes.
Sourcepub async fn write_row(&mut self, columns: &[&str]) -> Result<()>
pub async fn write_row(&mut self, columns: &[&str]) -> Result<()>
Send a single text-format row.
Columns are joined with \t and terminated with \n.
Sourcepub async fn write_csv_row(
&mut self,
columns: &[&str],
delimiter: char,
quote: char,
) -> Result<()>
pub async fn write_csv_row( &mut self, columns: &[&str], delimiter: char, quote: char, ) -> Result<()>
Send a single CSV-format row.
This uses PostgreSQL CSV format rules: fields containing the delimiter, quote character, or newline are wrapped in quotes; quotes inside quoted fields are doubled.
Note: This method cannot represent NULL values. Use
write_csv_row_with_null if you need
NULL support.
Sourcepub async fn write_csv_row_with_null(
&mut self,
columns: &[Option<&str>],
delimiter: char,
quote: char,
null_string: &str,
) -> Result<()>
pub async fn write_csv_row_with_null( &mut self, columns: &[Option<&str>], delimiter: char, quote: char, null_string: &str, ) -> Result<()>
Send a single CSV-format row with NULL support.
Like write_csv_row, but each column is an
Option<&str>. None values are written as the null_string
parameter (typically "" for the default PostgreSQL CSV NULL
representation, which is an empty string).
§Example
let mut copy = conn.copy_in("COPY users (id, name) FROM STDIN WITH (FORMAT csv)").await?;
copy.write_csv_row_with_null(
&[Some("1"), None, Some("active")],
',', '"', "",
).await?;