Skip to content

Commit

Permalink
fix!: remove OVERWRITE_DB, swap to querry
Browse files Browse the repository at this point in the history
  • Loading branch information
NexVeridian committed Sep 26, 2024
1 parent d980355 commit 8df3ab1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 61 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ WIKIDATA_FILE_FORMAT=bz2
WIKIDATA_FILE_NAME=data/latest-all.json.bz2
# If not using docker file for Wikidata to SurrealDB, use 0.0.0.0:8000
WIKIDATA_DB_PORT=surrealdb:8000
# true=overwrite existing data, false=skip if already exists
OVERWRITE_DB=false
CREATE_VERSION=Bulk
#FILTER_PATH=data/filter.surql
```
Expand Down
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 9 additions & 39 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,8 @@ pub mod init_reader;
mod tables;
use tables::*;

static OVERWRITE_DB: OnceCell<bool> = OnceCell::const_new();
static FILTER_PATH: OnceCell<String> = OnceCell::const_new();

async fn get_overwrite_db() -> bool {
*OVERWRITE_DB
.get_or_init(|| async {
env::var("OVERWRITE_DB")
.expect("OVERWRITE_DB not set")
.parse::<bool>()
.expect("Failed to parse OVERWRITE_DB")
})
.await
}

async fn get_filter_path() -> &'static String {
FILTER_PATH
.get_or_init(|| async {
Expand Down Expand Up @@ -160,33 +148,15 @@ impl CreateVersion {
claims_vec.push(claims);
}

if get_overwrite_db().await {
db.upsert::<Vec<EntityMini>>("Entity")
.content(entity_vec)
.await?;
db.upsert::<Vec<Claims>>("Claims")
.content(claims_vec)
.await?;
db.upsert::<Vec<EntityMini>>("Property")
.content(property_vec)
.await?;
db.upsert::<Vec<EntityMini>>("Lexeme")
.content(lexeme_vec)
.await?;
} else {
db.insert::<Vec<EntityMini>>("Entity")
.content(entity_vec)
.await?;
db.insert::<Vec<Claims>>("Claims")
.content(claims_vec)
.await?;
db.insert::<Vec<EntityMini>>("Property")
.content(property_vec)
.await?;
db.insert::<Vec<EntityMini>>("Lexeme")
.content(lexeme_vec)
.await?;
}
db.query("INSERT INTO Entity $entity_vec RETURN NONE;")
.bind(("entity_vec", entity_vec))
.query("INSERT INTO Claims $claims_vec RETURN NONE;")
.bind(("claims_vec", claims_vec))
.query("INSERT INTO Property $property_vec RETURN NONE;")
.bind(("property_vec", property_vec))
.query("INSERT INTO Lexeme $lexeme_vec RETURN NONE;")
.bind(("lexeme_vec", lexeme_vec))
.await?;

if let Some(ref p) = pb {
p.inc(batch_size as u64)
Expand Down
1 change: 0 additions & 1 deletion tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use wikidata_to_surrealdb::utils::*;

async fn inti_db() -> Result<Surreal<Db>, Error> {
env::set_var("WIKIDATA_LANG", "en");
env::set_var("OVERWRITE_DB", "false");

let db = init_db::create_db_mem().await?;

Expand Down

0 comments on commit 8df3ab1

Please sign in to comment.