mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-19 00:40:47 +00:00
Support parameter in bracket #8
This commit is contained in:
@@ -317,6 +317,10 @@ func (r rowContext) applyProjection(selectItems []parsers.SelectItem) RowType {
|
||||
} else {
|
||||
destinationName = fmt.Sprintf("$%d", index+1)
|
||||
}
|
||||
|
||||
if destinationName[0] == '@' {
|
||||
destinationName = r.parameters[destinationName].(string)
|
||||
}
|
||||
}
|
||||
|
||||
row[destinationName] = r.resolveSelectItem(selectItem)
|
||||
@@ -572,6 +576,9 @@ func (r rowContext) selectItem_SelectItemTypeField(selectItem parsers.SelectItem
|
||||
|
||||
if len(selectItem.Path) > 1 {
|
||||
for _, pathSegment := range selectItem.Path[1:] {
|
||||
if pathSegment[0] == '@' {
|
||||
pathSegment = r.parameters[pathSegment].(string)
|
||||
}
|
||||
|
||||
switch nestedValue := value.(type) {
|
||||
case map[string]interface{}:
|
||||
|
||||
@@ -35,6 +35,29 @@ func Test_Execute_Select(t *testing.T) {
|
||||
)
|
||||
})
|
||||
|
||||
t.Run("Should execute SELECT with query parameters as accessor", func(t *testing.T) {
|
||||
testQueryExecute(
|
||||
t,
|
||||
parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c", "id"}},
|
||||
{Path: []string{"c", "@param"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Parameters: map[string]interface{}{
|
||||
"@param": "pk",
|
||||
},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
map[string]interface{}{"id": "12345", "pk": 123},
|
||||
map[string]interface{}{"id": "67890", "pk": 456},
|
||||
map[string]interface{}{"id": "456", "pk": 456},
|
||||
map[string]interface{}{"id": "123", "pk": 456},
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
t.Run("Should execute SELECT DISTINCT", func(t *testing.T) {
|
||||
testQueryExecute(
|
||||
t,
|
||||
|
||||
Reference in New Issue
Block a user