-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial_2.go
More file actions
38 lines (31 loc) · 897 Bytes
/
tutorial_2.go
File metadata and controls
38 lines (31 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//go:build tutorial_2
// +build tutorial_2
package main
import (
"context"
"fmt"
"log"
"github.com/FrancoLiberali/cql"
"github.com/FrancoLiberali/cql-tutorial/conditions"
"github.com/FrancoLiberali/cql-tutorial/models"
)
// Target: get all cities whose name is 'Paris' and its population is greater than 1000000
func tutorial(db *cql.DB) {
cities, err := cql.Query[models.City](
context.Background(),
db,
conditions.City.Name.Is().Eq(cql.String("Paris")),
conditions.City.Population.Is().Gt(cql.Int64(1000000)),
).Find()
// SQL executed:
// SELECT cities.* FROM cities
// WHERE cities.name = "Paris" AND cities.population > 1000000
if err != nil {
log.Panicln(err)
}
fmt.Println("--------------------------")
fmt.Println("Cities named 'Paris' with a population bigger than 1.000.000 are:")
for i, city := range cities {
fmt.Printf("\t%v: %+v\n", i+1, city)
}
}