Add surrealdb module as a global object in JavaScript runtime

This commit is contained in:
Tobie Morgan Hitchcock 2022-07-23 20:06:21 +01:00
parent 3dc29e1228
commit db3115fc7c
4 changed files with 11 additions and 0 deletions

View file

@ -0,0 +1 @@
pub mod surrealdb;

View 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;
}

View file

@ -1,5 +1,6 @@
use super::classes;
use super::executor::Executor;
use super::globals;
use super::modules::loader;
use super::modules::resolver;
use crate::ctx::Context;
@ -36,6 +37,8 @@ pub async fn run(
let res: Result<Promise<Value>, js::Error> = ctx.with(|ctx| {
// Get the context global object
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
global.init_def::<classes::Duration>().unwrap();
// Register the Record type as a global class

View file

@ -6,6 +6,7 @@ mod classes;
mod error;
mod executor;
mod from;
mod globals;
mod into;
mod main;
mod modules;