Documentation ¶
Index ¶
- func EscapeCondValue(s string, isFieldVal ...bool) string
- func EscapeFieldValue(s string) string
- func EscapeTagTailBackslash(s string) string
- func EscapeTagValue(s string) string
- func FormatMeasurement(s string) string
- func Quote(s string) string
- func QuoteIfNeed(s string) string
- func SingleQuote(s string) string
- func UnescapeQueryResultValue(s string) string
- type Client
- func (this *Client) AlterRetentionPolicy(db string, rp *RetentionPolicy) error
- func (this *Client) Close()
- func (this *Client) CreateDatabase(db string) (bool, error)
- func (this *Client) CreateRetentionPolicy(db string, rp *RetentionPolicy) (bool, error)
- func (this *Client) DropDatabase(db string) error
- func (this *Client) DropMeasurement(db, measurement string) error
- func (this *Client) DropRetentionPolicy(db, rp string) error
- func (this *Client) Flush()
- func (this *Client) NewQuery() *Query
- func (this *Client) Printf(format string, args ...interface{})
- func (this *Client) RawQuery(db, sql string) ([]*Series, error)
- func (this *Client) RawWrite(db, rp string, lines []string) error
- func (this *Client) ShowDatabases() ([]string, error)
- func (this *Client) ShowFieldKeys(db, measurement string) ([]string, error)
- func (this *Client) ShowMeasurements(db string) ([]string, error)
- func (this *Client) ShowRetentionPolicies(db string) ([]*RetentionPolicy, error)
- func (this *Client) ShowSeries(db, measurement string) ([]string, error)
- func (this *Client) ShowTagKeys(db, measurement string) ([]string, error)
- func (this *Client) Write(db, rp string, points []*Point, immediate bool) error
- type ICond
- func And(arr ...ICond) ICond
- func Between(col string, less, more interface{}) ICond
- func BetweenOpen(col string, less, more interface{}) ICond
- func BetweenOpenL(col string, less, more interface{}) ICond
- func BetweenOpenR(col string, less, more interface{}) ICond
- func Expr(col, opr string, val interface{}) ICond
- func In(col string, values ...interface{}) ICond
- func Match(col, pattern string) ICond
- func NewCond() ICond
- func NotIn(col string, values ...interface{}) ICond
- func NotMatch(col, pattern string) ICond
- func Or(arr ...ICond) ICond
- func RawExpr(expr string) ICond
- type Option
- func WithAuth(username, password string) Option
- func WithFlushInterval(interval time.Duration) Option
- func WithFlushSize(size int) Option
- func WithGroupSize(size int) Option
- func WithLogger(logger logs.Logger) Option
- func WithLoggerLevel(level int) Option
- func WithQueryEpoch(epoch string) Option
- func WithWritePoolSize(n int) Option
- func WithWritePrecision(precision string) Option
- func WithWriteSortTagKey(sort bool) Option
- type Point
- type Query
- func (this *Query) Asc(field string) *Query
- func (this *Query) Desc(field string) *Query
- func (this *Query) Do() ([]*Series, error)
- func (this *Query) From(db, rp string, measurements ...string) *Query
- func (this *Query) GroupBy(groupBy string) *Query
- func (this *Query) Limit(limit int) *Query
- func (this *Query) OrderBy(orderBy string) *Query
- func (this *Query) Select(fields ...string) *Query
- func (this *Query) String() string
- func (this *Query) TimeZone(tz string) *Query
- func (this *Query) Where(cond ICond) *Query
- type RetentionPolicy
- type Series
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EscapeCondValue ¶
EscapeCondValue 查询数据时,需要将条件值中部分字符进行转义
由于tag和field写入时转义稍有差别,所以查询条件也需要区分,通常都是用tag字段作为条件,如果是field字段,需要额外指定 isFieldVal=true https://docs.influxdata.com/influxdb/v1/query_language/data_exploration/#string-literals
func EscapeFieldValue ¶
EscapeFieldValue 写入数据时,需要将field值中不合规的字符进行转义
func EscapeTagTailBackslash ¶
EscapeTagTailBackslash 写入数据时,标签字段尾部的反斜杠会对后面的空格进行转义,导致行协议无法正确解析,所以需要额外处理,查询时也需要对齐
func EscapeTagValue ¶
EscapeTagValue 写入数据时,需要将tag字段值中不合规的字符进行转义
行协议:https://docs.influxdata.com/influxdb/v1/write_protocols/line_protocol_reference
func FormatMeasurement ¶
FormatMeasurement 统一measurement命名规范,避免特殊字符
func QuoteIfNeed ¶
QuoteIfNeed 如有必要,给字段的Key加上双引号,否则返回原字符串
https://docs.influxdata.com/influxdb/v1/query_language/explore-data/#quoting
func SingleQuote ¶
SingleQuote 给查询条件值加上单引号
https://docs.influxdata.com/influxdb/v1/troubleshooting/frequently-asked-questions/#when-should-i-single-quote-and-when-should-i-double-quote-in-queries
func UnescapeQueryResultValue ¶
UnescapeQueryResultValue 还原查询结果中tag、field值的转义
写入时(RawWrite除外)tag、field值转义时都移除了前后空格,唯一特殊情况是以反斜杠结尾的tag字段,特殊追加了一个空格,所以查询结果中需要去掉,以保持一致
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) AlterRetentionPolicy ¶
func (this *Client) AlterRetentionPolicy(db string, rp *RetentionPolicy) error
func (*Client) CreateRetentionPolicy ¶
func (this *Client) CreateRetentionPolicy(db string, rp *RetentionPolicy) (bool, error)
func (*Client) DropDatabase ¶
func (*Client) DropMeasurement ¶
func (*Client) DropRetentionPolicy ¶
func (*Client) RawQuery ¶
RawQuery 执行查询语句
- db: 数据库名,也可以在sql语句中指定数据库
- sql: 查询语句,语法参考:https://docs.influxdata.com/influxdb/v1/query_language/explore-data/#the-basic-select-statement
func (*Client) RawWrite ¶
RawWrite 执行写入操作
- db: 数据库名,必须指定
- rp: 保留策略名,为空时使用默认
- lines: 符合influxdb行协议的数据,需自行处理转义
func (*Client) ShowDatabases ¶
func (*Client) ShowFieldKeys ¶
func (*Client) ShowRetentionPolicies ¶
func (this *Client) ShowRetentionPolicies(db string) ([]*RetentionPolicy, error)
func (*Client) ShowSeries ¶
func (*Client) ShowTagKeys ¶
type ICond ¶
func BetweenOpen ¶
func BetweenOpenL ¶
func BetweenOpenR ¶
func Expr ¶
Expr 表达式
- col: 字段名,支持tag字段(包含time)
- opr: 操作符,支持 =, !=, >, <, >=, <=, <>, =~, !~
- val: 字段值,支持数值、字符串
func Match ¶
Match 模糊匹配
https://docs.influxdata.com/influxdb/v1/query_language/explore-data/#regular-expressions !!! 注意:正则表达式匹配性能较差,尽量避免使用 !!!
type Option ¶
type Option func(*Client)
func WithFlushInterval ¶
WithFlushInterval 设置异步写入数据的时间间隔
func WithFlushSize ¶
WithFlushSize 设置异步写入数据的行数上限, 最大不超过 bucketSize
func WithLogger ¶
func WithLoggerLevel ¶
func WithQueryEpoch ¶
WithQueryEpoch 设置查询返回的时间格式, 默认s, 可选值:ns, u, ms, s, m, h
influxdb默认返回的时间是RFC3339格式,如果需要返回时间戳,需要通过epoch参数指定
func WithWritePrecision ¶
WithWritePrecision 设置写入数据的时间精度, 默认s, 可选值:ns, u, ms, s, m, h
func WithWriteSortTagKey ¶
type Point ¶
type Point struct { Measurement string // 表名,必须指定 Tags map[string]interface{} // tag字段 Fields map[string]interface{} // field字段 Time int64 // 时间戳,不传时数据库会自动写入当前时间 }
Point 数据点
注意:写入精度默认为秒,可以通过 WithWritePrecision 设置
func (*Point) ToLineData ¶
ToLineData 转换为行协议数据
行协议:<measurement>[,<tag_key>=<tag_value>[,<tag_key>=<tag_value>]] <field_key>=<field_value>[,<field_key>=<field_value>] [<timestamp>]
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
type RetentionPolicy ¶
type Series ¶
type Series struct { Name string `json:"name,omitempty"` // 表名,多表查询时有用 Tags map[string]string `json:"tags,omitempty"` Columns []string `json:"columns"` Values [][]interface{} `json:"values"` }
func (*Series) ToStringObjectMap ¶
func (this *Series) ToStringObjectMap() []mapUtil.StringObjectMap
ToStringObjectMap converts the Series to a slice of mapUtil.StringObjectMap.
[ {column1: value1, column2: value2, ...}, // row 1 {column1: value1, column2: value2, ...}, // row 2 ... ]