-
Notifications
You must be signed in to change notification settings - Fork 68
/
map_table1.go
46 lines (40 loc) · 946 Bytes
/
map_table1.go
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
40
41
42
43
44
45
46
package main
import (
"fmt"
"github.com/gocassa/gocassa"
"time"
)
// This test assumes that cassandra is running on default port locally and
// that the keySpace called 'test' already exists.
type Sale struct {
Id string
CustomerId string
SellerId string
Price int
Created time.Time
}
func main() {
keySpace, err := gocassa.ConnectToKeySpace("test", []string{"127.0.0.1"}, "", "")
if err != nil {
panic(err)
}
salesTable := keySpace.MapTable("sale", "Id", &Sale{})
// Create the table - we ignore error intentionally
salesTable.Create()
// We insert the first record into our table - yay!
err = salesTable.Set(Sale{
Id: "sale-1",
CustomerId: "customer-1",
SellerId: "seller-1",
Price: 42,
Created: time.Now(),
}).Run()
if err != nil {
panic(err)
}
result := Sale{}
if err := salesTable.Read("sale-1", &result).Run(); err != nil {
panic(err)
}
fmt.Println(result)
}