Documentation ¶
Overview ¶
Package eskuel provides a way to easily manipulate rows of data à la SQL.
Index ¶
- Variables
- type CSVReader
- type Column
- type Row
- type SubTable
- type Table
- func (t *Table) ColumnAppend(f func(Row), columns ...Column)
- func (t *Table) ColumnMove(col Column, pos int)
- func (t *Table) ColumnRemove(columns ...Column)
- func (t *Table) Columns() []Column
- func (t *Table) Count() int
- func (t *Table) Delete(sub *SubTable, f func(r Row) (delete bool)) int
- func (t *Table) FindRow(f func(Row) bool) Row
- func (t *Table) FromCSV(from CSVReader) error
- func (t *Table) FromView(v *View)
- func (t *Table) Group(sub *SubTable, gt *Table, trans func(in, out Row))
- func (t *Table) Insert(rows ...Row)
- func (t *Table) JoinFull(on *Table, subon *SubTable, f func(r, on Row) bool) *Table
- func (t *Table) JoinInner(on *Table, subon *SubTable, f func(r, on Row) bool) *Table
- func (t *Table) JoinLeft(on *Table, subon *SubTable, f func(r, on Row) bool) *Table
- func (t *Table) JoinOuterLeft(on *Table, subon *SubTable, f func(r, on Row) bool) *Table
- func (t *Table) MarshalText() (text []byte, err error)
- func (t *Table) Row() Row
- func (t *Table) Rows() []Row
- func (t *Table) Select(f func(Row) bool, schema ...ViewColumn) *View
- func (t *Table) Slice(i int, j int) *Table
- func (t *Table) Sort(less func(a, b Row) bool)
- func (t *Table) ToCSV(w io.Writer) error
- func (t *Table) UnionWith(tt *Table)
- func (t *Table) UnmarshalText(text []byte) error
- func (t *Table) Update(sub *SubTable, f func(r Row) (stop bool)) int
- type Value
- type View
- type ViewColumn
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Null = Value{^0, "NULL"}
Null defines the NULL value.
Functions ¶
This section is empty.
Types ¶
type CSVReader ¶
CSVReader is the interface used to parse CSV data (also supported by encoding/csv.Reader).
type Column ¶
type Column struct { // Name uniquely identifies a Column. Name string // Key defines if the column is part of the table key. // Rows are uniquely identified by the combination of // all column keys. Key bool // Column position in the schema. Automatically set. Position int // StringValue defines the methods to marshal and unmarshal a string // from and to a Value. They are typically used when processing CSV // data but there is no restriction on their usage. // The interface carries across a modified Table such as Table.Select. StringValue interface { MarshalString(Value) (string, error) UnmarshalString(string) (Value, error) } }
Column defines a table column.
type SubTable ¶
type SubTable struct {
// contains filtered or unexported fields
}
SubTable is a subset of a table columns. Its data is backed by the table's. A nil SubTable behaves as a Table. It is used to only supply the relevant columns when manipulating the table data, yielding better performance.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table holds a set of Rows.
func New ¶
New instantiates a new table with the supplied schema. An empty schema panics.
Example ¶
package main import ( "fmt" "git.sr.ht/~pierrec/eskuel" "git.sr.ht/~pierrec/eskuel/values" ) func main() { intCol := eskuel.Column{Name: "id", StringValue: values.Int64{}} strCol := eskuel.Column{Name: "name", StringValue: values.String{}} tab := eskuel.New(intCol, strCol) tab.Insert( eskuel.Row{{Int: 1}, {String: "a"}}, eskuel.Row{{Int: 2}, {String: "b"}}, ) for _, r := range tab.Rows() { fmt.Println(r[0].Int, r[1].String) } }
Output: 1 a 2 b
func NewFromCSV ¶
NewFromCSV creates a table populated with the data from the csv source. The first line of the csv data must contain the table schema. The init function is used to setup the Column's StringValue interface. It can be left nil if the StringValue interface does not need to be instantiated.
See Table.FromCSV for usage.
func (*Table) ColumnAppend ¶
ColumnAppend appends a set of new columns to the table's schema. Use ColumnMove to place them at the desired locations. Values for the new column are set by f or to Null if f is nil.
Rows having duplicate keys are deleted, only one of them being kept.
func (*Table) ColumnMove ¶
ColumnMove moves col to a new position. If pos < 0, then the column is moved at the front. If pos > len(Columns), then the column is moved at the end.
func (*Table) ColumnRemove ¶
ColumnRemove removes the provided columns from t. If all columns get removed, the table schema is left unchanged.
func (*Table) Delete ¶
Delete removes rows in t matched by f and returns the number of deleted rows. Note that row order is not preserved.
func (*Table) FromCSV ¶
FromCSV adds rows to t provided by the csv reader. Strings "NULL", "null" and "Null" are only converted to Null if the StringValue for the column being read is not set.
func (*Table) JoinOuterLeft ¶
JoinOuterLeft returns the outer left joined table of t and on.
func (*Table) MarshalText ¶
func (*Table) Select ¶
func (t *Table) Select(f func(Row) bool, schema ...ViewColumn) *View
Select returns a view on the table. An empty schema selects all columns from the table. Use f to filter rows. If unset, all rows are selected. If schema is empty, all columns from t are selected, unchanged.
func (*Table) UnionWith ¶
UnionWith merges the data from tt into t.
t and tt must have the same schema (same column length and names) leaving t unchanged if that is not the case.
Example ¶
package main import ( "fmt" "git.sr.ht/~pierrec/eskuel" ) func main() { // UnionWith can be used to make a full copy of tab. columns := []eskuel.Column{{Name: "c1"}, {Name: "c2"}} tab := eskuel.New(columns...) tab.Insert( eskuel.Row{{Int: 1}, {String: "a"}}, eskuel.Row{{Int: 2}, {String: "b"}}, ) dup := eskuel.New(columns...) dup.UnionWith(tab) for _, r := range dup.Rows() { fmt.Println(r[0].Int, r[1].String) } }
Output: 1 a 2 b
func (*Table) UnmarshalText ¶
type Value ¶
type Value struct { Int int64 // Int is used to store 8 bytes, typically a number. String string // String is used to store everything else. }
Value stores a row column value in one of the required type.
NB. no type checking is performed on columns.
type View ¶
type View struct {
// contains filtered or unexported fields
}
type ViewColumn ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
examples
|
|
csv
Parse an unconventional CSV data file into a table.
|
Parse an unconventional CSV data file into a table. |
join
Joining data from 2 tables.
|
Joining data from 2 tables. |
Package values provides typical implementations of eskuel.Value marshaller interface.
|
Package values provides typical implementations of eskuel.Value marshaller interface. |