table

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2017 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CastAll

func CastAll(iter Iterator, out interface{}) error

CastAll loads and casts all rows returned by the iterator to schema types.

The result argument must necessarily be the address for a slice. The slice may be nil or previously allocated.

Types

type Iterator

type Iterator interface {
	// Next advances the table interator to the next row, which will be available through the Cast or Row methods.
	// It returns false when the iterator stops, either by reaching the end of the table or an error.
	// After Next returns false, the Err method will return any error that ocurred during the iteration, except if it was io.EOF, Err
	// will return nil.
	// Next could automatically buffer some data, improving reading performance. It could also block, if necessary.
	Next() bool

	// CastRow casts the most recent row fetched by a call to Next. Cast will error if the table has no schema
	// associateed to it of if the row can not be cast to its respective schema. More at Schema.CastRow.
	CastRow(out interface{}) error

	// Row returns the most recent row fetched by a call to Next as a newly allocated string slice
	// holding its fields.
	Row() []string

	// Err returns nil if no errors happened during iteration, or the actual error
	// otherwise.
	Err() error
}

Iterator is an interface which provides method to interating over tabular data. It is heavly inspired by bufio.Scanner.

type Table

type Table interface {
	// Iter returns an Iterator to read the table. Iter returns an error
	// if the table physical source can not be iterated.
	Iter() (Iterator, error)

	// Infer tries to infer a suitable schema for the table.
	Infer() error

	// CastAll loads and casts all rows of the table to schema types. The table
	// schema must be previously assigned or inferred.
	//
	// The result argument must necessarily be the address for a slice. The slice
	// may be nil or previously allocated.
	CastAll(out interface{}) error

	// All returns all rows of the table.
	All() ([][]string, error)
}

Table makes it easy to deal with physical tabular data.

Jump to

Keyboard shortcuts

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