-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial_5.go
More file actions
39 lines (32 loc) · 940 Bytes
/
tutorial_5.go
File metadata and controls
39 lines (32 loc) · 940 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
39
//go:build tutorial_5
// +build tutorial_5
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 that the country to which they belong is called 'France'.
func tutorial(db *cql.DB) {
parisFrance, err := cql.Query[models.City](
context.Background(),
db,
conditions.City.Name.Is().Eq(cql.String("Paris")),
conditions.City.Country(
conditions.Country.Name.Is().Eq(cql.String("France")),
),
).FindOne()
// SQL executed:
// SELECT cities.* FROM cities
// INNER JOIN countries Country ON
// Country.id = cities.country_id AND Country.name = "France"
// WHERE cities.name = "Paris"
if err != nil {
log.Panicln(err)
}
fmt.Println("--------------------------")
fmt.Printf("City named 'Paris' in 'France' is: %+v\n", parisFrance)
}