Documentation
¶
Index ¶
- Variables
- func ColumnValue[T any](row *Row, idx int, def T) T
- func ColumnValueDecoder(def *Definition, value string) (any, error)
- func ColumnValueEncoder(def *Definition, value any) (string, error)
- func ConvertValueType(value string, tp reflect.Type) (any, error)
- func DetectValueType(name string, value string) reflect.Type
- func JoinAtChar(ss []string, sep byte) string
- func ParseInt(s string, bitSize int) (int64, error)
- func ReaderToLines(r io.Reader) iter.Seq[[]byte]
- func SliceFilter[T any](src []T, cb func(T) bool) []T
- func SliceKeyMap[T any, L comparable, M any](src []T, cb func(T, int) (L, M)) map[L]M
- func SliceMap[T any, K any](src []T, cb func(T) K) []K
- func SliceOmit[T comparable](src []T, keys []T) []T
- func SlicePick[T comparable](src []T, keys []T) []T
- func SplitAtChar(s string, sep byte) []string
- func ToType[T any](v T) reflect.Type
- func TryColumnValue[T any](row *Row, idx int) (T, error)
- type ActionAddColumn
- type ActionChangeColumnType
- type ActionFilterRow
- type ActionModifyRow
- type ActionRenameColumn
- type ActionSelection
- type ActionUpdate
- type AddColumnDataReader
- type ChangeColumnDataReader
- type Definition
- type IndexCache
- type ModifyTableDataReader
- type OptionCallback
- func WithColumns(cols ...string) OptionCallback
- func WithDefinition(name string, def *Definition) OptionCallback
- func WithDefinitionType(name string, tp reflect.Type) OptionCallback
- func WithIgnoreHeader(ih bool) OptionCallback
- func WithMaxRows(s int) OptionCallback
- func WithSampleSize(s int) OptionCallback
- func WithSampling(s int) OptionCallback
- func WithSeparator(sep byte) OptionCallback
- func WithTypeReader(cb func(int, string) reflect.Type) OptionCallback
- type Options
- type PipelineAction
- type Row
- func (r *Row) AddColumn(value any) *Row
- func (r *Row) AsSlice(s *State) ([]string, error)
- func (r *Row) At(idx int) any
- func (r *Row) Clone() *Row
- func (r *Row) CloneP(s *State, names ...string) (*Row, error)
- func (r *Row) Patch(def *Definition, idx int, value any) error
- func (r *Row) Pick(s *State, names ...string) ([]any, error)
- func (r *Row) Set(idx int, value any) *Row
- func (r *Row) WithIndex(idx int) *Row
- type State
- func (s *State) Clone() *State
- func (s *State) ColumnName(idx int) string
- func (s *State) DataType(name string) reflect.Type
- func (s *State) DataTypes() map[string]reflect.Type
- func (s *State) Definition(name string) *Definition
- func (s *State) DefinitionAt(idx int) *Definition
- func (s *State) HasColumn(name string) bool
- func (s *State) HasDefinition(name string) bool
- func (s *State) Index(name string) int
- func (s *State) IsEmpty() bool
- type Table
- func CherryPick(src *Table, columns []string, rows []*Row) (*Table, error)
- func File(path string, cbs ...OptionCallback) (*Table, error)
- func Lines(lines []string, cbs ...OptionCallback) (*Table, error)
- func New(ocbs ...OptionCallback) *Table
- func Raw(ss [][]string, cbs ...OptionCallback) (*Table, error)
- func Reader(r io.Reader, cbs ...OptionCallback) (*Table, error)
- func URL(uri string, cbs ...OptionCallback) (*Table, error)
- func (t *Table) AddRow(rows ...*Row)
- func (t *Table) AppendColumn(pos int, name string)
- func (t *Table) AsColumn(idx int, value string) (any, error)
- func (t *Table) At(idx int) *Row
- func (t *Table) Chunk(start int, end int) *Table
- func (t *Table) Chunks(limit int) iter.Seq2[int, *Table]
- func (t *Table) Clone() *Table
- func (t *Table) CloneE() *Table
- func (t *Table) ColLength() int
- func (t *Table) Execute(actions ...PipelineAction) (*Table, error)
- func (t *Table) ExecuteS(actions ...PipelineAction) error
- func (t *Table) First() *Row
- func (t *Table) Head(limit int) []*Row
- func (t *Table) Initialize() *Table
- func (t *Table) Insert(b []byte) error
- func (t *Table) InsertGenBytes(it iter.Seq[[]byte]) error
- func (t *Table) InsertLine(line string) error
- func (t *Table) InsertLines(lines []string) error
- func (t *Table) InsertSlice(values []string) error
- func (t *Table) InsertSlices(ss [][]string) error
- func (t *Table) IsAtMaxLine() bool
- func (t *Table) IsEmpty() bool
- func (t *Table) IsResolved() bool
- func (t *Table) Last() *Row
- func (t *Table) Length() int
- func (t *Table) MarkUnresolved() *Table
- func (t *Table) RSlice(start int, end int) []*Row
- func (t *Table) Read(r io.Reader) error
- func (t *Table) ResolveDefinition(name string, tp reflect.Type) *Definition
- func (t *Table) ResolveTypes(names []string, values []string) error
- func (t *Table) ResolveValueDefinition(idx int, name string, value string) *Definition
- func (t *Table) Save(path string) error
- func (t *Table) SetColumns(cols []string)
- func (t *Table) SetDefinition(name string, def *Definition) *Definition
- func (t *Table) SetIndexes(cache IndexCache)
- func (t *Table) SetOptions(opts *Options) *Table
- func (t *Table) SetState(s *State) *Table
- func (t *Table) Slice(start int, end int) []*Row
- func (t *Table) SliceToColumns(values []string) ([]any, error)
- func (t *Table) String() string
- func (t *Table) Tail(limit int) []*Row
- func (t *Table) UseColumns(values []string)
- func (t *Table) Write(f io.Writer) error
- type TableError
Constants ¶
This section is empty.
Variables ¶
var BoolToStringValues = []string{"1", "false", "no", "n"}
BoolToStringValues contains slice of string values that can be auto-translated to boolean
var BoolTrueStringValues = []string{"1", "true", "yes", "y"}
BoolTrueStringValues contains slice of string value that can be auto-translated to true boolean
var StringTranslatableKinds = []reflect.Kind{ reflect.String, reflect.Int, reflect.Int32, reflect.Int64, reflect.Float32, reflect.Float64, reflect.Bool, }
StringTranslatableKinds contains slice of reflect.Kind that can be translated to string
Functions ¶
func ColumnValue ¶
ColumnValue will try to read the value of column as provided data type or else returns fallback value.
$0 : row instance from table $1 : index of the column $2 : fallback value of the type val, err := ColumnValue[T any]($0, $1, $2)
func ColumnValueDecoder ¶
func ColumnValueDecoder(def *Definition, value string) (any, error)
ColumnValueDecoder decodes the column value from string using column definition or with default methods
func ColumnValueEncoder ¶
func ColumnValueEncoder(def *Definition, value any) (string, error)
ColumnValueEncoder encodes the column value to string using definition or with default methods
func ConvertValueType ¶
ConvertValueType converts string to provided type or throws error
func DetectValueType ¶
DetectValueType detects and returns reflect.Type of string value
func JoinAtChar ¶
JoinAtChar joins slice of string to string joined by provided separator and add quotes when needed
$0 : slice of String to join $1 : joining to split the string splits := JoinAtChar($0, $1)
func ReaderToLines ¶
convert data from reader to iterable bytes
func SliceFilter ¶
SliceFilter filters slice values based on filter func
func SliceKeyMap ¶
func SliceKeyMap[T any, L comparable, M any](src []T, cb func(T, int) (L, M)) map[L]M
SliceKeyMap convert slices of T to map of L[M]
func SplitAtChar ¶
SplitAtChar splits string to slice separated by provided separator but respects quotes
$0 : string to split $1 : separator to split the string splits := SplitAtChar($0, $1)
func ToType ¶
ToType reads the reflect.Type from provided value
Types ¶
type ActionAddColumn ¶
type ActionAddColumn[T any] struct { // contains filtered or unexported fields }
func AddColumn ¶
func AddColumn[T any](name string, sample T, cb AddColumnDataReader[T]) *ActionAddColumn[T]
AddColumn adds new column to every rows and resolves column value using callback and generates new table. Generic type of [T any] is applied.
$0 : Column Name $1 : Sample Value of T $2 : func(*framed.State, *framed.Row) T newTable, err := table.Execute( ... framed.AddColumn($0, $1, $2), ... )
func (ActionAddColumn[T]) ActionName ¶
func (a ActionAddColumn[T]) ActionName() string
type ActionChangeColumnType ¶
type ActionChangeColumnType[T any] struct { // contains filtered or unexported fields }
func ChangeColumnType ¶
func ChangeColumnType[T any](name string, sample T, cb ChangeColumnDataReader[T]) *ActionChangeColumnType[T]
ChangeColumnType updates columns on every rows and resolves column value using callback and generates new table. Generic type of [T any] is applied.
$0 : Column Name $1 : Sample Value of T $2 : func(*framed.State, *framed.Row, any) T newTable, err := table.Execute( ... framed.ChangeColumnType($0, $1, $2), ... )
func (ActionChangeColumnType[T]) ActionName ¶
func (a ActionChangeColumnType[T]) ActionName() string
type ActionFilterRow ¶
type ActionFilterRow struct {
// contains filtered or unexported fields
}
func FilterRow ¶
func FilterRow(cb func(*State, *Row) bool) *ActionFilterRow
FilterRow iterates through all rows, filters the rows and build a new table.
newTable, err := table.Execute( ... framed.FilterRow(func(*framed.State, *framed.Row) bool), ... )
func (ActionFilterRow) ActionName ¶
func (a ActionFilterRow) ActionName() string
type ActionModifyRow ¶
type ActionModifyRow struct {
// contains filtered or unexported fields
}
func ModifyRow ¶
func ModifyRow(cb ModifyTableDataReader) *ActionModifyRow
ModifyRow iterates through all rows to modify the row and generates the new table.
newTable, err := table.Execute( ... framed.ModifyRow(func(*State, *Row) *Row), ... )
func (ActionModifyRow) ActionName ¶
func (a ActionModifyRow) ActionName() string
type ActionRenameColumn ¶
type ActionRenameColumn struct {
// contains filtered or unexported fields
}
func RenameColumn ¶
func RenameColumn(name string, newName string) *ActionRenameColumn
RenameColumn renames a column generates the new table.
$0 : Existing Column Name $1 : New Column Name newTable, err := table.Execute( ... framed.RenameColumn($0, $1), ... )
func RenameColumns ¶
func RenameColumns(pairs ...[]string) *ActionRenameColumn
RenameColumns renames multiple columns at once and generates the new table.
newTable, err := table.Execute( ... framed.RenameColumns([]string{"EXISTING_COL_NAME", "NEW_COLUMN_NAME"}, ...), ... )
func (ActionRenameColumn) ActionName ¶
func (a ActionRenameColumn) ActionName() string
type ActionSelection ¶
type ActionSelection struct {
// contains filtered or unexported fields
}
func ColumnSelection ¶
func ColumnSelection(name string, columns ...string) *ActionSelection
func ColumnSelectionCallback ¶
func DropColumn ¶
func DropColumn(columns ...string) *ActionSelection
DropColumn ignores the specified columns and generates the new table.
newTable, err := table.Execute( ... framed.DropColumn("col1", "col2", ...), ... )
func PickColumn ¶
func PickColumn(columns ...string) *ActionSelection
PickColumn plucks the specified columns and generates the new table.
newTable, err := table.Execute( ... framed.PickColumn("col1", "col2", ...), ... )
func (ActionSelection) ActionName ¶
func (a ActionSelection) ActionName() string
type ActionUpdate ¶
type ActionUpdate struct {
// contains filtered or unexported fields
}
func ChangeOptions ¶
func ChangeOptions(cb func(*Table) (*Table, error)) *ActionUpdate
ChangeOptions provides access to current table in pipeline and allows to change options and definitions as required.
newTable, err := table.Execute( ... framed.ChangeOptions(func(*Table) (*Table, error)), ... )
type AddColumnDataReader ¶
type Definition ¶
type Definition struct { Label string Type reflect.Type Encoder func(any) (string, error) Decoder func(string) (any, error) }
Definition defines details and encoder/decoder for values
func NewDefinition ¶
func NewDefinition(tp reflect.Type) *Definition
NewDefinition creates new definition instance with reflect.Type
func (*Definition) Kind ¶
func (d *Definition) Kind() reflect.Kind
Kind returns the reflect.Kind from stored reflect.Type
func (*Definition) WithDecoder ¶
func (d *Definition) WithDecoder(cb func(string) (any, error)) *Definition
WithEncoder updates the decoder to use for data
func (*Definition) WithEncoder ¶
func (d *Definition) WithEncoder(cb func(any) (string, error)) *Definition
WithEncoder updates the encoder to use for data
func (*Definition) WithLabel ¶
func (d *Definition) WithLabel(val string) *Definition
WithLabel changes the label for current definition
type ModifyTableDataReader ¶
type OptionCallback ¶
type OptionCallback = func(*Options)
OptionCallback defines function signature for option builder
func WithColumns ¶
func WithColumns(cols ...string) OptionCallback
func WithDefinition ¶
func WithDefinition(name string, def *Definition) OptionCallback
func WithDefinitionType ¶
func WithDefinitionType(name string, tp reflect.Type) OptionCallback
func WithIgnoreHeader ¶
func WithIgnoreHeader(ih bool) OptionCallback
func WithMaxRows ¶
func WithMaxRows(s int) OptionCallback
func WithSampleSize ¶
func WithSampleSize(s int) OptionCallback
func WithSampling ¶
func WithSampling(s int) OptionCallback
func WithSeparator ¶
func WithSeparator(sep byte) OptionCallback
func WithTypeReader ¶
func WithTypeReader(cb func(int, string) reflect.Type) OptionCallback
type Options ¶
type Options struct { // sample rows count Sampling int // printable sample size SampleSize int // stop import at max defined count MaxRows int // ignore the header line IgnoreHeader bool // column separater character Separator byte // pre-defined columns for table Columns []string // pre-defined column definitions Definitions map[string]*Definition // helper to read column type TypeReader func(int, string) reflect.Type }
Options defines settings for table data
func NewOptions ¶
func NewOptions(ocbs ...OptionCallback) *Options
NewOptions creates option's instance using OptionCallback
type PipelineAction ¶
type PipelineAction interface { // ActionName returns the name of pipeline action ActionName() string // Execute executes the pipeline action Execute(*Table) (*Table, error) }
PipelineAction defines an action interface to modify table rows and options as needed.
type Row ¶
Row holds columns of row in table
func (*Row) Patch ¶
func (r *Row) Patch(def *Definition, idx int, value any) error
Patch attempts to update column value at x index and throws error on type fail
type State ¶
type State struct { // list of table columns Columns []string // indexes of detected columns Indexes IndexCache // resolved column definitions Definitions map[string]*Definition }
current state of table
func (*State) ColumnName ¶
ColumnName retrieves the name of column from index
func (*State) Definition ¶
func (s *State) Definition(name string) *Definition
Definition retrieves the value definition
func (*State) DefinitionAt ¶
func (s *State) DefinitionAt(idx int) *Definition
DefinitionAt retrieves the value definition via index
func (*State) HasDefinition ¶
HasDefinition checks if definition is available
type Table ¶
type Table struct { // slice of table rows Rows []*Row // current state of table State *State // current resolved options for table Options *Options // contains filtered or unexported fields }
func CherryPick ¶
CherryPick selects the columns and assigns new rows for those columns to build new Table
func File ¶
func File(path string, cbs ...OptionCallback) (*Table, error)
File opens file and creates table
func Lines ¶
func Lines(lines []string, cbs ...OptionCallback) (*Table, error)
Lines imports slices of string to create table
func New ¶
func New(ocbs ...OptionCallback) *Table
New creates new Table instance with OptionCallback
func Raw ¶
func Raw(ss [][]string, cbs ...OptionCallback) (*Table, error)
Raw imports slices of raw data to create table
func Reader ¶
func Reader(r io.Reader, cbs ...OptionCallback) (*Table, error)
Reader iterates through io.Reader and creates table
func URL ¶
func URL(uri string, cbs ...OptionCallback) (*Table, error)
URL sends http request to url and creates table
func (*Table) AppendColumn ¶
AppendColumn adds new column to table
func (*Table) Execute ¶
func (t *Table) Execute(actions ...PipelineAction) (*Table, error)
Execute is called by Table when pipeline actions are executed
func (*Table) ExecuteS ¶
func (t *Table) ExecuteS(actions ...PipelineAction) error
ExecuteS runs pipeline actions and dereferences the resulting Table back to self
func (*Table) Initialize ¶
Initialize executes the options on table instance
func (*Table) InsertGenBytes ¶
InsertGenBytes iterates bytes from iterator
func (*Table) InsertLine ¶
InsertLine adds string line as row
func (*Table) InsertLines ¶
InsertLines iterates list of string lines
func (*Table) InsertSlice ¶
InsertSlice adds slice of strings as row
func (*Table) InsertSlices ¶
InsertSlices iterates list of string slice
func (*Table) IsAtMaxLine ¶
IsAtMaxLine checks rows are already at restricted max limit
func (*Table) MarkUnresolved ¶
MarkUnresolved marks table as unresolved
func (*Table) ResolveDefinition ¶
func (t *Table) ResolveDefinition(name string, tp reflect.Type) *Definition
ResolveDefinition stores the column Definition if it doesn't exist
func (*Table) ResolveTypes ¶
ResolveTypes resolves the data types from the column values
func (*Table) ResolveValueDefinition ¶
func (t *Table) ResolveValueDefinition(idx int, name string, value string) *Definition
ResolveValueDefinition detects data type of column value and creates Definition
func (*Table) SetColumns ¶
SetColumns updates the header columns for table
func (*Table) SetDefinition ¶
func (t *Table) SetDefinition(name string, def *Definition) *Definition
SetDefinition assigns Definition for the column
func (*Table) SetIndexes ¶
func (t *Table) SetIndexes(cache IndexCache)
SetIndexes updates the column indexes for table
func (*Table) SetOptions ¶
SetOptions overrides the Options of table
func (*Table) SliceToColumns ¶
SliceToColumns convert slice of values to column slices
func (*Table) UseColumns ¶
UseColumns updates header columns for table
type TableError ¶
defines custom error with details about the table, row and column (if any)
func ColError ¶
ColError will create an error instance with info about row and column index and name(if provided) along with the reason.
$0 : index of row $1 : index of column $2 : name of column $3 : main originating error $4 : reason of the error err := ColError($0, $1, $2, $3, $4)
func NewError ¶
func NewError(err error, reason string) TableError
NewError will create an error instance along with the reason.
$0 : main originating error $1 : reason of the error err := NewError($0, $1, $2, $3, $4)
func RowError ¶
func RowError(idx int, err error, reason string) TableError
RowError will create an error instance with info about row along with the reason.
$0 : index of row $1 : main originating error $2 : reason of the error err := RowError($0, $1, $2, $3, $4)
func (TableError) Error ¶
func (e TableError) Error() string
Source Files
¶
- action_add.go
- action_change_type.go
- action_filter.go
- action_modify.go
- action_rename.go
- action_selection.go
- action_update.go
- column.go
- definition.go
- error.go
- io.go
- options.go
- row.go
- state.go
- table.go
- table_access.go
- table_action.go
- table_clone.go
- table_display.go
- table_input.go
- table_output.go
- table_resolve.go
- table_slice.go
- table_write.go
- typecast.go
- utils.go