Explorar o código

fix parsing of collection bind params

Aneurin Barker Snook hai 1 ano
pai
achega
6f85786542
Modificáronse 3 ficheiros con 12 adicións e 12 borrados
  1. 1 1
      params.go
  2. 1 1
      params_test.go
  3. 10 10
      query_test.go

+ 1 - 1
params.go

@@ -5,7 +5,7 @@ import (
 )
 
 // 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.
 func ReadParams(input string) []string {

+ 1 - 1
params_test.go

@@ -18,7 +18,7 @@ func TestReadParams(t *testing.T) {
 		},
 		{
 			Input:  "FOR doc IN @@collection FILTER doc.title == @title RETURN doc",
-			Output: []string{"collection", "title"},
+			Output: []string{"@collection", "title"},
 		},
 	}
 

+ 10 - 10
query_test.go

@@ -28,8 +28,8 @@ func TestQueryAppend(t *testing.T) {
 FILTER doc.title == @title
 RETURN doc`,
 			ExpectedParams: map[string]any{
-				"collection": "recipes",
-				"title":      "Spaghetti",
+				"@collection": "recipes",
+				"title":       "Spaghetti",
 			},
 		},
 		// Append with too many parameters
@@ -42,8 +42,8 @@ RETURN doc`,
 FILTER doc.title == @title
 RETURN doc`,
 			ExpectedParams: map[string]any{
-				"collection": "recipes",
-				"title":      "Spaghetti",
+				"@collection": "recipes",
+				"title":       "Spaghetti",
 			},
 		},
 		// Append without parameters and bind after
@@ -52,14 +52,14 @@ RETURN doc`,
 				Append("FOR doc IN @@collection").
 				Append("FILTER doc.title == @title").
 				Append("RETURN doc").
-				Bind("collection", "recipes").
+				Bind("@collection", "recipes").
 				Bind("title", "Spaghetti"),
 			ExpectedStr: `FOR doc IN @@collection
 FILTER doc.title == @title
 RETURN doc`,
 			ExpectedParams: map[string]any{
-				"collection": "recipes",
-				"title":      "Spaghetti",
+				"@collection": "recipes",
+				"title":       "Spaghetti",
 			},
 		},
 		// Append and bind map
@@ -68,13 +68,13 @@ RETURN doc`,
 				Append("FOR doc IN @@collection").
 				Append("FILTER doc.title == @title").
 				Append("RETURN doc").
-				BindMap(map[string]any{"collection": "recipes", "title": "Spaghetti"}),
+				BindMap(map[string]any{"@collection": "recipes", "title": "Spaghetti"}),
 			ExpectedStr: `FOR doc IN @@collection
 FILTER doc.title == @title
 RETURN doc`,
 			ExpectedParams: map[string]any{
-				"collection": "recipes",
-				"title":      "Spaghetti",
+				"@collection": "recipes",
+				"title":       "Spaghetti",
 			},
 		},
 		// Append and Appendf