mirror of
https://github.com/NexVeridian/wikidata-to-surrealdb.git
synced 2025-09-02 09:59:13 +00:00
refactor init_db and init_progress_bar
This commit is contained in:
parent
731df97cd2
commit
2ded1d5b1b
8 changed files with 103 additions and 134 deletions
38
src/utils/init_db.rs
Normal file
38
src/utils/init_db.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use anyhow::Error;
|
||||
use anyhow::Result;
|
||||
use lazy_static::lazy_static;
|
||||
use std::env;
|
||||
use surrealdb::{
|
||||
engine::{
|
||||
local::{Db, Mem},
|
||||
remote::ws::{Client, Ws},
|
||||
},
|
||||
opt::auth::Root,
|
||||
Surreal,
|
||||
};
|
||||
|
||||
lazy_static! {
|
||||
static ref DB_USER: String = env::var("DB_USER").expect("DB_USER not set");
|
||||
static ref DB_PASSWORD: String = env::var("DB_PASSWORD").expect("DB_PASSWORD not set");
|
||||
static ref WIKIDATA_DB_PORT: String =
|
||||
env::var("WIKIDATA_DB_PORT").expect("WIKIDATA_DB_PORT not set");
|
||||
}
|
||||
|
||||
pub async fn create_db_ws() -> Result<Surreal<Client>, Error> {
|
||||
let db = Surreal::new::<Ws>(WIKIDATA_DB_PORT.as_str()).await?;
|
||||
|
||||
db.signin(Root {
|
||||
username: &DB_USER,
|
||||
password: &DB_PASSWORD,
|
||||
})
|
||||
.await?;
|
||||
db.use_ns("wikidata").use_db("wikidata").await?;
|
||||
|
||||
Ok(db)
|
||||
}
|
||||
|
||||
pub async fn create_db_mem() -> Result<Surreal<Db>, Error> {
|
||||
let db = Surreal::new::<Mem>(()).await?;
|
||||
db.use_ns("wikidata").use_db("wikidata").await?;
|
||||
Ok(db)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue