Created
August 15, 2020 15:32
-
-
Save RouHim/439b2d56fd29989d3a1f44322bc38ce4 to your computer and use it in GitHub Desktop.
GO | ArangoDB | Retrieve typed documents for a query with a parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func RetrieveDocumentsForDate(date string) { | |
ctx := context.Background() | |
query := "FOR d IN table FILTER d.date == @date RETURN d" | |
bindVars := map[string]interface{}{ | |
"date": date, | |
} | |
cursor, err := database.Query(ctx, query, bindVars) | |
if err != nil { | |
log.Fatal(err) | |
} | |
_ = cursor.Close() | |
for { | |
var doc meal.Meal | |
_, err := cursor.ReadDocument(ctx, &doc) | |
if driver.IsNoMoreDocuments(err) { | |
break | |
} else if err != nil { | |
// handle other errors | |
} | |
fmt.Printf("Got doc with key '%s' from query\n", doc.Name) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment