Added support for TOP statement

This commit is contained in:
Pijus Kamandulis
2024-02-14 21:03:49 +02:00
parent 62ac9ddf6b
commit b13434eeff
6 changed files with 477 additions and 316 deletions

View File

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

View File

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