Skip to main content

SessionBuilder

Struct SessionBuilder 

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

Source

pub fn new() -> Self

Create a new SessionBuilder with default settings.

The default settings are:

  • Data path: ./chdb in the current working directory
  • Output format: TabSeparated
  • Auto cleanup: false
§Examples
use chdb_rust::session::SessionBuilder;

let builder = SessionBuilder::new();
Source

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");
Source

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 only OutputFormat is 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));
Source

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

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

Trait Implementations§

Source§

impl Default for SessionBuilder<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for SessionBuilder<'a>

§

impl<'a> RefUnwindSafe for SessionBuilder<'a>

§

impl<'a> Send for SessionBuilder<'a>

§

impl<'a> Sync for SessionBuilder<'a>

§

impl<'a> Unpin for SessionBuilder<'a>

§

impl<'a> UnwindSafe for SessionBuilder<'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<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, 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.