Add surrealdb module as a global object in JavaScript runtime
This commit is contained in:
parent
3dc29e1228
commit
db3115fc7c
4 changed files with 11 additions and 0 deletions
1
lib/src/fnc/script/globals/mod.rs
Normal file
1
lib/src/fnc/script/globals/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod surrealdb;
|
6
lib/src/fnc/script/globals/surrealdb.rs
Normal file
6
lib/src/fnc/script/globals/surrealdb.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#[js::bind(object, public)]
|
||||||
|
#[quickjs(rename = "surrealdb")]
|
||||||
|
#[allow(non_upper_case_globals)]
|
||||||
|
pub mod package {
|
||||||
|
pub const version: &str = crate::cnf::VERSION;
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
use super::classes;
|
use super::classes;
|
||||||
use super::executor::Executor;
|
use super::executor::Executor;
|
||||||
|
use super::globals;
|
||||||
use super::modules::loader;
|
use super::modules::loader;
|
||||||
use super::modules::resolver;
|
use super::modules::resolver;
|
||||||
use crate::ctx::Context;
|
use crate::ctx::Context;
|
||||||
|
@ -36,6 +37,8 @@ pub async fn run(
|
||||||
let res: Result<Promise<Value>, js::Error> = ctx.with(|ctx| {
|
let res: Result<Promise<Value>, js::Error> = ctx.with(|ctx| {
|
||||||
// Get the context global object
|
// Get the context global object
|
||||||
let global = ctx.globals();
|
let global = ctx.globals();
|
||||||
|
// Register the surrealdb module as a global object
|
||||||
|
global.init_def::<globals::surrealdb::Package>().unwrap();
|
||||||
// Register the Duration type as a global class
|
// Register the Duration type as a global class
|
||||||
global.init_def::<classes::Duration>().unwrap();
|
global.init_def::<classes::Duration>().unwrap();
|
||||||
// Register the Record type as a global class
|
// Register the Record type as a global class
|
||||||
|
|
|
@ -6,6 +6,7 @@ mod classes;
|
||||||
mod error;
|
mod error;
|
||||||
mod executor;
|
mod executor;
|
||||||
mod from;
|
mod from;
|
||||||
|
mod globals;
|
||||||
mod into;
|
mod into;
|
||||||
mod main;
|
mod main;
|
||||||
mod modules;
|
mod modules;
|
||||||
|
|
Loading…
Reference in a new issue