Skip to content

Commit 84ff268

Browse files
committed
file writing
1 parent a896f9f commit 84ff268

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,21 @@ use quick_xml::Reader;
2121
use std::env;
2222
use std::path::Path;
2323

24+
pub mod sql_file;
25+
use sql_file::NodeFile;
26+
2427
fn main() {
28+
2529
let args: Vec<_> = env::args().collect();
2630

2731
let formated_arg = Arguments::parse_args(args);
2832

2933
let result = Reader::from_file(&Path::new(&formated_arg.input_file));
3034

35+
let nodes_table = NodeFile {..NodeFile::new(formated_arg.output_dir,formated_arg.maximum_rows_per_query)};
36+
37+
println!("One file is created:- {:?}",nodes_table.sql.rows);
38+
3139
// let mut count = 0;
3240
let mut buf = Vec::new();
3341
match result {

src/sql_file.rs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,53 @@
1+
use std::fs::File;
2+
use std::fs::OpenOptions;
3+
use std::io::prelude::*;
4+
5+
use std::path::PathBuf;
6+
17
pub struct SqlFile {
28
pub table_name: String,
39
pub rows: i32,
4-
pub sets: i32
5-
}
10+
pub sets: i32,
11+
pub maximum_rows_per_query: i32
12+
}
13+
14+
pub struct NodeFile {
15+
pub sql:SqlFile,
16+
pub file: File
17+
}
18+
19+
impl NodeFile {
20+
pub fn new(output_dir:String,maximum_rows_per_query:i32)->NodeFile{
21+
let file_name = String::from("nodes.sql");
22+
23+
let file_path = PathBuf::from(output_dir).join(file_name);
24+
25+
let mut file = OpenOptions::new()
26+
.write(true)
27+
.append(true)
28+
.create_new(true)
29+
.open(file_path)
30+
.unwrap();
31+
32+
if let Err(e) = writeln!(file, "DROP TABLE IF EXISTS nodes;") {
33+
drop(file);
34+
panic!("Could not to write to the file: {:?}",e);
35+
}
36+
37+
if let Err(e) = writeln!(file, "CREATE TABLE nodes ();") {
38+
drop(file);
39+
panic!("Could not to write to the file: {:?}",e);
40+
}
41+
42+
return NodeFile {
43+
sql: SqlFile {
44+
table_name: String::from("nodes"),
45+
rows: 0,
46+
sets: 0,
47+
maximum_rows_per_query:maximum_rows_per_query
48+
},
49+
file: file
50+
}
51+
}
52+
}
53+

0 commit comments

Comments
 (0)