mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-18 16:30:44 +00:00
Added support for TOP statement
This commit is contained in:
@@ -18,6 +18,17 @@ func Execute(query parsers.SelectStmt, data []RowType) []RowType {
|
||||
}
|
||||
}
|
||||
|
||||
// Apply result limit
|
||||
if query.Count > 0 {
|
||||
count := func() int {
|
||||
if len(result) < query.Count {
|
||||
return len(result)
|
||||
}
|
||||
return query.Count
|
||||
}()
|
||||
result = result[:count]
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,24 @@ func Test_Execute(t *testing.T) {
|
||||
)
|
||||
})
|
||||
|
||||
t.Run("Should execute SELECT TOP", func(t *testing.T) {
|
||||
testQueryExecute(
|
||||
t,
|
||||
parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c", "id"}},
|
||||
{Path: []string{"c", "pk"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Count: 1,
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
map[string]interface{}{"id": "12345", "pk": 123},
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
t.Run("Should execute SELECT VALUE", func(t *testing.T) {
|
||||
testQueryExecute(
|
||||
t,
|
||||
|
||||
Reference in New Issue
Block a user