-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial_1.go
More file actions
38 lines (31 loc) · 797 Bytes
/
tutorial_1.go
File metadata and controls
38 lines (31 loc) · 797 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_1
// +build tutorial_1
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'
// SQL executed: SELECT cities.* FROM cities WHERE cities.name = "Paris"
func tutorial(db *cql.DB) {
cities, err := cql.Query[models.City](
context.Background(),
db,
conditions.City.Name.Is().Eq(cql.String("Paris")),
).Find()
// SQL executed:
// SELECT cities.* FROM cities
// WHERE cities.name = "Paris"
if err != nil {
log.Panicln(err)
}
fmt.Println("--------------------------")
fmt.Println("Cities named 'Paris' are:")
for i, city := range cities {
fmt.Printf("\t%v: %+v\n", i+1, city)
}
}