surrealpatch/src/dbs/mod.rs
2022-07-04 01:46:09 +01:00

17 lines
420 B
Rust

use crate::cli::CF;
use crate::err::Error;
use once_cell::sync::OnceCell;
use surrealdb::Datastore;
pub static DB: OnceCell<Datastore> = OnceCell::new();
pub async fn init() -> Result<(), Error> {
// Get local copy of options
let opt = CF.get().unwrap();
// Parse and setup the desired kv datastore
let dbs = Datastore::new(&opt.path).await?;
// Store database instance
let _ = DB.set(dbs);
// All ok
Ok(())
}