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
impl InsertFormatted
Sourcepub async fn send_compressed(&mut self, data: CompressedData) -> Result<()>
Available on crate feature lz4 only.
pub async fn send_compressed(&mut self, data: CompressedData) -> Result<()>
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
impl InsertFormatted
Sourcepub fn with_timeouts(
self,
send_timeout: Option<Duration>,
end_timeout: Option<Duration>,
) -> Self
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().
Sourcepub fn with_roles(
self,
roles: impl IntoIterator<Item = impl Into<String>>,
) -> Self
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.
Sourcepub fn with_default_roles(self) -> Self
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.
Sourcepub fn with_option(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Self
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.
Sourcepub fn buffered(self) -> BufInsertFormatted
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().
Sourcepub fn buffered_with_capacity(self, capacity: usize) -> BufInsertFormatted
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.
Sourcepub async fn send(&mut self, data: Bytes) -> Result<()>
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.