Documentation
¶
Overview ¶
Package driver realize data read and write support for different databases(datastore provider)
All driver object must implement IDriver interface to support read/write data for IoT devices As an excellent IoT data engineer, the IoT data storage structure you design should have the following parts: Data collection time, data collection location, [] (data object name, data value) At the same time, in order to comply with the table architecture specifications of the project, we will set the following fields for the stored data: Table ID, Node ID (this is the AgentID set by the user (usually you)) It is also your `data collection location` Data name Time Its format is: (id, node_id, [your dataColumns], ts) You don't need to consider id, nodeId and ts, we have already designed it for you! You just need to make sure that the data object you pass in conforms to the deserializable json object.
Index ¶
- Variables
- func SetRepo(repo repo.ICoreDb)
- type ConNode
- type ConTimeRange
- type ConValRange
- type ConditionOption
- type IDriver
- type IReader
- type IWriter
- type MySql
- func (m *MySql) CreateColumnsWithType(data map[string]string) error
- func (m *MySql) GetData(conditions ...ConditionOption) map[string][]any
- func (*MySql) GetDriverName() string
- func (m *MySql) GetNewDriver(tableName string) IDriver
- func (m *MySql) Insert(data map[string]any) error
- func (m *MySql) Migrate(columns map[string]string) error
- func (m *MySql) SetBatchWriteTxnSize(size int) (int, error)
- func (m *MySql) SetTableName(tableName string)
- func (m *MySql) Write(p []byte) (n int, err error)
- type QueryCondition
- type TDEngine
- func (t *TDEngine) CreateColumnsWithType(data map[string]string) error
- func (t *TDEngine) GetData(conditions ...ConditionOption) map[string][]any
- func (*TDEngine) GetDriverName() string
- func (t *TDEngine) GetNewDriver(tableName string) IDriver
- func (t *TDEngine) Insert(m map[string]any) error
- func (t *TDEngine) Migrate(m map[string]string) error
- func (t *TDEngine) SetBatchWriteTxnSize(size int) (int, error)
- func (t *TDEngine) SetTableName(tableName string)
- func (t *TDEngine) Write(p []byte) (n int, err error)
Constants ¶
This section is empty.
Variables ¶
var ErrWriteTxnSize = errors.New("write txn size should be 1<= size <=100")
Functions ¶
Types ¶
type ConNode ¶
type ConNode struct { NodeName *string // Node name for exact match NodeID *string // Node ID for exact match }
ConNode defines node query conditions. Pointer fields allow empty values, both nil means no node constraint.
type ConTimeRange ¶
type ConTimeRange struct { StartAt *uint64 // Start timestamp in UNIX format (inclusive, closed interval) EndAt *uint64 // End timestamp in UNIX format (inclusive, closed interval) }
ConTimeRange defines time range query conditions. Uses pointers to implement optional fields (nil means no time constraint).
type ConValRange ¶
type ConValRange struct { Key string // Target key name for filtering StartVal *float64 // Minimum value pointer (inclusive, nil means no lower bound) EndVal *float64 // Maximum value pointer (inclusive, nil means no upper bound) }
ConValRange defines value range filter conditions. Used to specify range constraints for specific keys. Support int and float data.
type ConditionOption ¶
type ConditionOption func(driver *QueryCondition)
ConditionOption defines function type for functional option pattern Used to flexibly compose query conditions
func WithNode ¶
func WithNode(nodeName, nodeID string) ConditionOption
WithNode creates a node condition configuration Parameters:
- nodeName: Exact match node name (empty string means not set)
- nodeID: Exact match node ID (empty string means not set)
Creates node condition only when either parameter is non-empty
func WithTimeRange ¶
func WithTimeRange(startAt, endAt uint64) ConditionOption
WithTimeRange creates a time range condition configuration Parameters:
- startAt: UNIX timestamp in seconds (0 means not set)
- endAt: UNIX timestamp in seconds (0 means not set)
Creates time condition only when startAt/endAt are non-zero
func WithValRange ¶
func WithValRange(key string, startVal, endVal float64) ConditionOption
WithValRange creates a value range condition configuration Parameters:
- key: Required key name for filtering
- startVal: Minimum value (inclusive, 0 is considered valid)
- endVal: Maximum value (inclusive, 0 is considered valid)
Appends new condition to existing ValRange slice
type IDriver ¶
type IDriver interface { GetDriverName() string // SetTableName Set write/reader table name SetTableName(tableName string) // GetNewDriver Get a new writer/reader driver GetNewDriver(tableName string) IDriver // CreateColumnsWithType Create columns with type: key is column name, value is column type CreateColumnsWithType(map[string]string) error // SetBatchWriteTxnSize Set batch write transaction size: it should be 1<= size <=100.(default is 1) // if size = 0,it will return currentSize,nil // if size > 100,or size < 1,it will return 0,and error SetBatchWriteTxnSize(size int) (int, error) // Migrate auto migrate table Migrate(map[string]string) error IWriter IReader }
func NewMySQLDriver ¶
type IReader ¶
type IReader interface {
GetData(conditions ...ConditionOption) map[string][]any
}
type MySql ¶
type MySql struct {
// contains filtered or unexported fields
}
func (*MySql) CreateColumnsWithType ¶
func (*MySql) GetDriverName ¶
func (*MySql) GetNewDriver ¶
func (*MySql) SetTableName ¶
type QueryCondition ¶
type QueryCondition struct { *ConTimeRange // Embedded time range condition (optional) *ConNode // Embedded node condition (optional) ValRange []ConValRange // Slice of value range conditions }
QueryCondition represents a collection of query conditions. Contains optional time range, node conditions, and multiple value range filters.
type TDEngine ¶
type TDEngine struct {
// contains filtered or unexported fields
}
func (*TDEngine) CreateColumnsWithType ¶
func (*TDEngine) GetData ¶
func (t *TDEngine) GetData(conditions ...ConditionOption) map[string][]any