fix parsing of collection bind params

This commit is contained in:
Aneurin Barker Snook
2023-10-13 07:59:04 +01:00
parent 7ae2ef1d56
commit 6f85786542
3 changed files with 12 additions and 12 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ import (
) )
// https://docs.arangodb.com/3.11/aql/fundamentals/bind-parameters/#syntax // https://docs.arangodb.com/3.11/aql/fundamentals/bind-parameters/#syntax
var paramRegexp = regexp.MustCompile("@{1,2}([A-z0-9_]+)") var paramRegexp = regexp.MustCompile("@(@?[A-z0-9_]+)")
// ReadParams reads out named parameters from an AQL string. // ReadParams reads out named parameters from an AQL string.
func ReadParams(input string) []string { func ReadParams(input string) []string {
+1 -1
View File
@@ -18,7 +18,7 @@ func TestReadParams(t *testing.T) {
}, },
{ {
Input: "FOR doc IN @@collection FILTER doc.title == @title RETURN doc", Input: "FOR doc IN @@collection FILTER doc.title == @title RETURN doc",
Output: []string{"collection", "title"}, Output: []string{"@collection", "title"},
}, },
} }
+6 -6
View File
@@ -28,7 +28,7 @@ func TestQueryAppend(t *testing.T) {
FILTER doc.title == @title FILTER doc.title == @title
RETURN doc`, RETURN doc`,
ExpectedParams: map[string]any{ ExpectedParams: map[string]any{
"collection": "recipes", "@collection": "recipes",
"title": "Spaghetti", "title": "Spaghetti",
}, },
}, },
@@ -42,7 +42,7 @@ RETURN doc`,
FILTER doc.title == @title FILTER doc.title == @title
RETURN doc`, RETURN doc`,
ExpectedParams: map[string]any{ ExpectedParams: map[string]any{
"collection": "recipes", "@collection": "recipes",
"title": "Spaghetti", "title": "Spaghetti",
}, },
}, },
@@ -52,13 +52,13 @@ RETURN doc`,
Append("FOR doc IN @@collection"). Append("FOR doc IN @@collection").
Append("FILTER doc.title == @title"). Append("FILTER doc.title == @title").
Append("RETURN doc"). Append("RETURN doc").
Bind("collection", "recipes"). Bind("@collection", "recipes").
Bind("title", "Spaghetti"), Bind("title", "Spaghetti"),
ExpectedStr: `FOR doc IN @@collection ExpectedStr: `FOR doc IN @@collection
FILTER doc.title == @title FILTER doc.title == @title
RETURN doc`, RETURN doc`,
ExpectedParams: map[string]any{ ExpectedParams: map[string]any{
"collection": "recipes", "@collection": "recipes",
"title": "Spaghetti", "title": "Spaghetti",
}, },
}, },
@@ -68,12 +68,12 @@ RETURN doc`,
Append("FOR doc IN @@collection"). Append("FOR doc IN @@collection").
Append("FILTER doc.title == @title"). Append("FILTER doc.title == @title").
Append("RETURN doc"). Append("RETURN doc").
BindMap(map[string]any{"collection": "recipes", "title": "Spaghetti"}), BindMap(map[string]any{"@collection": "recipes", "title": "Spaghetti"}),
ExpectedStr: `FOR doc IN @@collection ExpectedStr: `FOR doc IN @@collection
FILTER doc.title == @title FILTER doc.title == @title
RETURN doc`, RETURN doc`,
ExpectedParams: map[string]any{ ExpectedParams: map[string]any{
"collection": "recipes", "@collection": "recipes",
"title": "Spaghetti", "title": "Spaghetti",
}, },
}, },