PoC: Successful End-to-End integration of CHORUS core components
This commit is contained in:
@@ -17,20 +17,22 @@ pub enum GraphError {
|
||||
}
|
||||
|
||||
pub struct DoltGraph {
|
||||
repo_path: std::path::PathBuf,
|
||||
pub repo_path: std::path::PathBuf,
|
||||
}
|
||||
|
||||
impl DoltGraph {
|
||||
pub fn init(path: &Path) -> Result<Self, GraphError> {
|
||||
let status = Command::new("dolt")
|
||||
.arg("init")
|
||||
.current_dir(path)
|
||||
.status()?;
|
||||
if !status.success() {
|
||||
return Err(GraphError::CommandFailed(format!(
|
||||
"dolt init failed with status {:?}",
|
||||
status
|
||||
)));
|
||||
if !path.join(".dolt").exists() {
|
||||
let status = Command::new("dolt")
|
||||
.arg("init")
|
||||
.current_dir(path)
|
||||
.status()?;
|
||||
if !status.success() {
|
||||
return Err(GraphError::CommandFailed(format!(
|
||||
"dolt init failed with status {:?}",
|
||||
status
|
||||
)));
|
||||
}
|
||||
}
|
||||
Ok(Self {
|
||||
repo_path: path.to_path_buf(),
|
||||
@@ -44,7 +46,6 @@ impl DoltGraph {
|
||||
.output()?;
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
eprintln!("Dolt Command Failed: {:?} -> {}", args, stderr);
|
||||
return Err(GraphError::CommandFailed(stderr.to_string()));
|
||||
}
|
||||
Ok(())
|
||||
@@ -58,8 +59,12 @@ impl DoltGraph {
|
||||
|
||||
pub fn create_table(&self, table_name: &str, schema: &str) -> Result<(), GraphError> {
|
||||
let query = format!("CREATE TABLE {} ({})", table_name, schema);
|
||||
println!("Executing: dolt sql -q \"{}\"", query);
|
||||
self.run_cmd(&["sql", "-q", &query])?;
|
||||
if let Err(e) = self.run_cmd(&["sql", "-q", &query]) {
|
||||
if e.to_string().contains("already exists") {
|
||||
return Ok(());
|
||||
}
|
||||
return Err(e);
|
||||
}
|
||||
self.commit(&format!("Create table {}", table_name))?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -93,7 +98,6 @@ impl DoltGraph {
|
||||
columns.join(", "),
|
||||
values.join(", ")
|
||||
);
|
||||
println!("Executing: dolt sql -q \"{}\"", query);
|
||||
self.run_cmd(&["sql", "-q", &query])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user