-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial_3.go
More file actions
38 lines (31 loc) · 822 Bytes
/
tutorial_3.go
File metadata and controls
38 lines (31 loc) · 822 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_3
// +build tutorial_3
package main
import (
"context"
"fmt"
"log"
"github.com/FrancoLiberali/cql"
"github.com/FrancoLiberali/cql-tutorial/conditions"
"github.com/FrancoLiberali/cql-tutorial/models"
)
// Target: get the city named 'Paris' with the largest population
func tutorial(db *cql.DB) {
parisFrance, err := cql.Query[models.City](
context.Background(),
db,
conditions.City.Name.Is().Eq(cql.String("Paris")),
).Descending(
conditions.City.Population,
).Limit(1).FindOne()
// SQL executed:
// SELECT cities.* FROM cities
// WHERE cities.name = "Paris"
// ORDER BY cities.population DESC
// LIMIT 1
if err != nil {
log.Panicln(err)
}
fmt.Println("--------------------------")
fmt.Printf("City named 'Paris' with the largest population is: %+v\n", parisFrance)
}