pub struct InsertStream<'a> { /* private fields */ }Expand description
An open streaming INSERT.
The connection is exclusively borrowed for the life of the stream: chDB accepts no other statement on a connection while one is open.
§Examples
use chdb_rust::connection::Connection;
use chdb_rust::format::InputFormat;
let mut conn = Connection::open_in_memory()?;
let mut ins = conn.insert_stream("INSERT INTO t (a, b)", InputFormat::CSV)?;
ins.append(b"1,\"one\"\n")?;
let stats = ins.finish()?;
println!("wrote {} rows", stats.rows_written);Implementations§
Source§impl<'a> InsertStream<'a>
impl<'a> InsertStream<'a>
Sourcepub fn with_write_buffer(self, bytes: usize) -> Self
pub fn with_write_buffer(self, bytes: usize) -> Self
Set how many bytes io::Write gathers before sending them to the engine.
Defaults to DEFAULT_WRITE_BUFFER (64 KiB). Pass 0 to send every
write straight away. This only affects writes made through
std::io::Write; append always sends immediately.
use std::io::Write;
use chdb_rust::connection::Connection;
use chdb_rust::format::InputFormat;
let mut conn = Connection::open_in_memory()?;
let mut ins = conn
.insert_stream("INSERT INTO t (a)", InputFormat::CSV)?
.with_write_buffer(1024 * 1024);
writeln!(ins, "1")?;
ins.finish()?;Sourcepub fn append(&mut self, data: &[u8]) -> Result<()>
pub fn append(&mut self, data: &[u8]) -> Result<()>
Append one chunk of format-encoded data.
The bytes must be in the input format the stream was opened with. Chunk boundaries need not align to row boundaries. The data is copied by the engine, so the caller keeps ownership.
May block while the engine applies backpressure.
§Errors
Returns Error::QueryError if the stream has already failed — a
malformed row in an earlier chunk, for instance — or was finalised.
Sourcepub fn finish(self) -> Result<WriteStats>
pub fn finish(self) -> Result<WriteStats>
Finalise the insert and commit.
§Errors
Returns Error::QueryError if the engine rejected any of the data.
Trait Implementations§
Source§impl<'a> Debug for InsertStream<'a>
impl<'a> Debug for InsertStream<'a>
Source§impl Drop for InsertStream<'_>
impl Drop for InsertStream<'_>
Source§impl Write for InsertStream<'_>
Lets anything that writes bytes — serde_json::to_writer, csv::Writer,
write! — feed the stream directly.
impl Write for InsertStream<'_>
Lets anything that writes bytes — serde_json::to_writer, csv::Writer,
write! — feed the stream directly.
Writes are buffered (64 KiB by default, see
InsertStream::with_write_buffer) before being sent, so a writeln! per row
doesn’t turn into a trip to the engine per row. Because of that, an error
caused by a write can show up on a later write, on flush, or on
InsertStream::finish.
Errors are surfaced as
std::io::ErrorKind::Other carrying the engine’s message, because that is
the only shape io::Write has for them.
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Sends anything buffered to the engine. InsertStream::finish does
this too, so calling it is only needed to surface errors early.
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)