Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
akevinge committed Mar 21, 2022
0 parents commit 35c31c7
Show file tree
Hide file tree
Showing 21 changed files with 1,187 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/target
3 changes: 3 additions & 0 deletions tesql-cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tesql_out
tesql_sql
tesql_json
247 changes: 247 additions & 0 deletions tesql-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tesql-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "tesql-cli"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tesql = { path = "../tesql", version = "0.1.0" }
structopt = { version = "0.3", default-features = false }
3 changes: 3 additions & 0 deletions tesql-cli/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn print_error(msg: impl Into<String>) {
eprintln!("[tesql error]: {}", msg.into());
}
55 changes: 55 additions & 0 deletions tesql-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use structopt::StructOpt;
use tesql;

mod error;
use crate::error::print_error;

#[derive(StructOpt, Debug)]
struct Cli {
#[structopt(name = "in_path", long = "in", short = "i", default_value = ".")]
in_path: String,
#[structopt(
name = "json_out_path",
long = "json-out",
default_value = "./tesql_out/out.json"
)]
json_out_path: String,
#[structopt(
name = "sql_out_path",
long = "sql-out",
default_value = "./tesql_out/out.sql"
)]
sql_out_path: String,
#[structopt(
name = "json_out_dir",
long = "json-dir",
default_value = "./tesql_json"
)]
json_dir_path: String,
#[structopt(name = "sql_out_dir", long = "sql-dir", default_value = "./tesql_sql")]
sql_dir_path: String,
#[structopt(name = "split_files", long = "split", short = "sp")]
split_files: bool,
}

#[cfg(windows)]
fn main() {
let args = Cli::from_args();
let gen = tesql::gen_inserts_from_file(
args.in_path.as_str(),
tesql::GenInsertOptions {
split_data_files: args.split_files,
json_out_dir_path: args.json_dir_path.as_str(),
json_out_file_path: args.json_out_path.as_str(),
sql_out_dir_path: args.sql_dir_path.as_str(),
sql_out_file_path: args.sql_out_path.as_str(),
},
);

match gen {
Ok(_) => {
println!("[tesql]: successfully generated sql and json files");
}
Err(err) => print_error(format!("{:?}", err)),
}
}
51 changes: 51 additions & 0 deletions tesql-cli/testdata/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"data": {
"user": {
"columns": [
{ "name": "id", "type": "uuid" },
{ "name": "username", "type": "text" },
{ "name": "is_student", "type": "text" },
{ "name": "friends_ids", "type": "array" },
{ "name": "nested_arrays", "type": "array" }
],
"inserts": [
{
"id": "0101111111111",
"username": "Bob",
"is_student": true,
"friends_ids": ["hello", "world", "hi!"],
"nested_arrays": [
["hey", "man"],
["the", "world", "goes", "round"]
]
},
{
"id": "2",
"username": "Bob2",
"is_student": false,
"friends_ids": ["hi", "mom"],
"nested_arrays": [["hello", "there"], ["hello", "world"], ["hi!"]]
}
]
},
"user1": {
"columns": [
{ "name": "id", "type": "uuid" },
{ "name": "username", "type": "text" },
{ "name": "bool", "type": "text" }
],
"inserts": [
{
"id": "0101",
"username": "Bob",
"bool": true
},
{
"id": "2",
"username": "Bob2",
"bool": false
}
]
}
}
}
2 changes: 2 additions & 0 deletions tesql/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/testgen*
/out*
Loading

0 comments on commit 35c31c7

Please sign in to comment.