-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_store.go
45 lines (38 loc) · 887 Bytes
/
user_store.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
package nateer
import (
"context"
"cloud.google.com/go/spanner"
"google.golang.org/api/iterator"
)
type UserStore struct {
spa *spanner.Client
}
func NewUserStore(ctx context.Context, spa *spanner.Client) (*UserStore, error) {
return &UserStore{
spa: spa,
}, nil
}
func (s *UserStore) Select(ctx context.Context, id string) (string, error) {
tx := s.spa.ReadOnlyTransaction()
defer tx.Close()
statement := spanner.NewStatement("SELECT ID FROM User10m WHERE ID = @ID")
statement.Params = map[string]interface{}{"ID": id}
iter := tx.QueryWithOptions(ctx, statement, spanner.QueryOptions{
Mode: nil,
Options: nil,
Priority: 0,
RequestTag: "nateer-userStore-select",
})
defer iter.Stop()
for {
row, err := iter.Next()
if err == iterator.Done {
break
}
if err != nil {
return "", err
}
return row.String(), nil
}
return "", nil
}