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:
./chdbin the current working directory - 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.
Currently, only OutputFormat arguments are supported and will be used
as the default output format for queries executed on this session.
§Arguments
arg- The argument to add (currently onlyOutputFormatis supported)
§Examples
use chdb_rust::session::SessionBuilder;
use chdb_rust::arg::Arg;
use chdb_rust::format::OutputFormat;
let builder = SessionBuilder::new()
.with_arg(Arg::OutputFormat(OutputFormat::JSONEachRow));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, Error>
pub fn build(self) -> Result<Session, Error>
Build the session with the configured settings.
This creates the data directory if it doesn’t exist and establishes a connection to the database.
§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()?;