Skip to content
github-actions[bot] edited this page Apr 2, 2026 · 7 revisions

db

import "github.com/AarC10/GSW-V2/lib/db"

Index

func CreateQuery

func CreateQuery(measurements MeasurementGroup) string

CreateQuery generates InfluxDB query for measurement group

type BatchHandler

BatchHandler extends Handler with batch write support

type BatchHandler interface {
    Handler
    Flush() error
}

type Handler

Handler is an interface for database access implementations

type Handler interface {
    // Insert sends the measurement data to the database.
    Insert(measurements MeasurementGroup) error
    // CreateQuery generates the database query for measurementGroup.
    CreateQuery(measurements MeasurementGroup) string
    // Close closes the database client when done.
    Close() error
}

type InfluxDBV1Config

InfluxDBV1Config holds the fields needed for UDP writes.

type InfluxDBV1Config struct {
    Host string
    Port int
}

type InfluxDBV1Handler

InfluxDBV1Handler is a DB Handler implementation for InfluxDB v1

type InfluxDBV1Handler struct {
    // contains filtered or unexported fields
}

func (*InfluxDBV1Handler) Close

func (h *InfluxDBV1Handler) Close() error

Close closes the InfluxDB UDP client when done

func (*InfluxDBV1Handler) CreateQuery

func (h *InfluxDBV1Handler) CreateQuery(measurements MeasurementGroup) string

CreateQuery generates InfluxDB query for measurement group

func (*InfluxDBV1Handler) Initialize

func (h *InfluxDBV1Handler) Initialize(host string, port int) error

Initialize sets up the InfluxDB UDP connection

func (*InfluxDBV1Handler) InitializeWithConfig

func (h *InfluxDBV1Handler) InitializeWithConfig(cfg InfluxDBV1Config) error

InitializeWithConfig sets up the InfluxDB UDP connection.

func (*InfluxDBV1Handler) Insert

func (h *InfluxDBV1Handler) Insert(measurements MeasurementGroup) error

Insert sends the measurement group data to InfluxDB using UDP

type InfluxDBV2Config

InfluxDBV2Config holds the fields needed by the InfluxDB v2 client.

type InfluxDBV2Config struct {
    URL           string
    Token         string
    Org           string
    Bucket        string
    BatchSize     uint
    FlushInterval uint
    Precision     Precision
}

type InfluxDBV2Handler

InfluxDBV2Handler is a BatchHandler implementation for InfluxDB v1

type InfluxDBV2Handler struct {
    // contains filtered or unexported fields
}

func (*InfluxDBV2Handler) BlockingInsert

func (handler *InfluxDBV2Handler) BlockingInsert(ctx context.Context, measurements MeasurementGroup) error

BlockingInsert writes a point using the blocking write API.

func (*InfluxDBV2Handler) Close

func (handler *InfluxDBV2Handler) Close() error

Close flushes pending writes and closes the client.

func (*InfluxDBV2Handler) CreateQuery

func (handler *InfluxDBV2Handler) CreateQuery(_ MeasurementGroup) string

CreateQuery generates InfluxDB line protocol for a MeasurementGroup. This is literally useless so just return nothing.

func (*InfluxDBV2Handler) Flush

func (handler *InfluxDBV2Handler) Flush() error

Flush forces all buffered points to be sent immediately.

func (*InfluxDBV2Handler) Initialize

func (handler *InfluxDBV2Handler) Initialize(host string, port int) error

Initialize satisfies the Handler interface using host/port only. This is a wrapper around InitializeWithConfig that fills in the URL and leaves.

func (*InfluxDBV2Handler) InitializeWithConfig

func (handler *InfluxDBV2Handler) InitializeWithConfig(cfg InfluxDBV2Config) error

InitializeWithConfig sets up the InfluxDB v2 client with full config.

func (*InfluxDBV2Handler) Insert

func (handler *InfluxDBV2Handler) Insert(measurements MeasurementGroup) error

Insert writes a MeasurementGroup to InfluxDB v2 as a single point. The write is buffered and flushed based on batch size and flush interval.

func (*InfluxDBV2Handler) InsertBatch

func (handler *InfluxDBV2Handler) InsertBatch(batch []MeasurementGroup) error

InsertBatch writes multiple MeasurementGroups in one shot and flushes.

type Measurement

Measurement is a single measurement to be sent to the database

type Measurement struct {
    Name  string // Name of the measurement
    Value string // Value of the measurement
}

type MeasurementGroup

MeasurementGroup is a group of measurements to be sent to the database

type MeasurementGroup struct {
    DatabaseName string        // Name of the database
    Timestamp    int64         // Unix timestamp in nanoseconds
    Measurements []Measurement // List of measurements to be sent
}

type Precision

Precision constrains write precision to values supported by InfluxDB.

type Precision string

const (
    PrecisionNS Precision = "ns"
    PrecisionUS Precision = "us"
    PrecisionMS Precision = "ms"
    PrecisionS  Precision = "s"
)

func ParsePrecision

func ParsePrecision(raw string) (Precision, error)

ParsePrecision normalizes and validates config precision values.

func (Precision) Duration

func (p Precision) Duration() (time.Duration, error)

Duration maps precision values to the influx client write precision option.

Generated by gomarkdoc