Skip to content

Commit e80e829

Browse files
authored
Merge pull request #3 from rustbase/rustbase-v0.1.4-beta
feat: rustbase v0.1.4-beta
2 parents 15b2ed1 + 4415c5b commit e80e829

6 files changed

Lines changed: 123 additions & 116 deletions

File tree

.github/workflows/release.yml

Lines changed: 0 additions & 63 deletions
This file was deleted.

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
[package]
22
name = "rustbase-cli"
3-
version = "0.1.1-beta"
3+
version = "0.1.2-beta"
44
edition = "2021"
55
build = "./src/build.rs"
66

7-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8-
97
[dependencies]
108
tonic = "0.8.0"
119
prost = "0.11.0"

scripts/release.sh

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,75 @@
1-
# 86_64 Linux
2-
echo "Building linux 64-bit release..."
3-
rustup target add x86_64-unknown-linux-gnu
4-
cargo build --target x86_64-unknown-linux-gnu --release
1+
#!/bin/bash
52

6-
# x86_64 Windows
7-
echo "Building windows 64-bit release..."
8-
rustup target add x86_64-pc-windows-gnu
9-
cargo build --target x86_64-pc-windows-gnu --release
3+
only_target=$1
4+
5+
case "$only_target" in
6+
*-linux*)
7+
echo "Building only for Linux"
8+
only_target="linux"
9+
;;
10+
11+
*-windows*)
12+
echo "Building only for Windows"
13+
only_target="windows"
14+
;;
15+
16+
*-macos*)
17+
echo "Building only for Mac OS"
18+
only_target="macos"
19+
;;
20+
21+
*)
22+
echo "Building for all targets"
23+
only_target=""
24+
;;
25+
esac
26+
27+
targets=("x86_64-unknown-linux-gnu" "i686-unknown-linux-gnu" "x86_64-pc-windows-gnu" "i686-pc-windows-gnu")
28+
short_targets=("linux-x64" "linux-x86" "windows-x64" "windows-x86")
29+
30+
for t in "${targets[@]}"; do
31+
if [ "$only_target" != "" ] && [[ "$t" != *"$only_target"* ]]; then
32+
continue
33+
fi
34+
35+
echo "[+] Building for $t"
36+
# ignore informational messages
37+
rustup target add $t > /dev/null 2>&1
38+
39+
cargo build -q --target $t --release
40+
41+
echo "[Done] Building for $t"
42+
done
1043

11-
mkdir -p release
1244
bin_name=rustbase-cli
1345

14-
# 86_64 Linux
15-
cp target/x86_64-unknown-linux-gnu/release/$bin_name release/
46+
for t in "${!targets[@]}"; do
47+
target=${targets[$t]}
48+
short=${short_targets[$t]}
49+
50+
if [ "$only_target" != "" ] && [[ "$target" != *"$only_target"* ]]; then
51+
continue
52+
fi
53+
1654

17-
zip -jq release/$bin_name.zip release/$bin_name
55+
echo "[+] Packaging for $short"
1856

19-
mv release/$bin_name.zip release/$bin_name-linux-x64.zip
57+
if [[ "$short" == *"windows"* ]]; then
58+
target_ext=.exe
59+
else
60+
target_ext=""
61+
fi
2062

21-
rm -rf release/$bin_name
63+
filename=$bin_name$target_ext
2264

23-
# x86_64 Windows
24-
cp target/x86_64-pc-windows-gnu/release/$bin_name.exe release/
65+
mkdir -p release
66+
cp target/$target/release/$filename release/
67+
zip -jq release/$bin_name.zip release/$filename
68+
mv release/$bin_name.zip release/$bin_name-$short.zip
2569

26-
zip -jq release/$bin_name.zip release/$bin_name.exe
70+
rm -rf release/$filename
2771

28-
mv release/$bin_name.zip release/$bin_name-windows-x64.zip
72+
echo "[Done] Packaged for $short"
73+
done
2974

30-
rm -rf release/$bin_name.exe
75+
echo "[+] Done"

src/engine/mod.rs

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ pub enum Request {
1515
Query(String),
1616
}
1717

18-
pub enum Response {
19-
Query(QueryResult),
20-
}
21-
22-
type Result<T> = std::result::Result<T, Error>;
23-
2418
#[derive(Debug)]
2519
pub struct Error {
2620
status: tonic::Status,
@@ -62,30 +56,45 @@ impl Rustbase {
6256
database: self.database.clone(),
6357
};
6458

65-
let response = self.client.query(query).await.unwrap();
66-
let response = response.into_inner();
59+
match self.client.query(query.clone()).await {
60+
Ok(response) => {
61+
let response = response.into_inner();
6762

68-
match parse_i32_to_enum(response.result_type) {
69-
QueryResultType::Ok => {
70-
if let Some(result) = response.bson {
71-
println!("{}", bson::from_slice::<bson::Bson>(&result).unwrap());
72-
}
73-
}
74-
QueryResultType::Error => {
75-
println!(
76-
"{} {}",
77-
"[Error]".red().bold(),
78-
response.error_message.unwrap()
79-
);
80-
}
81-
QueryResultType::NotFound => {
82-
print!("{} Not found: ", "[Error]".red().bold());
83-
if let Some(msg) = response.error_message {
84-
println!("{}", msg);
63+
match parse_i32_to_enum(response.result_type) {
64+
QueryResultType::Ok => {
65+
if let Some(result) = response.bson {
66+
let doc = bson::from_slice::<bson::Document>(&result).unwrap();
67+
68+
if let Some(value) = doc.get("_l") {
69+
println!("{}", value);
70+
} else {
71+
println!("{}", doc);
72+
}
73+
} else {
74+
println!("{} OK", "[Success]".green());
75+
}
76+
}
77+
QueryResultType::Error => {
78+
println!(
79+
"{} {}",
80+
"[Error]".red().bold(),
81+
response.error_message.unwrap()
82+
);
83+
}
84+
QueryResultType::NotFound => {
85+
print!("{} Not found: ", "[Error]".red().bold());
86+
if let Some(msg) = response.error_message {
87+
println!("{}", msg);
88+
}
89+
}
90+
QueryResultType::SyntaxError => {
91+
println!("[Error] Syntax: \n{}", response.error_message.unwrap());
92+
}
8593
}
8694
}
87-
QueryResultType::SyntaxError => {
88-
println!("[Error] Syntax: \n{}", response.error_message.unwrap());
95+
96+
Err(e) => {
97+
eprintln!("Error: {}", e);
8998
}
9099
}
91100
}

src/main.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ async fn main() -> Result<()> {
4848

4949
let mut rl = Editor::<()>::new()?;
5050

51-
rl.load_history("repl.history").ok();
51+
rl.load_history(
52+
utils::get_current_path()
53+
.join("repl.history")
54+
.to_str()
55+
.unwrap(),
56+
)
57+
.ok();
5258

5359
let mut database = rl.readline("Database: ")?;
5460

@@ -76,13 +82,25 @@ async fn main() -> Result<()> {
7682
}
7783
Err(ReadlineError::Interrupted) => {
7884
println!("bye");
79-
rl.save_history("repl.history").ok();
85+
rl.save_history(
86+
utils::get_current_path()
87+
.join("repl.history")
88+
.to_str()
89+
.unwrap(),
90+
)
91+
.ok();
8092

8193
break;
8294
}
8395
Err(ReadlineError::Eof) => {
8496
println!("bye");
85-
rl.save_history("repl.history").ok();
97+
rl.save_history(
98+
utils::get_current_path()
99+
.join("repl.history")
100+
.to_str()
101+
.unwrap(),
102+
)
103+
.ok();
86104
break;
87105
}
88106
Err(err) => {

0 commit comments

Comments
 (0)