row

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Columns

func Columns(r Row) ([]string, error)

func Flatten

func Flatten(r Row) []types.Value

func Length

func Length(r Row) (int, error)

Length returns the number of columns of a row.

func MarshalJSON

func MarshalJSON(r Row) ([]byte, error)

MarshalJSON encodes a row to json.

func MarshalTextIndent

func MarshalTextIndent(r Row, prefix, indent string) ([]byte, error)

func NewValue

func NewValue(x any) (types.Value, error)

NewValue creates a value whose type is infered from x.

Types

type Column

type Column struct {
	Name  string
	Value types.Value
}

type ColumnBuffer

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

ColumnBuffer stores a group of columns in memory. It implements the Row interface.

func NewColumnBuffer

func NewColumnBuffer() *ColumnBuffer

NewColumnBuffer creates a ColumnBuffer.

func (*ColumnBuffer) Add

func (cb *ColumnBuffer) Add(column string, v types.Value) *ColumnBuffer

Add a field to the buffer.

func (*ColumnBuffer) Copy

func (cb *ColumnBuffer) Copy(r Row) error

Copy every value of the row to the buffer.

func (*ColumnBuffer) Delete

func (cb *ColumnBuffer) Delete(column string) error

Delete a column from the buffer.

func (ColumnBuffer) Get

func (cb ColumnBuffer) Get(column string) (types.Value, error)

Get returns a value by column. Returns an error if the column doesn't exists.

func (ColumnBuffer) Iterate

func (cb ColumnBuffer) Iterate(fn func(column string, value types.Value) error) error

Iterate goes through all the columns of the row and calls the given function by passing each one of them. If the given function returns an error, the iteration stops.

func (ColumnBuffer) Len

func (cb ColumnBuffer) Len() int

Len of the buffer.

func (*ColumnBuffer) MarshalJSON

func (cb *ColumnBuffer) MarshalJSON() ([]byte, error)

func (*ColumnBuffer) Replace

func (cb *ColumnBuffer) Replace(column string, v types.Value) error

Replace the value of the column by v.

func (*ColumnBuffer) Reset

func (cb *ColumnBuffer) Reset()

Reset the buffer.

func (*ColumnBuffer) ScanCSV

func (cb *ColumnBuffer) ScanCSV(headers, columns []string)

func (*ColumnBuffer) Set

func (cb *ColumnBuffer) Set(column string, v types.Value) error

Set replaces a column if it already exists or creates one if not.

func (*ColumnBuffer) UnmarshalJSON

func (cb *ColumnBuffer) UnmarshalJSON(data []byte) error

type Row

type Row interface {
	// Iterate goes through all the columns of the row and calls the given function
	// by passing the column name
	Iterate(fn func(column string, value types.Value) error) error

	// Get returns the value of the given column.
	// If the column does not exist, it returns ErrColumnNotFound.
	Get(name string) (types.Value, error)
}

func NewFromCSV

func NewFromCSV(headers, columns []string) Row

NewFromCSV takes a list of headers and columns and returns an row. Each header will be assigned as the key and each corresponding column as a text value. The length of headers and columns must be the same.

func SortColumns

func SortColumns(r Row) Row

func Unflatten

func Unflatten(values []types.Value) Row

Jump to

Keyboard shortcuts

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