spannerio

package
v0.0.0-...-269ea87 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(s beam.Scope, conn string, mutations []*spanner.Mutation)

func Query

Query executes a query. The output must have a schema compatible with the given type, t. It returns a PCollection<t>.

func Read

func Read(s beam.Scope, conn, table string, t reflect.Type) beam.PCollection

Read reads all rows from the given table. The table must have a schema compatible with the given type, t, and Read returns a PCollection<t>. If the table has more rows than t, then Read is implicitly a projection.

Types

type ApplyMutationFn

type ApplyMutationFn struct {
	Connection string
}

func (*ApplyMutationFn) ProcessElement

func (f *ApplyMutationFn) ProcessElement(ctx context.Context, mutations []*spanner.Mutation) error

type Client

type Client struct {
	*spanner.Client
	Config Config
}

func New

func New(ctx context.Context, cfg *Config) (*Client, error)

type Config

type Config struct {
	Project  string
	Instance string
	Database string
}

func (*Config) AsConnectionString

func (c *Config) AsConnectionString() string

type MutationBuilder

type MutationBuilder interface {
	InsertOrUpdateStruct(table string, in interface{}) error
	GetMutations() []*spanner.Mutation
}

MutationBuilder provides a cleaner API for collecting mutations to be applied on a spanner database. There is a set of methods which allow the collection of mutations of different kinds. A single GetMutations method is also provided allowing the user to extract the resulting set of mutations.

func NewMutationBuilder

func NewMutationBuilder() MutationBuilder

NewMutationBuilder returns MutationSet as MutationBuilder interface.

type MutationSet

type MutationSet []*spanner.Mutation

MutationSet is a wrapper around a []*spanner.Mutation which implements the MutationBuilder interface.

Package cloud.google.com/go/spanner does not provide a clean API for collecting mutations which are to be applied on a database. Likewise, they do not provide an interface around their functions, making it hard to test. The use of this will assist in gathering mutations to be applied, whilst also providing ease for mocking out at test time.

The methods of this struct directly wrap the spanner package level functions with the same name.

func NewMutationSet

func NewMutationSet() *MutationSet

NewMutationSet returns an empty mutation set.

func (*MutationSet) GetMutations

func (m *MutationSet) GetMutations() []*spanner.Mutation

GetMutations returns the slice of mutations which have been maintained by the MutationSet.

func (*MutationSet) InsertOrUpdateStruct

func (m *MutationSet) InsertOrUpdateStruct(table string, in interface{}) error

InsertOrUpdateStruct adds a Mutation to insert a row into a table, specified by a Go struct. If the row already exists, it updates it instead. Any column values not explicitly written are preserved.

The in argument must be a struct or a pointer to a struct. Its exported fields specify the column names and values. Use a field tag like "spanner:name" to provide an alternative column name, or use "spanner:-" to ignore the field.

type MutationSetFn

type MutationSetFn struct{}

func (*MutationSetFn) AddInput

func (fn *MutationSetFn) AddInput(m *MutationSet, mut *spanner.Mutation) *MutationSet

func (*MutationSetFn) CreateAccumulator

func (fn *MutationSetFn) CreateAccumulator() *MutationSet

func (*MutationSetFn) ExtractOutput

func (fn *MutationSetFn) ExtractOutput(m MutationBuilder) []*spanner.Mutation

func (*MutationSetFn) MergeAccumulators

func (fn *MutationSetFn) MergeAccumulators(a, v *MutationSet) *MutationSet

type UpsertMutationFn

type UpsertMutationFn struct {
	Transform func(interface{}) interface{}
	Table     string
}

func (*UpsertMutationFn) ProcessElement

func (u *UpsertMutationFn) ProcessElement(ctx context.Context, row interface{}, emit func(mutation *spanner.Mutation)) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL