Sha256: eed99485bd0989f1822f951b9e0950f186ac104d3f934fac8661e6cb8a791bd2

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

use polars::sql::SQLContext;
use std::cell::RefCell;

use crate::{RbLazyFrame, RbPolarsErr, RbResult};

#[magnus::wrap(class = "Polars::RbSQLContext")]
#[repr(transparent)]
#[derive(Clone)]
pub struct RbSQLContext {
    pub context: RefCell<SQLContext>,
}

#[allow(
    clippy::wrong_self_convention,
    clippy::should_implement_trait,
    clippy::len_without_is_empty
)]
impl RbSQLContext {
    #[allow(clippy::new_without_default)]
    pub fn new() -> RbSQLContext {
        RbSQLContext {
            context: SQLContext::new().into(),
        }
    }

    pub fn execute(&self, query: String) -> RbResult<RbLazyFrame> {
        Ok(self
            .context
            .borrow_mut()
            .execute(&query)
            .map_err(RbPolarsErr::from)?
            .into())
    }

    pub fn get_tables(&self) -> RbResult<Vec<String>> {
        Ok(self.context.borrow().get_tables())
    }

    pub fn register(&self, name: String, lf: &RbLazyFrame) {
        self.context.borrow_mut().register(&name, lf.ldf.clone())
    }

    pub fn unregister(&self, name: String) {
        self.context.borrow_mut().unregister(&name)
    }
}

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
polars-df-0.11.0 ext/polars/src/sql.rs
polars-df-0.10.0 ext/polars/src/sql.rs
polars-df-0.9.0 ext/polars/src/sql.rs
polars-df-0.8.0 ext/polars/src/sql.rs
polars-df-0.7.0 ext/polars/src/sql.rs