retsu

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: MIT Imports: 10 Imported by: 0

README

retsu 列

A library to provide convenience functions for column

Sample Usage

type testObj struct {
	Index int    `json:"index"`
	Str   string `json:"str"`
}

// create new collection
col := column.NewCollection()

// add columns from struct
csvCols, err := StructToCols[testObj](col, "json")
if err != nil {
	return err
}

// add data
col.Query(func(txn *column.Txn) error {
  t := testObj{
    Index: 1,
    Str: "1",
  }
  // insert row based on struct
  txn.Insert(InsertStruct(&t, "json"))
  return nil
})

// save deep snapshot
if err := SaveDeepSnapshotFile(col, csvCols, "deep_snapshot.snappy"); err != nil {
	return err
}

---

// load deep snapshot
savedCol, savedCSVCols, err := LoadDeepSnapshotFile("deep_snapshot.snappy")
if err != nil {
	return err
}

Benchmarks

cpu: AMD Ryzen 9 5900X 12-Core Processor            
BenchmarkSnapshot/raw-24         	      57	  19821002 ns/op	12077931 B/op	     457 allocs/op
BenchmarkSnapshot/basic-24       	      61	  19677610 ns/op	13691278 B/op	     524 allocs/op
BenchmarkSnapshot/deep-24        	      55	  21546802 ns/op	23765586 B/op	     555 allocs/op

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecWhenSettable

func ExecWhenSettable[T any](input *T, structTag string, f func(string, reflect.Value) error) error

ExecWhenSettable executes a function on a reflect.Value when it's settable

func GetValue

func GetValue(val reflect.Value) (any, error)

GetValue attempts to get underlying of given reflect.Value

func InsertStruct

func InsertStruct[T any](input *T, structTag string) func(r column.Row) error

InsertStruct converts a given struct to a row Fields must be tagged with `col`

func LoadBasicSnapshot

func LoadBasicSnapshot(col *column.Collection, r io.Reader) error

LoadBasicSnapshot takes a collection and loads a basic snapshot (only data, no columns) Reads from given reader using s2 decompression

func LoadBasicSnapshotFile

func LoadBasicSnapshotFile(col *column.Collection, filepath string) error

LoadBasicSnapshotFile takes a collection and loads a basic snapshot (only data, no columns) Loads it from the given filepath using s2 decompression

func LoadDeepSnapshot

func LoadDeepSnapshot(r io.Reader) (*column.Collection, map[string]any, error)

LoadDeepSnapshot takes a collection and loads a deep snapshot (data + columns) Reads from given reader using gob decoding + s2 decompression

func LoadDeepSnapshotFile

func LoadDeepSnapshotFile(filepath string) (*column.Collection, map[string]any, error)

LoadDeepSnapshotFile takes a collection and loads a deep snapshot (data + columns) Loads it from the given filepath using gob decoding + s2 decompression

func SaveBasicSnapshot

func SaveBasicSnapshot(col *column.Collection, w io.Writer) error

SaveBasicSnapshot takes a collection and creates a basic snapshot (only data, no columns) Writes to given writer using s2 compression

func SaveBasicSnapshotFile

func SaveBasicSnapshotFile(col *column.Collection, filepath string) error

SaveBasicSnapshotFile takes a collection and creates a basic snapshot (only data, no columns) Saves it to filepath using s2 compression

func SaveDeepSnapshot

func SaveDeepSnapshot(col *column.Collection, csvCols map[string]any, w io.Writer) error

SaveDeepSnapshot takes a collection and creates a deep snapshot (data + columns) Writes to given writer using gob encoding + s2 compression

func SaveDeepSnapshotFile

func SaveDeepSnapshotFile(col *column.Collection, csvCols map[string]any, filepath string) error

SaveDeepSnapshotFile takes a collection and creates a deep snapshot (data + columns) Saves it to filepath using gob encoding + s2 compression

func SetValue

func SetValue(r column.Row, val reflect.Value, colName string) error

SetValue creates a row for a specified reflect.Value

func StructToCols

func StructToCols[T any](col *column.Collection, structTag string) (map[string]any, error)

StructToCols converts a given struct to columns Fields must be tagged with given structTag

func StructToColsDirect

func StructToColsDirect[T any](col *column.Collection, structTag string) error

StructToColsDirect converts a given struct to columns Fields must be tagged with given structTag

func StructToColsMap

func StructToColsMap[T any](structTag string) (map[string]any, error)

StructToColsMap converts a given struct to map of column name to value Fields must be tagged with given structTag

Types

type DeepSnapshot

type DeepSnapshot struct {
	CSVCols map[string]any
	Data    []byte
}

DeepSnapshot struct to hold csv column data and collection data

func (DeepSnapshot) ToCollection

func (d DeepSnapshot) ToCollection() (*column.Collection, map[string]any, error)

ToCollection converts the deep snapshot back into a collection + columns

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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