Go - Collection.Query.Where()
Adds a new where clause to a query, which filters the data returned.
import ("fmt""github.com/nitrictech/go-sdk/api/documents""github.com/nitrictech/go-sdk/nitric")func main() {profiles, err := nitric.NewCollection("profiles").With(nitric.CollectionReading)if err != nil {return}query := profiles.Query().Where(documents.Condition("name").StartsWith(documents.StringValue("T")),)nitric.Run()}
Parameters
- Name
expressions
- Required
- Required
- Type
- ...QueryExpression
- Description
The query expressions.
Notes
Multiple query expressions combined together are always considered AND
Examples
A simple query
import ("fmt""github.com/nitrictech/go-sdk/api/documents""github.com/nitrictech/go-sdk/nitric")func main() {profiles, err := nitric.NewCollection("profiles").With(nitric.CollectionReading)if err != nil {return}query := profiles.Query().Where(documents.Condition("firstName").Eq(documents.StringValue("Drake")),)nitric.Run()}
Combining where clauses
import ("fmt""github.com/nitrictech/go-sdk/api/documents""github.com/nitrictech/go-sdk/nitric")func main() {profiles, err := nitric.NewCollection("profiles").With(nitric.CollectionReading)if err != nil {return}query := profiles.Query().Where(documents.Condition("name").Eq(documents.StringValue("Drake")),documents.Condition("age").Gt(documents.DoubleValue(21)),)nitric.Run()}
See also
Last updated on Dec 19, 2024