Added support for 'SELECT *'

This commit is contained in:
Pijus Kamandulis
2024-02-15 23:11:46 +02:00
parent a36b578a9b
commit f183f308fb
5 changed files with 347 additions and 282 deletions

View File

@@ -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

View File

@@ -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,