Skip to main content

InsertFormatted

Struct InsertFormatted 

Source
pub struct InsertFormatted { /* private fields */ }
Expand description

Performs one INSERT, sending pre-formatted data.

The InsertFormatted::end method must be called to finalize the INSERT. Otherwise, the whole INSERT will be aborted.

Rows are sent progressively to spread network load.

§Note: Not Validated

Unlike Insert and Inserter, this does not perform any validation on the submitted data.

Only the use of self-describing formats (e.g. CSV, TabSeparated, JSON) is recommended.

See the list of supported formats for details.

Implementations§

Source§

impl InsertFormatted

Source

pub async fn send_compressed(&mut self, data: CompressedData) -> Result<()>

Available on crate feature lz4 only.

Send a chunk of pre-compressed data.

§Errors

In addition to network errors, this will return Error::Compression if the Client does not have compression enabled.

Source§

impl InsertFormatted

Source

pub fn with_timeouts( self, send_timeout: Option<Duration>, end_timeout: Option<Duration>, ) -> Self

Sets timeouts for different operations.

send_timeout restricts time on sending a data chunk to a socket. None disables the timeout, it’s a default. It’s roughly equivalent to tokio::time::timeout(insert.write(...)).

end_timeout restricts time on waiting for a response from the CH server. Thus, it includes all work needed to handle INSERT by the CH server, e.g. handling all materialized views and so on. None disables the timeout, it’s a default. It’s roughly equivalent to tokio::time::timeout(insert.end(...)).

These timeouts are much more performant (~x10) than wrapping write() and end() calls into tokio::time::timeout().

Source

pub fn with_roles( self, roles: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Configure the roles to use when executing INSERT statements.

Overrides any roles previously set by this method, InsertFormatted::with_option, Client::with_roles or Client::with_option.

An empty iterator may be passed to clear the set roles.

§Panics

If called after the request is started, e.g., after InsertFormatted::send.

Source

pub fn with_default_roles(self) -> Self

Clear any explicit roles previously set on this Insert or inherited from Client.

Overrides any roles previously set by InsertFormatted::with_roles, InsertFormatted::with_option, Client::with_roles or Client::with_option.

§Panics

If called after the request is started, e.g., after InsertFormatted::send.

Source

pub fn with_option( self, name: impl Into<String>, value: impl Into<String>, ) -> Self

Similar to Client::with_option, but for this particular INSERT statement only.

§Panics

If called after the request is started, e.g., after InsertFormatted::send.

Source

pub fn buffered(self) -> BufInsertFormatted

Wrap this InsertFormatted with a buffer of a default size.

The returned type also implements AsyncWrite.

To set the capacity, use Self::buffered_with_capacity().

Source

pub fn buffered_with_capacity(self, capacity: usize) -> BufInsertFormatted

Wrap this InsertFormatted with a buffer of a given size.

The returned type also implements AsyncWrite.

If capacity == 0, the buffer is flushed between every write regardless of size.

Source

pub async fn send(&mut self, data: Bytes) -> Result<()>

Send a chunk of data.

If compression is enabled, the data is compressed first.

To pre-compress the data, use Self::send_compressed() instead.

§Note: Unbuffered

This immediately compresses and queues the data to be sent on the connection without waiting for more chunks. For best performance, chunks should not be too small.

Use Self::buffered() for a buffered implementation which also implements AsyncWrite.

Source

pub async fn end(self) -> Result<()>

Ends INSERT, the server starts processing the data.

Succeeds if the server returns 200, that means the INSERT was handled successfully, including all materialized views and quorum writes.

NOTE: If this isn’t called, the whole INSERT is aborted.

Trait Implementations§

Source§

impl Drop for InsertFormatted

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Is for T
where T: ?Sized,

Source§

type EqTo = T

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more