Skip to content

Commit 4fe2b6f

Browse files
loloxwgKKould
andauthored
fix(main): Add condition to skip empty user input. import data before looping (#52)
* fix(main): Add condition to skip empty user input. import data before loop * fix(bug): thiserror * fix: cannot be compiled on linux --------- Co-authored-by: Kould <2435992353@qq.com>
1 parent 7f5d68f commit 4fe2b6f

File tree

4 files changed

+26
-39
lines changed

4 files changed

+26
-39
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,28 @@
1-
name: CI
1+
name: Rust
22

33
on:
44
push:
5+
branches: [main]
56
pull_request:
7+
branches: [main]
68

79
env:
810
CARGO_TERM_COLOR: always
911

1012
jobs:
11-
fmt:
12-
runs-on: ubuntu-latest
13-
steps:
14-
- uses: actions/checkout@v3
15-
- uses: actions-rs/toolchain@v1
16-
with:
17-
profile: minimal
18-
components: rustfmt, clippy
19-
- uses: actions/cache@v3
20-
with:
21-
path: |
22-
~/.cargo/registry/index/
23-
~/.cargo/registry/cache/
24-
~/.cargo/git/db/
25-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
26-
- name: Check code format
27-
run: cargo fmt --all -- --check
13+
build:
2814

29-
30-
31-
test:
3215
runs-on: ubuntu-latest
16+
3317
steps:
34-
- uses: actions/checkout@v3
35-
- uses: actions-rs/toolchain@v1
18+
- uses: actions/checkout@v2
19+
- name: Setup Rust
20+
uses: actions-rs/toolchain@v1
3621
with:
37-
profile: minimal
38-
- uses: actions/cache@v3
22+
toolchain: nightly-2023-04-07
23+
override: true
24+
25+
- name: Run tests
26+
uses: actions-rs/cargo@v1
3927
with:
40-
path: |
41-
~/.cargo/registry/index/
42-
~/.cargo/registry/cache/
43-
~/.cargo/git/db/
44-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
45-
- uses: taiki-e/install-action@nextest
46-
- name: Test
47-
run: cargo nextest run --no-fail-fast --all-features
28+
command: test

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ sqlparser = "0.34.0"
1313
thiserror = "1"
1414
parking_lot = "0.12.1"
1515
itertools = "0.10"
16-
sqllogictest = "0.11.1"
1716
tracing = "0.1.37"
1817
chrono = "0.4.26"
1918
tokio = { version = "1.28.2", features = ["full"] }

src/db.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ impl Database {
3636
pub async fn run(&self, sql: &str) -> Result<Vec<Tuple>, DatabaseError> {
3737
// parse
3838
let stmts = parse_sql(sql)?;
39+
if stmts.is_empty() {
40+
return Ok(vec![]);
41+
}
42+
3943
// bind
4044
let catalog = self.storage.get_catalog();
4145

@@ -121,7 +125,6 @@ pub enum DatabaseError {
121125
StorageError(
122126
#[source]
123127
#[from]
124-
#[backtrace]
125128
StorageError,
126129
),
127130
#[error("mapping error: {0}")]

src/main.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,26 @@ async fn main() -> Result<(), Box<dyn Error>> {
4141

4242
async fn server_run() -> Result<(), Box<dyn Error>> {
4343
let db = Database::new_on_mem();
44+
let _ = db.run("create table t1 (a int, b int)").await?;
45+
let _ = db.run("create table t2 (c int, d int null)").await?;
46+
let _ = db.run("insert into t1 (a, b) values (1, 1), (5, 3), (5, 2)").await?;
47+
let _ = db.run("insert into t2 (d, c) values (2, 1), (3, 1), (null, 6)").await?;
48+
4449
loop {
4550
println!("> type👇 plz");
4651
let mut input = String::new();
4752
io::stdin().read_line(&mut input)?;
48-
49-
if input.to_lowercase()[..4].eq("quit") {
53+
if input.to_lowercase().eq("quit\n") {
5054
println!("{}", BLOOM);
5155
break
5256
}
5357

5458
match db.run(&input).await {
5559
Ok(tuples) => {
5660
if tuples.is_empty() {
57-
println!("\nEmpty!");
61+
println!("\nEmpty\n");
5862
} else {
59-
println!("\n{}", create_table(&tuples));
63+
println!("\n{}\n", create_table(&tuples));
6064
}
6165
}
6266
Err(err) => {

0 commit comments

Comments
 (0)