Skip to content

Commit c1d3393

Browse files
committed
0.0.0
1 parent 4a42b23 commit c1d3393

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ Cargo.lock
88

99
# These are backup files generated by rustfmt
1010
**/*.rs.bk
11+
12+
13+
# Added by cargo
14+
15+
/target

Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "multisql-cli"
3+
version = "0.0.0"
4+
authors = ["Kyran Gostelow <kyran@gostelow.me>"]
5+
edition = "2021"
6+
7+
[dependencies]
8+
dialoguer = "^0"
9+
indicatif = "^0"
10+
multisql = "0.0.2"
11+
lazy_static = "^1"
12+
console = "^0"

rustfmt.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hard_tabs = true

src/main.rs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
use {
2+
console::Style,
3+
dialoguer::{theme::ColorfulTheme, Confirm, Editor, Input, Select},
4+
indicatif::{ProgressBar, ProgressStyle},
5+
lazy_static::lazy_static,
6+
multisql::{CSVStorage, Glue, SledStorage, Storage},
7+
};
8+
9+
lazy_static! {
10+
pub(crate) static ref PROGRESS_STYLE: ProgressStyle = ProgressStyle::default_spinner()
11+
.template("{spinner:.magenta} {elapsed:3.red} {msg:.green}")
12+
.tick_chars("|/—\\*");
13+
}
14+
15+
fn main() {
16+
let mut glue = Glue::new_multi(vec![]);
17+
while prompt(&mut glue) {}
18+
}
19+
20+
const PROMPT_ACTION: [&str; 2] = ["Connect", "Query"];
21+
const PROMPT_KIND: [&str; 2] = ["Sled", "CSV"];
22+
const QUERY_KIND: [&str; 3] = ["Small", "Big", "File"];
23+
24+
fn prompt(glue: &mut Glue) -> bool {
25+
let mut input_theme = ColorfulTheme::default();
26+
input_theme.active_item_prefix = Style::new().green().apply_to(String::from("•-"));
27+
28+
match Select::with_theme(&input_theme)
29+
.items(&PROMPT_ACTION)
30+
.default(0)
31+
.interact()
32+
.unwrap()
33+
{
34+
0 => {
35+
let name = Input::with_theme(&input_theme)
36+
.with_prompt("Name")
37+
.interact()
38+
.unwrap();
39+
let new_storage = match Select::with_theme(&input_theme)
40+
.items(&PROMPT_KIND)
41+
.default(0)
42+
.interact()
43+
.unwrap()
44+
{
45+
0 => {
46+
let path: String = Input::with_theme(&input_theme)
47+
.with_prompt("Path")
48+
.interact()
49+
.unwrap();
50+
Storage::new_sled(SledStorage::new(&path).unwrap())
51+
}
52+
1 => {
53+
let path: String = Input::with_theme(&input_theme)
54+
.with_prompt("Path")
55+
.interact()
56+
.unwrap();
57+
Storage::new_csv(CSVStorage::new(&path).unwrap())
58+
}
59+
_ => unreachable!(),
60+
};
61+
glue.extend(vec![Glue::new(name, new_storage)]);
62+
}
63+
1 => {
64+
let query = match Select::with_theme(&input_theme)
65+
.items(&QUERY_KIND)
66+
.default(0)
67+
.interact()
68+
.unwrap()
69+
{
70+
0 => Input::with_theme(&input_theme)
71+
.with_prompt("Query")
72+
.interact()
73+
.unwrap(),
74+
1 => {
75+
let text = Editor::new()
76+
.extension("sql")
77+
.require_save(false)
78+
.edit("")
79+
.unwrap()
80+
.unwrap();
81+
println!("{}", text);
82+
Confirm::with_theme(&input_theme)
83+
.with_prompt("Run")
84+
.default(true)
85+
.interact()
86+
.unwrap();
87+
text
88+
}
89+
2 => unimplemented!(),
90+
_ => unreachable!(),
91+
};
92+
93+
let progress = ProgressBar::new_spinner()
94+
.with_message(format!("Running Query"))
95+
.with_style(PROGRESS_STYLE.clone());
96+
progress.enable_steady_tick(200);
97+
98+
glue.execute(&query).unwrap();
99+
100+
progress.finish();
101+
}
102+
_ => unreachable!(),
103+
}
104+
105+
true
106+
}

test.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a,b

0 commit comments

Comments
 (0)