mirror of
https://github.com/pikami/cosmium.git
synced 2024-11-25 06:57:10 +00:00
Add support for array field access
This commit is contained in:
parent
ca49228c66
commit
bdf9970ce6
File diff suppressed because it is too large
Load Diff
@ -24,11 +24,7 @@ func makeFieldPath(name interface{}, path interface{}, alias interface{}) (parse
|
|||||||
paths := make([]string, 1)
|
paths := make([]string, 1)
|
||||||
paths[0] = name.(string)
|
paths[0] = name.(string)
|
||||||
for _, p := range ps {
|
for _, p := range ps {
|
||||||
pa := p.([]interface{})
|
paths = append(paths, p.(string))
|
||||||
px := pa[1:]
|
|
||||||
for _, pi := range px {
|
|
||||||
paths = append(paths, pi.(string))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldPath := parsers.FieldPath{Path: paths}
|
fieldPath := parsers.FieldPath{Path: paths}
|
||||||
@ -97,11 +93,19 @@ TableName <- key:Identifier {
|
|||||||
return parsers.Table{Value: key.(string)}, nil
|
return parsers.Table{Value: key.(string)}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
FieldPath <- name:Identifier path:("." Identifier)*
|
FieldPath <- name:Identifier path:(DotFieldAccess / ArrayFieldAccess)*
|
||||||
asClause:(ws "AS" ws alias:Identifier { return alias, nil })? {
|
asClause:(ws "AS" ws alias:Identifier { return alias, nil })? {
|
||||||
return makeFieldPath(name, path, asClause)
|
return makeFieldPath(name, path, asClause)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DotFieldAccess <- "." id:Identifier {
|
||||||
|
return id, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayFieldAccess <- "[\"" id:Identifier "\"]" {
|
||||||
|
return id, nil
|
||||||
|
}
|
||||||
|
|
||||||
Identifier <- [a-zA-Z_][a-zA-Z0-9_]* {
|
Identifier <- [a-zA-Z_][a-zA-Z0-9_]* {
|
||||||
return string(c.text), nil
|
return string(c.text), nil
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func Test_Parse(t *testing.T) {
|
|||||||
t.Run("Shoul parse simple SELECT", func(t *testing.T) {
|
t.Run("Shoul parse simple SELECT", func(t *testing.T) {
|
||||||
testQueryParse(
|
testQueryParse(
|
||||||
t,
|
t,
|
||||||
`SELECT c.id, c.pk FROM c`,
|
`SELECT c.id, c["pk"] FROM c`,
|
||||||
parsers.SelectStmt{
|
parsers.SelectStmt{
|
||||||
Columns: []parsers.FieldPath{
|
Columns: []parsers.FieldPath{
|
||||||
{Path: []string{"c", "id"}},
|
{Path: []string{"c", "id"}},
|
||||||
|
Loading…
Reference in New Issue
Block a user