timescale

package
v0.27.2 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CastType

func CastType(iface interface{}) string

Types

type Batch added in v0.23.0

type Batch struct {
	Rows []string
}

type Result

type Result struct {
	Cols    *[]string
	Rows    []*Row
	IsEmpty bool
	First   *Row
	Err     error
}

func (*Result) ToSlice

func (r *Result) ToSlice() []map[string]interface{}

ToSlice ToSlice

type Row

type Row struct {
	Data map[string]interface{}
}

Row contains Data of one Timescale row as a map where map keys are column names.

func (*Row) Get

func (r *Row) Get(field string) *Value

Get data from given column as Value. Returns nil if no data found.

func (*Row) GetDefault

func (r *Row) GetDefault(field string, defaultValue interface{}) *Value

Get data from given column as Value. Returns defaultvalue if no data found.

func (*Row) GetFloat added in v0.23.0

func (r *Row) GetFloat(field string) float64

Get data from given column as float64. Returns NaN if no data found.

func (*Row) GetFloats added in v0.23.0

func (r *Row) GetFloats(blacklist []string) *map[string]float64

Get all convertible data as float64 and return as a map. Blacklist of columns can be given to exclude certain columns.

func (*Row) GetInt added in v0.23.0

func (r *Row) GetInt(field string) int

Get data from given column as int. Returns -1 if no data found.

func (*Row) GetString added in v0.23.0

func (r *Row) GetString(field string) string

Get data from given column as string.

func (*Row) GetStruct added in v0.23.0

func (r *Row) GetStruct(structPointer interface{})

Fills the given struct with data from Timescale row. The struct to be filled is given as a pointer. Function will fill all the struct's fields it finds and leaves the rest of the fields untouched. Thus default values can be set to struct prior to filling it. NOTE: Struct field name must match the timescale column name, except that struct field always needs capital letter

func (*Row) GetTime added in v0.23.0

func (r *Row) GetTime(field string) time.Time

Get data from given column as time.Time.

type Timescale

type Timescale struct {
	DB    *sqlx.DB
	Error string // Error string
	// contains filtered or unexported fields
}

Timescale parameters.

func New

func New(params ...string) (timescale *Timescale)

New Timescale connection.

params[0] = uri (mandatory)
params[1] = appname (optional)

func (*Timescale) BulkInsert

func (ts *Timescale) BulkInsert(table string, data []map[string]interface{})

Insert multiple records

func (*Timescale) Close

func (ts *Timescale) Close() error

Close connection.

func (*Timescale) Connect

func (ts *Timescale) Connect() (err error)

Connect to Timescale. SSL is set as disabled and hostname is used as the application name. In case of not being able to connect, Error string is updated.

func (*Timescale) ExecAndCommit

func (ts *Timescale) ExecAndCommit(query string, args ...interface{}) error

ExecAndCommit ExecAndCommit

func (*Timescale) FindByID

func (ts *Timescale) FindByID(table string, id int) *Result

func (*Timescale) FuncString added in v0.24.0

func (ts *Timescale) FuncString(input string) func() string

FuncString funcstring

func (*Timescale) Get added in v0.24.0

func (ts *Timescale) Get(strc interface{}, query string) error

Get get

func (*Timescale) Insert

func (ts *Timescale) Insert(table string, data map[string]interface{})

Insert single record

func (*Timescale) InsertStruct

func (ts *Timescale) InsertStruct(table string, data interface{})

Insert single struct

func (*Timescale) ProcessBatch added in v0.23.0

func (ts *Timescale) ProcessBatch(b *Batch, copyCmd, splitChar string) (int, error)

Batch processing for fast raw data writing to Timescale. Returns the number of records written and possible error.

func (*Timescale) Query

func (ts *Timescale) Query(query string, data map[string]interface{}) *Result

Query to Result struct

func (*Timescale) QueryByRow added in v0.23.0

func (ts *Timescale) QueryByRow(query string, data map[string]interface{}, fn func(row *Row))

QueryByRow goes through the data row by row with MapScan and executes given function for each row.

func (*Timescale) QuerySelect added in v0.24.0

func (ts *Timescale) QuerySelect(strc interface{}, query string, data map[string]interface{}) error

QuerySelect select

func (*Timescale) Select added in v0.23.0

func (ts *Timescale) Select(dest interface{}, query string) error

Select queries the data to given interface struct

func (*Timescale) Update

func (ts *Timescale) Update(table string, data map[string]interface{}, where string)

Update single record

func (*Timescale) UpdateByID

func (ts *Timescale) UpdateByID(table string, data map[string]interface{}, id int)

type Value

type Value struct {
	Raw interface{}
}

Value struct contains the Raw data of unknown type

func (*Value) AsBool

func (v *Value) AsBool() bool

Returns raw value as boolean.

func (*Value) AsByte

func (v *Value) AsByte() []byte

Returns raw value as byte.

func (*Value) AsFloat

func (v *Value) AsFloat() float64

Returns raw value as float64. Returns NaN if no value.

func (*Value) AsFloats added in v0.23.0

func (v *Value) AsFloats() []float64

func (*Value) AsInt

func (v *Value) AsInt() int

Returns raw value as int. Returns 0 if no value.

func (*Value) AsInt64

func (v *Value) AsInt64() int64

Returns raw value as int64. Returns 0 if no value.

func (*Value) AsInterface

func (v *Value) AsInterface() interface{}

Returns raw value as interface.

func (*Value) AsJSON

func (v *Value) AsJSON(target interface{})

Unmarshals JSON to target.

func (*Value) AsString

func (v *Value) AsString() string

Returns raw value as string

func (*Value) AsTime

func (v *Value) AsTime() time.Time

Returns raw value as time.Time

func (*Value) BinaryToInt

func (v *Value) BinaryToInt() int

Returns raw binary value as int. Returns 0 if no value.

Jump to

Keyboard shortcuts

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