-
Notifications
You must be signed in to change notification settings - Fork 387
/
adapter_spanner.go
56 lines (46 loc) · 1.55 KB
/
adapter_spanner.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
47
48
49
50
51
52
53
54
55
56
// Copyright (C) 2024 Storj Labs, Inc.
// See LICENSE for copying information.
package metabase
import (
"context"
"log"
"os"
"github.com/storj/exp-spanner"
"github.com/zeebo/errs"
)
// SpannerConfig includes all the configuration required by using spanner.
type SpannerConfig struct {
Database string `help:"Database definition for spanner connection in the form projects/P/instances/I/databases/DB"`
}
// SpannerAdapter implements Adapter for Google Spanner connections..
type SpannerAdapter struct {
client *spanner.Client
}
// NewSpannerAdapter creates a new Spanner adapter.
func NewSpannerAdapter(ctx context.Context, cfg SpannerConfig) (*SpannerAdapter, error) {
client, err := spanner.NewClientWithConfig(ctx, cfg.Database,
spanner.ClientConfig{
Logger: log.New(os.Stdout, "spanner", log.LstdFlags),
SessionPoolConfig: spanner.DefaultSessionPoolConfig,
DisableRouteToLeader: false})
if err != nil {
return nil, errs.Wrap(err)
}
return &SpannerAdapter{
client: client,
}, nil
}
// TestingBeginObjectExactVersion implements Adapter.
func (s *SpannerAdapter) TestingBeginObjectExactVersion(ctx context.Context, opts BeginObjectExactVersion, object *Object) error {
panic("implement me")
}
// GetObjectLastCommitted implements Adapter.
func (s *SpannerAdapter) GetObjectLastCommitted(ctx context.Context, opts GetObjectLastCommitted, object *Object) error {
panic("implement me")
}
// Close closes the internal client.
func (s *SpannerAdapter) Close() error {
s.client.Close()
return nil
}
var _ Adapter = &SpannerAdapter{}