Skip to content

Commit

Permalink
feat: add point and query result struct (openGemini#14)
Browse files Browse the repository at this point in the history
Signed-off-by: ZhangJian He <shoothzj@gmail.com>
  • Loading branch information
ZhangJian He authored Nov 23, 2023
1 parent 67526e5 commit ad23261
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
45 changes: 45 additions & 0 deletions opengemini/point.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package opengemini

import "time"

type Point struct {
Measurement string
Precision string
Time time.Time
Tags map[string]string
Fields map[string]interface{}
}

func (p *Point) AddTag(key string, value string) {
if p.Tags == nil {
p.Tags = make(map[string]string)
}
p.Tags[key] = value
}

func (p *Point) AddField(key string, value interface{}) {
if p.Fields == nil {
p.Fields = make(map[string]interface{})
}
p.Fields[key] = value
}

func (p *Point) SetTime(t time.Time) {
p.Time = t
}

func (p *Point) SetPrecision(precision string) {
p.Precision = precision
}

func (p *Point) SetMeasurement(name string) {
p.Measurement = name
}

type BatchPoints struct {
Points []*Point
}

func (bp *BatchPoints) AddPoint(p *Point) {
bp.Points = append(bp.Points, p)
}
13 changes: 13 additions & 0 deletions opengemini/query_result.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package opengemini

// SeriesResult contains the results of a series query
type SeriesResult struct {
Series []Series `json:"series,omitempty"`
Error string `json:"error,omitempty"`
}

// QueryResult is the top-level struct
type QueryResult struct {
Results []SeriesResult `json:"results,omitempty"`
Error string `json:"error,omitempty"`
}
9 changes: 9 additions & 0 deletions opengemini/series.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package opengemini

// Series defines the structure for series data
type Series struct {
Name string `json:"name,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
Columns []string `json:"columns,omitempty"`
Values [][]interface{} `json:"values,omitempty"`
}

0 comments on commit ad23261

Please sign in to comment.