forked from pola-rs/nodejs-polars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql.rs
44 lines (38 loc) · 987 Bytes
/
sql.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::{export::JsLazyFrame, prelude::*};
use polars::sql::SQLContext;
#[napi(js_name = "SqlContext")]
#[repr(transparent)]
#[derive(Clone)]
pub struct JsSQLContext {
context: SQLContext,
}
#[napi]
impl JsSQLContext {
#[napi(constructor)]
#[allow(clippy::new_without_default)]
pub fn new() -> JsSQLContext {
JsSQLContext {
context: SQLContext::new(),
}
}
#[napi(catch_unwind)]
pub fn execute(&mut self, query: String) -> JsResult<JsLazyFrame> {
Ok(self
.context
.execute(&query)
.map_err(JsPolarsErr::from)?
.into())
}
#[napi]
pub fn get_tables(&self) -> Vec<String> {
self.context.get_tables()
}
#[napi]
pub fn register(&mut self, name: String, lf: &JsLazyFrame) {
self.context.register(&name, lf.clone().ldf)
}
#[napi]
pub fn unregister(&mut self, name: String) {
self.context.unregister(&name)
}
}