-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: the
convert
command converts trace files to sqlite database
- Loading branch information
Showing
6 changed files
with
178 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use crate::{ | ||
compiler::ConstraintSet, | ||
pretty::{Base, Pretty}, | ||
utils::purify, | ||
}; | ||
use anyhow::*; | ||
use itertools::Itertools; | ||
use rusqlite::Connection; | ||
|
||
pub(crate) fn to_sqlite(cs: &ConstraintSet, exclude: &[String], filename: &str) -> Result<()> { | ||
let db = Connection::open(filename)?; | ||
|
||
for module in cs.columns.modules() { | ||
if exclude.contains(&module) { | ||
continue; | ||
} | ||
println!("Exporting {}", &module); | ||
let column_names = cs | ||
.columns | ||
.iter_module(&module) | ||
.map(|c| cs.handle(&c.0)) | ||
.collect::<Vec<_>>(); | ||
let sql_column_headers = column_names | ||
.iter() | ||
.map(|h| format!("{}_ TEXT NOT NULL", h.name)) | ||
.join(", "); | ||
let sql_column_names = column_names | ||
.iter() | ||
.map(|h| format!("{}_ ", h.name)) | ||
.join(", "); | ||
db.execute(&format!("DROP TABLE IF EXISTS {}_", purify(&module)), ())?; | ||
db.execute( | ||
&format!("CREATE TABLE {}_ ({})", purify(&module), sql_column_headers), | ||
(), | ||
)?; | ||
let max_i = cs.iter_len(&module); | ||
if max_i == 0 { | ||
continue; | ||
} | ||
|
||
for i in 0..max_i { | ||
let vals = cs | ||
.columns | ||
.iter_module(&module) | ||
.map(|col| { | ||
format!( | ||
"\"{}\"", | ||
cs.columns | ||
.get(&col.0, i.try_into().unwrap(), false) | ||
.unwrap_or_default() | ||
.pretty_with_base(Base::Hex) | ||
) | ||
}) | ||
.join(", "); | ||
db.execute( | ||
&format!( | ||
"INSERT INTO {}_ ({}) VALUES ({})", | ||
purify(&module), | ||
&sql_column_names, | ||
&vals | ||
), | ||
(), | ||
)?; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters