mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-18 16:30:44 +00:00
Added support for object selects
This commit is contained in:
@@ -92,6 +92,14 @@ func getFieldValue(field parsers.SelectItem, row RowType) interface{} {
|
||||
return arrayValue
|
||||
}
|
||||
|
||||
if field.Type == parsers.SelectItemTypeObject {
|
||||
objectValue := make(map[string]interface{})
|
||||
for _, selectItem := range field.SelectItems {
|
||||
objectValue[selectItem.Alias] = getFieldValue(selectItem, row)
|
||||
}
|
||||
return objectValue
|
||||
}
|
||||
|
||||
value := row
|
||||
for _, pathSegment := range field.Path[1:] {
|
||||
if nestedValue, ok := value.(map[string]interface{}); ok {
|
||||
|
||||
@@ -86,6 +86,30 @@ func Test_Execute(t *testing.T) {
|
||||
)
|
||||
})
|
||||
|
||||
t.Run("Should parse SELECT object", func(t *testing.T) {
|
||||
testQueryExecute(
|
||||
t,
|
||||
parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{
|
||||
Alias: "obj",
|
||||
Type: parsers.SelectItemTypeObject,
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Alias: "id", Path: []string{"c", "id"}},
|
||||
{Alias: "_pk", Path: []string{"c", "pk"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
map[string]interface{}{"obj": map[string]interface{}{"id": "12345", "_pk": 123}},
|
||||
map[string]interface{}{"obj": map[string]interface{}{"id": "67890", "_pk": 456}},
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
t.Run("Should execute SELECT with single WHERE condition", func(t *testing.T) {
|
||||
testQueryExecute(
|
||||
t,
|
||||
|
||||
Reference in New Issue
Block a user