mirror of https://github.com/pikami/cosmium.git
Added support for 'SELECT *'
This commit is contained in:
parent
a36b578a9b
commit
f183f308fb
File diff suppressed because it is too large
Load Diff
|
@ -112,7 +112,13 @@ TopClause <- Top ws count:Integer {
|
|||
return count, nil
|
||||
}
|
||||
|
||||
Selection <- SelectValueSpec / ColumnList
|
||||
Selection <- SelectValueSpec / ColumnList /SelectAsterisk
|
||||
|
||||
SelectAsterisk <- "*" {
|
||||
selectItem, _ := makeSelectItem("c", make([]interface{}, 0), parsers.SelectItemTypeField)
|
||||
selectItem.IsTopLevel = true
|
||||
return makeColumnList(selectItem, make([]interface{}, 0))
|
||||
}
|
||||
|
||||
ColumnList <- column:SelectItem other_columns:(ws "," ws coll:SelectItem {return coll, nil })* {
|
||||
return makeColumnList(column, other_columns)
|
||||
|
|
|
@ -79,6 +79,19 @@ func Test_Parse(t *testing.T) {
|
|||
)
|
||||
})
|
||||
|
||||
t.Run("Should parse SELECT *", func(t *testing.T) {
|
||||
testQueryParse(
|
||||
t,
|
||||
`SELECT * FROM c`,
|
||||
parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c"}, IsTopLevel: true},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
t.Run("Should parse SELECT array", func(t *testing.T) {
|
||||
testQueryParse(
|
||||
t,
|
||||
|
|
|
@ -112,11 +112,13 @@ func getFieldValue(field parsers.SelectItem, row RowType) interface{} {
|
|||
}
|
||||
|
||||
value := row
|
||||
for _, pathSegment := range field.Path[1:] {
|
||||
if nestedValue, ok := value.(map[string]interface{}); ok {
|
||||
value = nestedValue[pathSegment]
|
||||
} else {
|
||||
return nil
|
||||
if len(field.Path) > 1 {
|
||||
for _, pathSegment := range field.Path[1:] {
|
||||
if nestedValue, ok := value.(map[string]interface{}); ok {
|
||||
value = nestedValue[pathSegment]
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return value
|
||||
|
|
|
@ -86,6 +86,20 @@ func Test_Execute(t *testing.T) {
|
|||
)
|
||||
})
|
||||
|
||||
t.Run("Should execute SELECT *", func(t *testing.T) {
|
||||
testQueryExecute(
|
||||
t,
|
||||
parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c"}, IsTopLevel: true},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
},
|
||||
mockData,
|
||||
mockData,
|
||||
)
|
||||
})
|
||||
|
||||
t.Run("Should execute SELECT array", func(t *testing.T) {
|
||||
testQueryExecute(
|
||||
t,
|
||||
|
|
Loading…
Reference in New Issue