mirror of
https://github.com/pikami/cosmium.git
synced 2024-11-28 16:37:18 +00:00
105 lines
2.1 KiB
Go
105 lines
2.1 KiB
Go
package nosql_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/pikami/cosmium/parsers"
|
|
)
|
|
|
|
func Test_Parse_Select(t *testing.T) {
|
|
|
|
t.Run("Should parse simple SELECT", func(t *testing.T) {
|
|
testQueryParse(
|
|
t,
|
|
`SELECT c.id, c["pk"] FROM c`,
|
|
parsers.SelectStmt{
|
|
SelectItems: []parsers.SelectItem{
|
|
{Path: []string{"c", "id"}},
|
|
{Path: []string{"c", "pk"}},
|
|
},
|
|
Table: parsers.Table{Value: "c"},
|
|
},
|
|
)
|
|
})
|
|
|
|
t.Run("Should parse SELECT TOP", func(t *testing.T) {
|
|
testQueryParse(
|
|
t,
|
|
`SELECT TOP 1 c.id FROM c`,
|
|
parsers.SelectStmt{
|
|
SelectItems: []parsers.SelectItem{
|
|
{Path: []string{"c", "id"}},
|
|
},
|
|
Table: parsers.Table{Value: "c"},
|
|
Count: 1,
|
|
},
|
|
)
|
|
})
|
|
|
|
t.Run("Should parse SELECT VALUE", func(t *testing.T) {
|
|
testQueryParse(
|
|
t,
|
|
`SELECT VALUE c.id FROM c`,
|
|
parsers.SelectStmt{
|
|
SelectItems: []parsers.SelectItem{
|
|
{Path: []string{"c", "id"}, IsTopLevel: true},
|
|
},
|
|
Table: parsers.Table{Value: "c"},
|
|
},
|
|
)
|
|
})
|
|
|
|
t.Run("Should parse SELECT *", func(t *testing.T) {
|
|
testQueryParse(
|
|
t,
|
|
`SELECT * FROM c`,
|
|
parsers.SelectStmt{
|
|
SelectItems: []parsers.SelectItem{
|
|
{Path: []string{"c"}, IsTopLevel: true},
|
|
},
|
|
Table: parsers.Table{Value: "c"},
|
|
},
|
|
)
|
|
})
|
|
|
|
t.Run("Should parse SELECT array", func(t *testing.T) {
|
|
testQueryParse(
|
|
t,
|
|
`SELECT [c.id, c.pk] as arr FROM c`,
|
|
parsers.SelectStmt{
|
|
SelectItems: []parsers.SelectItem{
|
|
{
|
|
Alias: "arr",
|
|
Type: parsers.SelectItemTypeArray,
|
|
SelectItems: []parsers.SelectItem{
|
|
{Path: []string{"c", "id"}},
|
|
{Path: []string{"c", "pk"}},
|
|
},
|
|
},
|
|
},
|
|
Table: parsers.Table{Value: "c"},
|
|
},
|
|
)
|
|
})
|
|
|
|
t.Run("Should parse SELECT object", func(t *testing.T) {
|
|
testQueryParse(
|
|
t,
|
|
`SELECT { id: c.id, _pk: c.pk } AS obj FROM c`,
|
|
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"},
|
|
},
|
|
)
|
|
})
|
|
}
|