Skip to main content

InsertStream

Struct InsertStream 

Source
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>

Source

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()?;
Source

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.

Source

pub fn finish(self) -> Result<WriteStats>

Finalise the insert and commit.

§Errors

Returns Error::QueryError if the engine rejected any of the data.

Source

pub fn cancel(self)

Abort without committing.

ClickHouse-default semantics: no rollback of anything already flushed.

Trait Implementations§

Source§

impl<'a> Debug for InsertStream<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for InsertStream<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

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<()>

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>

Writes a buffer into this writer, returning how many bytes were written. Read more
1.36.0 · Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations§

§

impl<'a> !Send for InsertStream<'a>

§

impl<'a> !Sync for InsertStream<'a>

§

impl<'a> !UnwindSafe for InsertStream<'a>

§

impl<'a> Forget for InsertStream<'a>

§

impl<'a> Freeze for InsertStream<'a>

§

impl<'a> Move for InsertStream<'a>

§

impl<'a> RefUnwindSafe for InsertStream<'a>

§

impl<'a> Unpin for InsertStream<'a>

§

impl<'a> UnsafeUnpin for InsertStream<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.