use from table to remove into-db command (#6205)

* use from table to remove into-db command

* correct tests for db expressions
This commit is contained in:
Fernando Herrera 2022-08-01 21:27:55 +01:00 committed by GitHub
parent 2ac7a4d48d
commit 1f4791a191
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 73 additions and 87 deletions

View file

@ -32,17 +32,16 @@ impl Command for AliasDb {
vec![
Example {
description: "Creates an alias for a selected table",
example: r#"open db.mysql
| into db
example: r#"open db.sqlite
| from table table_1
| select a
| from table_1
| as t1
| describe"#,
result: Some(Value::Record {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {
@ -55,22 +54,20 @@ impl Command for AliasDb {
},
Example {
description: "Creates an alias for a derived table",
example: r#"open db.mysql
| into db
| select a
| from (
open db.mysql
| into db
example: r#"open db.sqlite
| from table (
open db.sqlite
| from table table_a
| select a b
| from table_a
)
| select a
| as t1
| describe"#,
result: Some(Value::Record {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {

View file

@ -38,10 +38,9 @@ impl Command for AndDb {
vec![
Example {
description: "Selects a column from a database with an AND clause",
example: r#"open db.mysql
| into db
example: r#"open db.sqlite
| from table table_1
| select a
| from table_1
| where ((field a) > 1)
| and ((field b) == 1)
| describe"#,
@ -49,7 +48,7 @@ impl Command for AndDb {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {
@ -62,10 +61,9 @@ impl Command for AndDb {
},
Example {
description: "Creates a AND clause combined with an expression AND",
example: r#"open db.mysql
| into db
example: r#"open db.sqlite
| from table table_1
| select a
| from table_1
| where ((field a) > 1 | and ((field a) < 10))
| and ((field b) == 1)
| describe"#,
@ -73,7 +71,7 @@ impl Command for AndDb {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {

View file

@ -28,7 +28,7 @@ impl Command for CollectDb {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Collect from a select query",
example: "open foo.db | into db | select a | from table_1 | collect",
example: "open foo.db | from table table_1 db | select a | collect",
result: None,
}]
}

View file

@ -28,7 +28,7 @@ impl Command for DescribeDb {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Describe SQLite database constructed query",
example: "open foo.db | into db | select col_1 | from table_1 | describe",
example: "open foo.db | from table table_1 | select col_1 | describe",
result: Some(Value::Record {
cols: vec!["connection".into(), "query".into()],
vals: vec![

View file

@ -15,7 +15,7 @@ pub struct FromDb;
impl Command for FromDb {
fn name(&self) -> &str {
"from"
"from table"
}
fn usage(&self) -> &str {
@ -35,7 +35,7 @@ impl Command for FromDb {
"Alias for the selected table",
Some('a'),
)
.input_type(Type::Custom("database".into()))
.input_type(Type::Any)
.output_type(Type::Custom("database".into()))
.category(Category::Custom("database".into()))
}
@ -47,12 +47,12 @@ impl Command for FromDb {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Selects a table from database",
example: "open db.mysql | into db | from table_a | describe",
example: "open db.sqlite | from table table_a | describe",
result: Some(Value::Record {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {

View file

@ -42,9 +42,8 @@ impl Command for GroupByDb {
vec![
Example {
description: "groups by column a and calculates the max",
example: r#"open db.mysql
| into db
| from table_a
example: r#"open db.sqlite
| from table table_a
| select (fn max a)
| group-by a
| describe"#,
@ -52,7 +51,7 @@ impl Command for GroupByDb {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {
@ -65,9 +64,8 @@ impl Command for GroupByDb {
},
Example {
description: "groups by column column a and counts records",
example: r#"open db.mysql
| into db
| from table_a
example: r#"open db.sqlite
| from table table_a
| select (fn count *)
| group-by a
| describe"#,
@ -75,7 +73,7 @@ impl Command for GroupByDb {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {

View file

@ -54,17 +54,16 @@ impl Command for JoinDb {
vec![
Example {
description: "joins two tables on col_b",
example: r#"open db.mysql
| into db
| select col_a
| from table_1 --as t1
example: r#"open db.sqlite
| from table table_1 --as t1
| join table_2 col_b --as t2
| select col_a
| describe"#,
result: Some(Value::Record {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {
@ -78,22 +77,20 @@ impl Command for JoinDb {
},
Example {
description: "joins a table with a derived table using aliases",
example: r#"open db.mysql
| into db
| select col_a
| from table_1 --as t1
example: r#"open db.sqlite
| from table table_1 --as t1
| join (
open db.mysql
| into db
open db.sqlite
| from table table_2
| select col_c
| from table_2
) ((field t1.col_a) == (field t2.col_c)) --as t2 --right
| select col_a
| describe"#,
result: Some(Value::Record {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {

View file

@ -40,9 +40,8 @@ impl Command for LimitDb {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Limits selection from table",
example: r#"open db.mysql
| into db
| from table_a
example: r#"open db.sqlite
| from table table_a
| select a
| limit 10
| describe"#,
@ -50,7 +49,7 @@ impl Command for LimitDb {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {

View file

@ -38,10 +38,9 @@ impl Command for OrDb {
vec![
Example {
description: "selects a column from a database with an OR clause",
example: r#"open db.mysql
| into db
example: r#"open db.sqlite
| from table table_1
| select a
| from table_1
| where ((field a) > 1)
| or ((field b) == 1)
| describe"#,
@ -49,7 +48,7 @@ impl Command for OrDb {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {
@ -62,10 +61,9 @@ impl Command for OrDb {
},
Example {
description: "Creates an OR clause in the column names and a column",
example: r#"open db.mysql
| into db
example: r#"open db.sqlite
| from table table_1
| select a
| from table_1
| where ((field a) > 1 | or ((field a) < 10))
| or ((field b) == 1)
| describe"#,
@ -73,7 +71,7 @@ impl Command for OrDb {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {

View file

@ -44,9 +44,8 @@ impl Command for OrderByDb {
vec![
Example {
description: "orders query by a column",
example: r#"open db.mysql
| into db
| from table_a
example: r#"open db.sqlite
| from table table_a
| select a
| order-by a
| describe"#,
@ -54,7 +53,7 @@ impl Command for OrderByDb {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {
@ -67,9 +66,8 @@ impl Command for OrderByDb {
},
Example {
description: "orders query by column a ascending and by column b",
example: r#"open db.mysql
| into db
| from table_a
example: r#"open db.sqlite
| from table table_a
| select a
| order-by a --ascending
| order-by b
@ -78,7 +76,7 @@ impl Command for OrderByDb {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {

View file

@ -16,7 +16,7 @@ impl Command for SchemaDb {
fn signature(&self) -> Signature {
Signature::build(self.name())
.input_type(Type::Custom("database".into()))
.input_type(Type::Any)
.output_type(Type::Any)
.category(Category::Custom("database".into()))
}
@ -28,7 +28,7 @@ impl Command for SchemaDb {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Show the schema of a SQLite database",
example: r#"open foo.db | into db | schema"#,
example: r#"open foo.db | schema"#,
result: None,
}]
}

View file

@ -40,12 +40,12 @@ impl Command for ProjectionDb {
vec![
Example {
description: "selects a column from a database",
example: "open db.mysql | into db | select a | describe",
example: "open db.sqlite | into db | select a | describe",
result: Some(Value::Record {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {
@ -58,16 +58,16 @@ impl Command for ProjectionDb {
},
Example {
description: "selects columns from a database using alias",
example: r#"open db.mysql
example: r#"open db.sqlite
| into db
| select (field a | as new_a) b c
| from table_1
| from table table_1
| describe"#,
result: Some(Value::Record {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {

View file

@ -18,6 +18,10 @@ impl Command for ToDataBase {
"Converts into an open db connection"
}
fn extra_usage(&self) -> &str {
"This function is used as type hint for parser, specially if the query is not started with 'from table'"
}
fn signature(&self) -> Signature {
Signature::build(self.name())
.input_type(Type::Any)
@ -32,7 +36,7 @@ impl Command for ToDataBase {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Converts an open file into a db object",
example: "open db.mysql | into db",
example: "open db.sqlite | into db",
result: None,
}]
}

View file

@ -37,17 +37,16 @@ impl Command for WhereDb {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "selects a column from a database with a where clause",
example: r#"open db.mysql
| into db
example: r#"open db.sqlite
| from table table_1
| select a
| from table_1
| where ((field a) > 1)
| describe"#,
result: Some(Value::Record {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {

View file

@ -68,16 +68,15 @@ impl Command for FunctionExpr {
},
Example {
description: "orders query by a column",
example: r#"open db.mysql
| into db
example: r#"open db.sqlite
| from table table_a
| select (fn lead col_a)
| from table_a
| describe"#,
result: Some(Value::Record {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {

View file

@ -69,16 +69,15 @@ impl Command for OverExpr {
},
Example {
description: "orders query by a column",
example: r#"open db.mysql
| into db
example: r#"open db.sqlite
| from table table_a
| select (fn lead col_a | over col_b)
| from table_a
| describe"#,
result: Some(Value::Record {
cols: vec!["connection".into(), "query".into()],
vals: vec![
Value::String {
val: "db.mysql".into(),
val: "db.sqlite".into(),
span: Span::test_data(),
},
Value::String {