table

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: Zlib Imports: 6 Imported by: 0

Documentation

Overview

Package table give a logical in-memory buffer row a database table.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	// Name of the table in the buffer. May be manually set for further encoding.
	Name string
	Row  []Row // Row data.

	// Truncated may be manually set to true if the returned row set has been truncated.
	Truncated bool

	// Result set, which should include current buffer if not nil.
	Set []*Buffer
	// contains filtered or unexported fields
}

Buffer represents a table buffer that holds one or more query.

func Fill

func Fill(ctx context.Context, res *rdb.Result) (*Buffer, error)

Fill the query result and return the buffer.

func FillCommand

func FillCommand(ctx context.Context, q rdb.Queryer, cmd *rdb.Command, params ...rdb.Param) (*Buffer, error)

FillCommand runs a query, fills the result, and closes the query result.

func FillSet

func FillSet(res *rdb.Result) ([]*Buffer, error)

FillSet populates a query result and returns a table set.

func (*Buffer) AddBufferRow

func (b *Buffer) AddBufferRow(row Row)

AddBufferRow adds a new row to the buffer manually.

func (*Buffer) AddRow

func (b *Buffer) AddRow(v ...interface{}) *Row

AddRow adds a slice of values.

func (*Buffer) ColumnIndex

func (b *Buffer) ColumnIndex(name string) int

ColumnIndex returns the index of the named column. If the name is not present it returns -1.

func (*Buffer) Len

func (b *Buffer) Len() int

Len is the number of rows in the table buffer.

func (*Buffer) Schema

func (b *Buffer) Schema() []*rdb.Column

Schema returns the table column schema

func (*Buffer) SetSchema

func (b *Buffer) SetSchema(schema []*rdb.Column) error

SetSchema sets the table buffer schema manually.

type JsonRowArray

type JsonRowArray struct {
	*Buffer
	FlushAt int

	// Additional properties to add to the output.
	Meta map[string]interface{}

	ResultNameName    string // Default field name is "Name".
	ColumnHeadersName string // Default field name is "Column".
	DataRowsName      string // Default field name is "Data".
}

Serialize the table buffer as an object with a column name array and an an array of rows. Each row is an array of values. Supports many result sets by chaining them together.

func (*JsonRowArray) MarshalJSON

func (coder *JsonRowArray) MarshalJSON() ([]byte, error)

func (*JsonRowArray) WriteTo

func (coder *JsonRowArray) WriteTo(writer io.Writer) (n int64, err error)

type JsonRowObject

type JsonRowObject struct {
	*Buffer
	FlushAt int
}

Serialize table buffer as an array of JSON objects. When multiple results are returned, turns into an array of arrays.

func (*JsonRowObject) MarshalJSON

func (coder *JsonRowObject) MarshalJSON() ([]byte, error)

func (*JsonRowObject) WriteTo

func (coder *JsonRowObject) WriteTo(writer io.Writer) (n int64, err error)

type Row

type Row struct {
	Field []rdb.Nullable
	// contains filtered or unexported fields
}

Row represents a single buffer row of a table.

func (Row) Get

func (row Row) Get(name string) interface{}

Get returns the column name as a value, nil if null. Panics if name is not a valid column.

func (Row) GetN

func (row Row) GetN(name string) rdb.Nullable

GetN returns a Nullable under the column name. If name does not exist, panics.

func (Row) HasColumn

func (row Row) HasColumn(name string) bool

HasColumn returns true if the row contains the column name.

func (Row) Index

func (row Row) Index(name string) int

Index returns the index of column name.

func (Row) Set added in v1.1.3

func (row Row) Set(name string, v interface{})

Set the value v on the row in column name. If name does not exist, panics.

func (Row) SetN added in v1.1.3

func (row Row) SetN(name string, v rdb.Nullable)

SetN sets the nullable value on column name. If name does not exist, panics.

Jump to

Keyboard shortcuts

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