Replies: 1 comment
-
In my prototype (for surrealdb evaluation), below is what I've had in place (where use once_cell::sync::Lazy;
use surrealdb::{engine::any::Any, opt::auth::Root, Surreal};
use crate::common::req_env;
type Sdb = Surreal<Any>;
pub static SDB: Lazy<Sdb> = Lazy::new(Surreal::init);
pub async fn sdb_open() {
let address = req_env("SDB_ADDRESS");
let db = req_env("SDB_DB");
let ns = req_env("SDB_NS");
SDB.connect(address.clone())
.await
.expect("connection completed");
if !is_for_embedded(&address) {
let username = req_env("SDB_USERNAME");
let password = req_env("SDB_PASSWORD");
SDB.signin(Root {
username: &username,
password: &password,
})
.await
.expect("signin completed");
}
eprintln!("sdb_open => SurrealDB connected to '{address}'");
SDB.use_ns(ns)
.use_db(db)
.await
.expect("use_ns and use_db completed");
}
fn is_for_embedded(address: &str) -> bool {
address == "memory" || address.starts_with("surrealkv:") || address.starts_with("rocksdb:")
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I also want to write a flexible application that supports local (embedded) and remote (hosted) databases (based on the environment configuration). Is there any standard way to achieve this? I mean I want to connect to the selected (local or remote) database using a simple URL where the schema part will identify the database (rocksdb://db/file/path.db or ws://localhost:8000 )
Beta Was this translation helpful? Give feedback.
All reactions