refactor: make public the code that needs to be exposed, remove unused code
This commit is contained in:
53
src/lib.rs
53
src/lib.rs
@@ -1,3 +1,50 @@
|
||||
mod mappings;
|
||||
mod schemas;
|
||||
mod query_builders;
|
||||
use crate::databases::{connect, disconnect, run_command};
|
||||
use crate::query_builders::table_sql_serializer::TableSqlSerializer;
|
||||
use crate::schemas::reader::SchemaParsingFacade;
|
||||
|
||||
pub mod mappings;
|
||||
pub mod schemas;
|
||||
pub mod query_builders;
|
||||
mod databases;
|
||||
|
||||
pub struct DbBuilderFacade {}
|
||||
|
||||
impl DbBuilderFacade {
|
||||
pub fn build(self, json_schema_path: String, db_connection: String) -> Result<(), String> {
|
||||
let schema_parsing_facade = SchemaParsingFacade{};
|
||||
let tables = schema_parsing_facade.parse(json_schema_path);
|
||||
|
||||
let table_serializer = TableSqlSerializer{};
|
||||
|
||||
let mut sql_tables = String::new();
|
||||
|
||||
for table in tables {
|
||||
sql_tables += &table_serializer.serialize(table);
|
||||
}
|
||||
|
||||
let connection_result = connect(db_connection);
|
||||
|
||||
if let Ok(connection) = connection_result {
|
||||
run_command(&connection, sql_tables).expect("Failed to execute query");
|
||||
disconnect(connection).expect("Failed to disconnect from sqlite");
|
||||
Ok(())
|
||||
} else {
|
||||
Err("Failed to connect to the server".to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_db_builder() {
|
||||
let facade = DbBuilderFacade{};
|
||||
|
||||
match facade.build("./example.json".to_string(), "test_db".to_string()) {
|
||||
Ok(_) => {assert!(true)},
|
||||
Err(message) => {assert!(false, "{}", message)}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user