Documentation ¶
Index ¶
- func Apply(s beam.Scope, conn string, mutations []*spanner.Mutation)
- func Query(s beam.Scope, conn string, q spanner.Statement, t reflect.Type) beam.PCollection
- func Read(s beam.Scope, conn, table string, t reflect.Type) beam.PCollection
- type ApplyMutationFn
- type Client
- type Config
- type MutationBuilder
- type MutationSet
- type MutationSetFn
- type UpsertMutationFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Query ¶
Query executes a query. The output must have a schema compatible with the given type, t. It returns a PCollection<t>.
Types ¶
type ApplyMutationFn ¶
type ApplyMutationFn struct {
Connection string
}
func (*ApplyMutationFn) ProcessElement ¶
type Config ¶
func (*Config) AsConnectionString ¶
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 ¶
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 }