hake

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: MIT Imports: 14 Imported by: 2

README

gcpug/hake Go Documentation Go Report Card codecov

gcpug/hake provides utilties for GenericColumnValue which handles Query's Response generically.

Install

go get github.com/gcpug/hake

Usage

All usage are described in GoDoc.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Columns

func Columns(row *spanner.Row) ([]*spanner.GenericColumnValue, error)

Columns returns columns of the row as []*spanner.GenericColumnValue.

func Types

func Types(row *spanner.Row) ([]*gspanner.Type, error)

Types returns column types of the row.

Types

type JSONColumn

type JSONColumn spanner.GenericColumnValue

JSONColumn is an encodable type of spanner.GenericColumnValue.

func (*JSONColumn) MarshalJSON

func (c *JSONColumn) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

type JSONObject

type JSONObject interface {
	Set(key string, value interface{})
	Get(key string) (interface{}, bool)
	Ref() string
}

JSONObject is interface of JSON object.

type JSONRow

type JSONRow spanner.Row

JSONRow is an encodable type of spanner.Row.

func (*JSONRow) JSONSchema

func (r *JSONRow) JSONSchema(w io.Writer, options ...jsonschema.Option) error

Schema writes JSON Schema of the row to writer w.

func (*JSONRow) MarshalJSON

func (r *JSONRow) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

type JSONRows

type JSONRows []*spanner.Row

JSONRows is an encodable type of []*spanner.Row.

func (JSONRows) At

func (rs JSONRows) At(i int) *JSONRow

At returns ith row as *JSONRow.

func (JSONRows) JSONSchema

func (rs JSONRows) JSONSchema(w io.Writer, options ...jsonschema.Option) error

Schema writes JSON Schema of the rows to writer w.

func (JSONRows) MarshalJSON

func (rs JSONRows) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

type RecordWriter

type RecordWriter interface {
	Write(record []string) error
}

RecordWriter writes a record. csv.Writer implements RecordWriter.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer is writes *spanner.Row to Recordwriter.

func NewWriter

func NewWriter(w RecordWriter, header bool) *Writer

NewWriter creates a Writer.

func (*Writer) Write

func (w *Writer) Write(row *spanner.Row) error

Write writes a row of spanner to RecordWriter. If it is first time to write, Write writes also a header before writing a row. When second argument of NewWriter is false, the header would be omit.

Example with csv.Writer:

func query(ctx context.Context, w io.Writer, client *spanner.Client) error {
	stmt := spanner.Statement{SQL: `SELECT * FROM mytable`}
	iter := client.Single().Query(ctx, stmt)
	defer iter.Stop()
	cw := csv.NewWriter(w)
	hw := hake.NewWriter(cw, true)
	for {
		row, err := iter.Next()
		switch {
		case err == iterator.Done:
			return nil
		case err != nil:
			return err
		}

		if err := hw.Write(row); err != nil {
			return err
		}
		cw.Flush()
	}
}

Jump to

Keyboard shortcuts

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