drow

package
v0.0.6-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package drow provides a dynamic struct/row type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func XToStruct

func XToStruct(r Row) any

Types

type Field

type Field struct {
	Name  string
	Value any
}

Field is a single field in a row

func F

func F[T any](name string, v T) Field

F Creates a new typed field. TODO: {lpf} to review since we don't need generics here

func (Field) Float32

func (f Field) Float32() float32

Float32 returns the float32 representation of the field or zero if it can't be converted

func (Field) Float64

func (f Field) Float64() float64

Float64 returns the float64 representation of the field or zero if it can't be converted

func (Field) Int

func (f Field) Int() int

Int returns the int representation of the field or zero if it can't be converted

func (Field) Int16

func (f Field) Int16() int16

Int16 returns the int16 representation of the field or zero if it can't be converted

func (Field) Int32

func (f Field) Int32() int32

Int32 returns the int32 representation of the field or zero if it can't be converted

func (Field) Int64

func (f Field) Int64() int64

Int64 returns the int64 representation of the field or zero if it can't be converted

func (Field) String

func (f Field) String() string

String returns the string representation of the field

func (Field) Uint

func (f Field) Uint() uint

Uint returns the uint representation of the field or zero if it can't be converted

func (Field) Uint16

func (f Field) Uint16() uint16

Uint16 returns the int16 representation of the field or zero if it can't be converted

func (Field) Uint32

func (f Field) Uint32() uint32

Uint32 returns the uint32 representation of the field or zero if it can't be converted

func (Field) Uint64

func (f Field) Uint64() uint64

Uint64 returns the uint64 representation of the field or zero if it can't be converted

type FieldExpr

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

func FE

func FE(s ...IntOrString) FieldExpr

Computed row field

func (FieldExpr) Apply

func (f FieldExpr) Apply(r Row) *Field

func (FieldExpr) As

func (f FieldExpr) As(s string) FieldExpr

type IntOrString

type IntOrString any

type Row

type Row []Field

Row is a slice of fields with a defined sequence.

func FromMap

func FromMap(m map[string]any) Row

FromMap creates a row from a map[string]interface{} the fields might not be in the same order as the map

func FromStruct

func FromStruct(v any) Row

func (Row) At

func (r Row) At(s IntOrString) Field

At returns the value of a field named s.

func (Row) Columns

func (r Row) Columns() []string

Columns returns the names of the fields.

func (Row) Concat

func (r Row) Concat(r2 Row) Row

Concat returns a new row with the fields of r and the fields of r2. this might duplicate field names.

func (Row) Drop

func (r Row) Drop(names ...string) Row

Drop returns a new row without the fields identified by names

func (Row) Eq

func (r Row) Eq(v any) bool

Eq returns true if the v is equal to row r

func (Row) Flat

func (r Row) Flat() Row

Flat if a field is a Row it's fields will be in the main row.

func (Row) Has

func (r Row) Has(s string) bool

Has returns true if the row has a field named s, false otherwise.

func (Row) Index

func (r Row) Index(s string) int

Index returns the index of a field by name.

func (Row) Info

func (r Row) Info() string

Info returns a string with the fields and values type of the row.

func (Row) InfoTree

func (r Row) InfoTree() string

InfoTree shows the tree of the row with fields and sub fields.

func (Row) MarshalJSON

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

func (Row) Merge

func (r Row) Merge(r2 Row) Row

Merge will set the fields of r2 in r.

func (Row) Prefix

func (r Row) Prefix(prefix string) Row

Prefix returns a new row with all fields prefixed with prefix.

func (Row) Rename

func (r Row) Rename(old, name string) Row

Rename returns a new row with the renamed field.

func (Row) RenameFields

func (r Row) RenameFields(m map[string]string) Row

RenameFields renames multiple fields based on map

func (Row) Select

func (r Row) Select(cols ...IntOrString) Row

Select returns a new row with the named selected fields.

func (Row) String

func (r Row) String() string

func (Row) ToMap

func (r Row) ToMap() map[string]any

ToMap converts a row to map[string]any

func (*Row) UnmarshalJSON

func (r *Row) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Row) Value

func (r Row) Value(s IntOrString) any

Value returns the value at s

func (Row) Values

func (r Row) Values() []any

Values return a []any of the values of the row fields.

func (Row) WithField

func (r Row) WithField(s string, v any) Row

WithField returns a copy of the row with the field f.

func (Row) WithFields

func (r Row) WithFields(fs ...Field) Row

WithFields returns a copy of the row with the several fields if the field name exists the value will be replaced in the new row.

Jump to

Keyboard shortcuts

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