pub struct SessionBuilder<'a> { /* private fields */ }Expand description
Builder for creating Session instances.
SessionBuilder provides a fluent API for configuring and creating sessions.
Use new to create a new builder, configure it with the desired
options, and call build to create the session.
§Examples
use chdb_rust::session::SessionBuilder;
// Create a session with default settings
let session = SessionBuilder::new()
.with_data_path("/tmp/mydb")
.with_auto_cleanup(true)
.build()?;Implementations§
Source§impl<'a> SessionBuilder<'a>
impl<'a> SessionBuilder<'a>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new SessionBuilder with default settings.
The default settings are:
- Data path: current working directory. The
buildmethod will create achdbsubdirectory if the path is not set. - Output format:
TabSeparated - Auto cleanup:
false
§Examples
use chdb_rust::session::SessionBuilder;
let builder = SessionBuilder::new();Sourcepub fn with_data_path(self, path: impl Into<PathBuf>) -> Self
pub fn with_data_path(self, path: impl Into<PathBuf>) -> Self
Set the data path for the session.
This specifies the filesystem path where the database will be stored. The directory will be created if it doesn’t exist.
§Arguments
path- The path where the database should be stored
§Examples
use chdb_rust::session::SessionBuilder;
let builder = SessionBuilder::new()
.with_data_path("/tmp/mydb");Sourcepub fn with_arg(self, arg: Arg<'a>) -> Self
pub fn with_arg(self, arg: Arg<'a>) -> Self
Add a query argument to the session builder.
If OutputFormat argument is provided it will be used
as the default output format for queries executed on this session.
Moreover, OutputFormat is consumed by the session layer and is not
forwarded as a command-line argument to the connection.
§Arguments
arg- The argument to add
§Examples
use chdb_rust::session::SessionBuilder;
use chdb_rust::arg::Arg;
use chdb_rust::format::OutputFormat;
use std::borrow::Cow;
let builder = SessionBuilder::new()
.with_arg(Arg::OutputFormat(OutputFormat::JSONEachRow))
.with_arg(Arg::ConfigFilePath(Cow::from("chdb_ssl.xml")))
.with_arg(Arg::Custom(Cow::from("progress"), Some(Cow::from("err"))));Custom arguments can be used to specify any additional command-line arguments
that can be found by running clickhouse-client --help in
the terminal.
Sourcepub fn with_auto_cleanup(self, value: bool) -> Self
pub fn with_auto_cleanup(self, value: bool) -> Self
Enable or disable automatic cleanup of the data directory.
If set to true, the session will automatically delete the data directory
when it is dropped. This is useful for temporary databases.
§Arguments
value- Whether to enable automatic cleanup
§Examples
use chdb_rust::session::SessionBuilder;
// Session will clean up data directory on drop
let session = SessionBuilder::new()
.with_data_path("/tmp/tempdb")
.with_auto_cleanup(true)
.build()?;Sourcepub fn build(self) -> Result<Session>
pub fn build(self) -> Result<Session>
Build the session with the configured settings.
This creates the data directory if it doesn’t exist and establishes a connection to the database. All configured arguments are passed to the connection.
§Returns
Returns a Session if successful, or an Error if
the session cannot be created.
§Errors
Returns an error if:
- The data path cannot be created
- The data path has insufficient permissions
- The connection cannot be established
§Examples
use chdb_rust::session::SessionBuilder;
let session = SessionBuilder::new()
.with_data_path("/tmp/mydb")
.build()?;