span

package
v0.0.0-...-be8672a Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package span contains utility functions to interact with the underlying Spanner storage. It does not attempt to encapsulate Spanner.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compress

func Compress(data []byte) []byte

Compress compresses data using zstd.

func Decompress

func Decompress(src, dest []byte) ([]byte, error)

Decompress decompresses the src compressed with Compress to dest. dest is the buffer for decompressed content, it will be reset to 0 length before taking the content.

func FromSpanner

func FromSpanner(row *spanner.Row, ptrs ...any) error

FromSpanner is a shortcut for (&Buffer{}).FromSpanner. Appropriate when FromSpanner is called only once, whereas Buffer is reusable throughout function.

func GenerateStatement

func GenerateStatement(tmpl *template.Template, name string, input any) (spanner.Statement, error)

GenerateStatement generates a spanner statement from a text template.

func InsertMap

func InsertMap(table string, in map[string]any) *spanner.Mutation

InsertMap is a shortcut for spanner.InsertMap with ToSpannerMap applied to in.

func InsertOrUpdateMap

func InsertOrUpdateMap(table string, in map[string]any) *spanner.Mutation

InsertOrUpdateMap is a shortcut for spanner.InsertOrUpdateMap with ToSpannerMap applied to in.

func QuoteLike

func QuoteLike(value string) string

QuoteLike turns a literal string into an escaped like expression. This means strings like test_name will only match as expected, rather than also matching test3name.

func SpannerDefaultsInterceptor

func SpannerDefaultsInterceptor() grpc.UnaryServerInterceptor

SpannerDefaultsInterceptor returns a gRPC interceptor that adds default Spanner request options to the context.

The request tag will be set the to RPC method name.

See also ModifyRequestOptions in luci/server/span.

func ToSpanner

func ToSpanner(v any) any

ToSpanner converts values from Go types to Spanner types. In addition to supported types in FromSpanner, also supports []any and map[string]any.

func ToSpannerMap

func ToSpannerMap(values map[string]any) map[string]any

ToSpannerMap converts a map of Go values to a map of Spanner values. See also ToSpanner.

func UpdateMap

func UpdateMap(table string, in map[string]any) *spanner.Mutation

UpdateMap is a shortcut for spanner.UpdateMap with ToSpannerMap applied to in.

Types

type Buffer

type Buffer struct {
	NullString  spanner.NullString
	NullTime    spanner.NullTime
	Int64       int64
	StringSlice []string
	ByteSlice   []byte
	Int64Slice  []int64
}

Buffer can convert a value from a Spanner type to a Go type. Supported types:

  • Value and Ptr
  • string
  • timestamppb.Timestamp
  • atvpb.Status
  • pb.Variant
  • pb.StringPair
  • proto.Message
  • internal.VerdictStatus

func (*Buffer) FromSpanner

func (b *Buffer) FromSpanner(row *spanner.Row, ptrs ...any) error

FromSpanner reads values from row to ptrs, converting types from Spanner to Go along the way.

type Compressed

type Compressed []byte

Compressed instructs ToSpanner and FromSpanner functions to compress the content with https://godoc.org/github.com/klauspost/compress/zstd encoding.

func (*Compressed) FromSpanner

func (c *Compressed) FromSpanner(b *Buffer) error

FromSpanner implements Ptr.

func (*Compressed) SpannerPtr

func (c *Compressed) SpannerPtr(b *Buffer) any

SpannerPtr implements Ptr.

func (Compressed) ToSpanner

func (c Compressed) ToSpanner() any

ToSpanner implements Value.

type Ptr

type Ptr interface {
	// SpannerPtr returns to a pointer of a type supported by Spanner client.
	// SpannerPtr must use one of typed buffers in b.
	SpannerPtr(b *Buffer) any
	// FromSpanner replaces Ptr value with the value in the typed buffer returned
	// by SpannerPtr.
	FromSpanner(b *Buffer) error
}

Ptr can be used a destination of reading a Spanner cell. Typically if type *T implements Ptr, then T implements Value.

type Value

type Value interface {
	// ToSpanner returns a value of a type supported by Spanner client.
	ToSpanner() any
}

Value can be converted to a Spanner value. Typically if type T implements Value, then *T implements Ptr.

Jump to

Keyboard shortcuts

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