luci: Index | Files

package spanutil

import ""

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


Package Files

buffer.go compression.go doc.go metrics.go util.go


var ErrNoResults = iterator.Done

ErrNoResults is an error returned when a query unexpectedly has no results.

func Compress Uses

func Compress(data []byte) []byte

Compress compresses data using zstd.

func Decompress Uses

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 Uses

func FromSpanner(row *spanner.Row, ptrs ...interface{}) error

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

func IncRowCount Uses

func IncRowCount(ctx context.Context, count int, table Table, rowStatus RowStatus, realm string)

IncRowCount increments the row counter.

func InsertMap Uses

func InsertMap(table string, in map[string]interface{}) *spanner.Mutation

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

func InsertOrUpdateMap Uses

func InsertOrUpdateMap(table string, in map[string]interface{}) *spanner.Mutation

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

func Query Uses

func Query(ctx context.Context, st spanner.Statement, fn func(row *spanner.Row) error) error

Query executes a query. Ensures st.Params are Spanner-compatible by modifying st.Params in place.

func QueryFirstRow Uses

func QueryFirstRow(ctx context.Context, st spanner.Statement, ptrs ...interface{}) error

QueryFirstRow executes a query, reads the first row into ptrs and stops the iterator. Returns ErrNoResults if the query does not return at least one row.

func ReadRow Uses

func ReadRow(ctx context.Context, table string, key spanner.Key, ptrMap map[string]interface{}) error

ReadRow reads a single row from the database and reads its values. ptrMap must map from column names to pointers where the values will be written.

func ToSpanner Uses

func ToSpanner(v interface{}) interface{}

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

func ToSpannerMap Uses

func ToSpannerMap(values map[string]interface{}) map[string]interface{}

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

func ToSpannerSlice Uses

func ToSpannerSlice(values ...interface{}) []interface{}

ToSpannerSlice converts a slice of Go values to a slice of Spanner values. See also ToSpanner.

func UpdateMap Uses

func UpdateMap(table string, in map[string]interface{}) *spanner.Mutation

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

type Buffer Uses

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

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

- Value and Ptr
- string
- tspb.Timestamp
- pb.InvocationState
- pb.TestStatus
- pb.Variant
- pb.StringPair
- proto.Message

TODO(nodir): move to buffer.go

func (*Buffer) FromSpanner Uses

func (b *Buffer) FromSpanner(row *spanner.Row, ptrs ...interface{}) error

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

type Compressed Uses

type Compressed []byte

Compressed instructs ToSpanner and FromSpanner functions to compress the content with encoding.

func (*Compressed) FromSpanner Uses

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

FromSpanner implements Ptr.

func (*Compressed) SpannerPtr Uses

func (c *Compressed) SpannerPtr(b *Buffer) interface{}

SpannerPtr implements Ptr.

func (Compressed) ToSpanner Uses

func (c Compressed) ToSpanner() interface{}

ToSpanner implements Value.

type Ptr Uses

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) interface{}
    // 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 RowStatus Uses

type RowStatus string

RowStatus is a status of a row. Used in metrics.

const (
    Inserted RowStatus = "INSERTED"
    Deleted  RowStatus = "DELETED"

Values of RowStatus type.

type Table Uses

type Table string

Table identifies a Spanner table. Used in metrics.

const (
    TestResults Table = "TestResults"
    Invocations Table = "Invocations"

Values of Table type.

type Value Uses

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

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

Package spanutil imports 16 packages (graph) and is imported by 25 packages. Updated 2021-01-24. Refresh now. Tools for package owners.