mirror of
https://github.com/pikami/cosmium.git
synced 2024-11-25 06:57:10 +00:00
119 lines
2.4 KiB
Go
119 lines
2.4 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 DISTINCT", func(t *testing.T) {
|
|
testQueryParse(
|
|
t,
|
|
`SELECT DISTINCT c.id FROM c`,
|
|
parsers.SelectStmt{
|
|
SelectItems: []parsers.SelectItem{
|
|
{Path: []string{"c", "id"}},
|
|
},
|
|
Table: parsers.Table{Value: "c"},
|
|
Distinct: true,
|
|
},
|
|
)
|
|
})
|
|
|
|
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"},
|
|
},
|
|
)
|
|
})
|
|
}
|