Skip to content

Commit

Permalink
Add example for new valve api
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcmicu committed Jan 14, 2024
1 parent 86c62e6 commit 9003bed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ rev = "f46fbd5450505644ed9970cef1ae14164699981f"

[dependencies.ontodev_valve]
git = "https://github.com/ontodev/valve.rs"
rev = "2c06218be84012a98f53e5ba695094a303891b29"
rev = "db9502201ce5e1d8d2ff368ca6c1f3f873aecc4d"

[dependencies.ontodev_sqlrest]
git = "https://github.com/ontodev/sqlrest.rs"
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use indexmap::map::IndexMap;
use ontodev_valve::{
get_compiled_datatype_conditions, get_compiled_rule_conditions,
get_parsed_structure_conditions, valve_grammar::StartParser, valve_old, ColumnRule,
CompiledCondition, ParsedStructure, ValveCommand,
CompiledCondition, ParsedStructure, ValveCommandOld,
};
use serde::{Deserialize, Serialize};
use serde_json::Value as SerdeValue;
Expand Down Expand Up @@ -257,7 +257,7 @@ impl Config {
match valve_old(
&self.valve_path,
&self.connection,
&ValveCommand::Config,
&ValveCommandOld::Config,
verbose,
initial_load,
"table",
Expand Down
17 changes: 14 additions & 3 deletions src/init.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::config::{Config, DEFAULT_TOML};
use ontodev_valve::{valve_old, ValveCommand};
use ontodev_valve::{valve_old, Valve, ValveCommandOld};
use std::error;
use std::fs;
use std::fs::File;
Expand Down Expand Up @@ -116,6 +116,7 @@ fn create_datatype_tsv(path: &Path) -> Result<(), Box<dyn error::Error>> {

pub async fn init(config: &Config) -> Result<String, String> {
// Fail if the database already exists.
/*
let database = config.connection.to_owned();
let path = Path::new(&database);
if path.exists() {
Expand Down Expand Up @@ -194,9 +195,9 @@ pub async fn init(config: &Config) -> Result<String, String> {
// load tables into database
let verbose = false;
let command = if config.valve_create_only {
&ValveCommand::Create
&ValveCommandOld::Create
} else {
&ValveCommand::Load
&ValveCommandOld::Load
};
tracing::debug!("VALVE command {:?}", command);
tracing::debug!("VALVE initial_load {}", config.valve_initial_load);
Expand All @@ -220,6 +221,16 @@ pub async fn init(config: &Config) -> Result<String, String> {
}
tracing::info!("Loaded '{}' using '{}'", database, &config.valve_path);
*/

////////////////// New API example
let valve = Valve::build(&config.valve_path, "new_api.db", false, false)
.await
.unwrap();
valve.load_all_tables(true).await.unwrap();
println!("{:#?}", valve);

//////////////////////////////////

Ok(String::from("Initialized a Nanobot project"))
}

0 comments on commit 9003bed

Please sign in to comment.