Documentation ¶
Overview ¶
Package influxdb3 provides client for InfluxDB server.
Index ¶
- Variables
- func ReplaceURLProtocolWithPort(url string) (string, *bool)
- type Client
- func (c *Client) Close() error
- func (c *Client) Query(ctx context.Context, query string, options ...QueryOption) (*QueryIterator, error)
- func (c *Client) QueryWithOptions(ctx context.Context, options *QueryOptions, query string) (*QueryIterator, error)deprecated
- func (c *Client) QueryWithParameters(ctx context.Context, query string, parameters QueryParameters, ...) (*QueryIterator, error)
- func (c *Client) Write(ctx context.Context, buff []byte, options ...WriteOption) error
- func (c *Client) WriteData(ctx context.Context, points []interface{}, options ...WriteOption) error
- func (c *Client) WriteDataWithOptions(ctx context.Context, options *WriteOptions, points ...interface{}) errordeprecated
- func (c *Client) WritePoints(ctx context.Context, points []*Point, options ...WriteOption) error
- func (c *Client) WritePointsWithOptions(ctx context.Context, options *WriteOptions, points ...*Point) errordeprecated
- func (c *Client) WriteWithOptions(ctx context.Context, options *WriteOptions, buff []byte) errordeprecated
- type ClientConfig
- type Option
- type Point
- func (p *Point) Copy() *Point
- func (p *Point) GetBooleanField(name string) *bool
- func (p *Point) GetDoubleField(name string) *float64
- func (p *Point) GetField(name string) interface{}
- func (p *Point) GetFieldNames() []string
- func (p *Point) GetIntegerField(name string) *int64
- func (p *Point) GetMeasurement() string
- func (p *Point) GetStringField(name string) *string
- func (p *Point) GetTag(name string) (string, bool)
- func (p *Point) GetTagNames() []string
- func (p *Point) GetUIntegerField(name string) *uint64
- func (p *Point) HasFields() bool
- func (p *Point) MarshalBinary(precision lineprotocol.Precision) ([]byte, error)
- func (p *Point) MarshalBinaryWithDefaultTags(precision lineprotocol.Precision, defaultTags map[string]string) ([]byte, error)
- func (p *Point) RemoveField(name string) *Point
- func (p *Point) RemoveTag(name string) *Point
- func (p *Point) SetBooleanField(name string, value bool) *Point
- func (p *Point) SetDoubleField(name string, value float64) *Point
- func (p *Point) SetField(name string, value interface{}) *Point
- func (p *Point) SetIntegerField(name string, value int64) *Point
- func (p *Point) SetMeasurement(measurementName string) *Point
- func (p *Point) SetStringField(name string, value string) *Point
- func (p *Point) SetTag(name string, value string) *Point
- func (p *Point) SetTimestamp(timestamp time.Time) *Point
- func (p *Point) SetTimestampWithEpoch(timestamp int64) *Point
- func (p *Point) SetUIntegerField(name string, value uint64) *Point
- type PointValues
- func (pv *PointValues) AsPoint() (*Point, error)
- func (pv *PointValues) AsPointWithMeasurement(measurement string) (*Point, error)
- func (pv *PointValues) Copy() *PointValues
- func (pv *PointValues) GetBooleanField(name string) *bool
- func (pv *PointValues) GetDoubleField(name string) *float64
- func (pv *PointValues) GetField(name string) interface{}
- func (pv *PointValues) GetFieldNames() []string
- func (pv *PointValues) GetIntegerField(name string) *int64
- func (pv *PointValues) GetMeasurement() string
- func (pv *PointValues) GetStringField(name string) *string
- func (pv *PointValues) GetTag(name string) (string, bool)
- func (pv *PointValues) GetTagNames() []string
- func (pv *PointValues) GetUIntegerField(name string) *uint64
- func (pv *PointValues) HasFields() bool
- func (pv *PointValues) RemoveField(name string) *PointValues
- func (pv *PointValues) RemoveTag(name string) *PointValues
- func (pv *PointValues) SetBooleanField(name string, value bool) *PointValues
- func (pv *PointValues) SetDoubleField(name string, value float64) *PointValues
- func (pv *PointValues) SetField(name string, value interface{}) *PointValues
- func (pv *PointValues) SetIntegerField(name string, value int64) *PointValues
- func (pv *PointValues) SetMeasurement(measurementName string) *PointValues
- func (pv *PointValues) SetStringField(name string, value string) *PointValues
- func (pv *PointValues) SetTag(name string, value string) *PointValues
- func (pv *PointValues) SetTimestamp(timestamp time.Time) *PointValues
- func (pv *PointValues) SetTimestampWithEpoch(timestamp int64) *PointValues
- func (pv *PointValues) SetUIntegerField(name string, value uint64) *PointValues
- type QueryIterator
- type QueryOption
- type QueryOptions
- type QueryParameters
- type QueryType
- type ServerError
- type WriteOption
- type WriteOptions
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultQueryOptions = QueryOptions{ QueryType: SQL, }
DefaultQueryOptions specifies default query options
var DefaultWriteOptions = WriteOptions{ Precision: lineprotocol.Nanosecond, GzipThreshold: 1_000, }
DefaultWriteOptions specifies default write options
Functions ¶
func ReplaceURLProtocolWithPort ¶
ReplaceURLProtocolWithPort removes the "http://" or "https://" protocol from the given URL and replaces it with the port number. Currently, Apache Arrow does not support the "http://" or "https://" protocol in the URL, so this function is used to remove it. If a port number is already present in the URL, only the protocol is removed. The function also returns a boolean value indicating whether the communication is safe or unsafe. - If the URL starts with "https://", the communication is considered safe, and the returned boolean value will be true. - If the URL starts with "http://", the communication is considered unsafe, and the returned boolean value will be false. - If the URL does not start with either "http://" or "https://", the returned boolean value will be nil.
Parameters:
- url: The URL to process.
Returns:
- The modified URL with the protocol replaced by the port.
- A boolean value indicating the safety of communication (true for safe, false for unsafe) or nil if not detected.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements an InfluxDB client.
func New ¶
func New(config ClientConfig) (*Client, error)
New creates new Client with given config, where `Host` and `Token` are mandatory.
Example ¶
client, err := New(ClientConfig{ Host: "https://us-east-1-1.aws.cloud2.influxdata.com", Token: "my-token", Database: "my-database", }) if err != nil { log.Fatal(err) } defer client.Close()
Output:
func NewFromConnectionString ¶ added in v0.3.0
NewFromConnectionString creates new Client from the specified connection string. Parameters:
- connectionString: connection string in URL format.
Supported query parameters:
- token - authentication token (required)
- org - organization name
- database - database (bucket) name
- precision - timestamp precision when writing data
- gzipThreshold - payload size threshold for gzipping data
Example ¶
client, err := NewFromConnectionString("https://us-east-1-1.aws.cloud2.influxdata.com/?token=my-token&database=my-database") if err != nil { log.Fatal(err) } defer client.Close()
Output:
func NewFromEnv ¶ added in v0.3.0
NewFromEnv creates new Client instance from environment variables. Supported variables:
- INFLUX_HOST - cloud/server URL (required)
- INFLUX_TOKEN - authentication token (required)
- INFLUX_ORG - organization name
- INFLUX_DATABASE - database (bucket) name
- INFLUX_PRECISION - timestamp precision when writing data
- INFLUX_GZIP_THRESHOLD - payload size threshold for gzipping data
Example ¶
client, err := NewFromEnv() if err != nil { log.Fatal(err) } defer client.Close()
Output:
func (*Client) Query ¶
func (c *Client) Query(ctx context.Context, query string, options ...QueryOption) (*QueryIterator, error)
Query queries data from InfluxDB IOx. Parameters:
- ctx: The context.Context to use for the request.
- query: The query string to execute.
- options: The optional query options. See QueryOption for available options.
Returns:
- A custom iterator (*QueryIterator).
- An error, if any.
Example ¶
client, err := NewFromEnv() if err != nil { log.Fatal(err) } defer client.Close() // query iterator, err := client.Query(context.Background(), "SELECT count(*) FROM weather WHERE time >= now() - interval '5 minutes'") for iterator.Next() { // process the result } // query with custom header iterator, err = client.Query(context.Background(), "SELECT count(*) FROM stat WHERE time >= now() - interval '5 minutes'", WithHeader("X-trace-ID", "#0122")) for iterator.Next() { // process the result }
Output:
func (*Client) QueryWithOptions
deprecated
func (c *Client) QueryWithOptions(ctx context.Context, options *QueryOptions, query string) (*QueryIterator, error)
QueryWithOptions Query data from InfluxDB IOx with query options. Parameters:
- ctx: The context.Context to use for the request.
- options: Query options (query type, optional database).
- query: The query string to execute.
Returns:
- A custom iterator (*QueryIterator) that can also be used to get raw flightsql reader.
- An error, if any.
Deprecated: use Query with variadic QueryOption options.
func (*Client) QueryWithParameters ¶ added in v0.6.0
func (c *Client) QueryWithParameters(ctx context.Context, query string, parameters QueryParameters, options ...QueryOption) (*QueryIterator, error)
QueryWithParameters queries data from InfluxDB IOx with parameterized query. Parameters:
- ctx: The context.Context to use for the request.
- query: The query string to execute.
- parameters: The query parameters.
- options: The optional query options. See QueryOption for available options.
Returns:
- A custom iterator (*QueryIterator).
- An error, if any.
Example ¶
client, err := NewFromEnv() if err != nil { log.Fatal(err) } defer client.Close() // query iterator, err := client.QueryWithParameters(context.Background(), "SELECT count(*) FROM weather WHERE location = $location AND time >= now() - interval '5 minutes'", QueryParameters{ "location": "sun-valley-1", }) for iterator.Next() { // process the result } // query with custom header iterator, err = client.QueryWithParameters(context.Background(), "SELECT count(*) FROM weather WHERE location = $location AND time >= now() - interval '5 minutes'", QueryParameters{ "location": "sun-valley-1", }, WithHeader("X-trace-ID", "#0122")) for iterator.Next() { // process the result }
Output:
func (*Client) Write ¶
Write writes line protocol record(s) to the server into the given database. Multiple records must be separated by the new line character (\n). The data is written synchronously.
Parameters:
- ctx: The context.Context to use for the request.
- buff: The line protocol record(s) to write.
- options: Optional write options. See WriteOption for available options.
Returns:
- An error, if any.
Example ¶
client, err := NewFromEnv() if err != nil { log.Fatal() } defer client.Close() l0 := "cpu,host=localhost usage_user=16.75" l1 := "cpu,host=gw usage_user=2.90" data := []byte(strings.Join([]string{l0, l1}, "\n")) // write line protocol err = client.Write(context.Background(), data) if err != nil { log.Fatal() } // write line protocol with options err = client.Write(context.Background(), data, WithDatabase("another-database"), WithGzipThreshold(64)) if err != nil { log.Fatal() }
Output:
func (*Client) WriteData ¶
func (c *Client) WriteData(ctx context.Context, points []interface{}, options ...WriteOption) error
WriteData encodes fields of custom points into line protocol and writes line protocol record(s) to the server into the given database. Each custom point must be annotated with 'lp' prefix and Values measurement, tag, field, or timestamp. A valid point must contain a measurement and at least one field. The points are written synchronously.
A field with a timestamp must be of type time.Time.
Parameters:
- ctx: The context.Context to use for the request.
- points: The custom points to encode and write.
- options: Optional write options. See WriteOption for available options.
Returns:
- An error, if any.
Example ¶
type AirSensor struct { Measurement string `lp:"measurement"` Sensor string `lp:"tag,sensor"` ID string `lp:"tag,device_id"` Temp float64 `lp:"field,temperature"` Hum int `lp:"field,humidity"` Time time.Time `lp:"timestamp"` Description string `lp:"-"` } client, err := NewFromEnv() if err != nil { log.Fatal() } defer client.Close() p0 := AirSensor{ "air", "SHT31", "10", 23.5, 55, time.Now(), "Room temp", } points := []any{&p0} // write points err = client.WriteData(context.Background(), points) if err != nil { log.Fatal() } // write points with options err = client.WriteData(context.Background(), points, WithDefaultTags(map[string]string{ "version": "0.1", })) if err != nil { log.Fatal() }
Output:
func (*Client) WriteDataWithOptions
deprecated
func (c *Client) WriteDataWithOptions(ctx context.Context, options *WriteOptions, points ...interface{}) error
WriteDataWithOptions encodes fields of custom points into line protocol and writes line protocol record(s) to the server into the given database. Each custom point must be annotated with 'lp' prefix and Values measurement, tag, field, or timestamp. A valid point must contain a measurement and at least one field. The points are written synchronously.
A field with a timestamp must be of type time.Time.
Parameters:
- ctx: The context.Context to use for the request.
- points: The custom points to encode and write.
- options: Write options.
Returns:
- An error, if any.
Deprecated: use WriteData with variadic WriteOption option
func (*Client) WritePoints ¶
WritePoints writes all the given points to the server into the given database. The data is written synchronously.
Parameters:
- ctx: The context.Context to use for the request.
- points: The points to write.
- options: Optional write options. See WriteOption for available options.
Returns:
- An error, if any.
Example ¶
client, err := NewFromEnv() if err != nil { log.Fatal() } defer client.Close() p0 := NewPointWithMeasurement("cpu") p0.SetTag("host", "localhost") p0.SetField("usage_user", 16.75) p0.SetTimestamp(time.Now()) points := []*Point{p0} // write points err = client.WritePoints(context.Background(), points) if err != nil { log.Fatal() } // write points with options err = client.WritePoints(context.Background(), points, WithPrecision(lineprotocol.Second)) if err != nil { log.Fatal() }
Output:
func (*Client) WritePointsWithOptions
deprecated
func (c *Client) WritePointsWithOptions(ctx context.Context, options *WriteOptions, points ...*Point) error
WritePointsWithOptions writes all the given points to the server into the given database. The data is written synchronously.
Parameters:
- ctx: The context.Context to use for the request.
- points: The points to write.
- options: Write options.
Returns:
- An error, if any.
Deprecated: use WritePoints with variadic WriteOption options.
func (*Client) WriteWithOptions
deprecated
WriteWithOptions writes line protocol record(s) to the server into the given database. Multiple records must be separated by the new line character (\n). The data is written synchronously.
Parameters:
- ctx: The context.Context to use for the request.
- buff: The line protocol record(s) to write.
- options: Write options.
Returns:
- An error, if any.
Deprecated: use Write with variadic WriteOption option
type ClientConfig ¶
type ClientConfig struct { // Host holds the URL of the InfluxDB server to connect to. // This must be non-empty. E.g. http://localhost:8086 Host string // Token holds the authorization token for the API. // This can be obtained through the GUI web browser interface. Token string // Organization is name or ID of organization where data (databases, users, tasks, etc.) belongs to // Optional for InfluxDB Cloud Organization string // Database used by the client. Database string // HTTPClient is used to make API requests. // // This can be used to specify a custom TLS configuration // (TLSClientConfig), a custom request timeout (Timeout), // or other customization as required. // // It HTTPClient is nil, http.DefaultClient will be used. HTTPClient *http.Client // Write options WriteOptions *WriteOptions // Default HTTP headers to be included in requests Headers http.Header }
ClientConfig holds the parameters for creating a new client. The only mandatory field is Host. Token is also important if authentication was not done outside this client.
type Option ¶ added in v0.6.0
type Option func(o *options)
Option is a functional option type that can be passed to Client.Query and Client.Write methods.
func WithDatabase ¶ added in v0.6.0
WithDatabase is used to override default database in Client.Query and Client.Write methods.
func WithDefaultTags ¶ added in v0.6.0
WithDefaultTags is used to override default tags in Client.Write methods.
func WithGzipThreshold ¶ added in v0.6.0
WithGzipThreshold is used to override default GZIP threshold in Client.Write methods.
func WithHeader ¶ added in v0.7.0
WithHeader is used to add or override default header in Client.Query method.
func WithPrecision ¶ added in v0.6.0
func WithPrecision(precision lineprotocol.Precision) Option
WithPrecision is used to override default precision in Client.Write methods.
func WithQueryType ¶ added in v0.6.0
WithQueryType is used to override default query type in Client.Query method.
type Point ¶
type Point struct {
Values *PointValues
}
Point represents InfluxDB time series point, holding tags and fields
func FromValues ¶ added in v0.4.0
func FromValues(values *PointValues) (*Point, error)
FromValues creates a new PointData with given Values.
func NewPoint ¶
func NewPoint(measurement string, tags map[string]string, fields map[string]interface{}, ts time.Time) *Point
NewPoint is a convenient function for creating a Point with the given measurement name, tags, fields, and timestamp.
Parameters:
- measurement: The measurement name for the Point.
- tags: The tags for the Point.
- fields: The fields for the Point.
- ts: The timestamp for the Point.
Returns:
- The created Point.
func NewPointWithMeasurement ¶
NewPointWithMeasurement creates a new PointData with specified measurement name.
func NewPointWithPointValues ¶ added in v0.4.0
func NewPointWithPointValues(values *PointValues) *Point
NewPointWithPointValues returns a new Point with given PointValues.
func (*Point) GetBooleanField ¶ added in v0.4.0
GetBooleanField gets the bool field value associated with the specified name. If the field is not present, returns nil.
func (*Point) GetDoubleField ¶ added in v0.4.0
GetDoubleField gets the double field value associated with the specified name. If the field is not present, returns nil.
func (*Point) GetField ¶ added in v0.4.0
GetField gets field of given name. Can be nil if field doesn't exist.
func (*Point) GetFieldNames ¶ added in v0.4.0
GetFieldNames gets an array of field names associated with this object.
func (*Point) GetIntegerField ¶ added in v0.4.0
GetIntegerField gets the integer field value associated with the specified name. If the field is not present, returns nil.
func (*Point) GetMeasurement ¶ added in v0.4.0
GetMeasurement returns the measurement name
func (*Point) GetStringField ¶ added in v0.4.0
GetStringField gets the string field value associated with the specified name. If the field is not present, returns nil.
func (*Point) GetTagNames ¶ added in v0.4.0
GetTagNames retrieves all tag names
func (*Point) GetUIntegerField ¶ added in v0.4.0
GetUIntegerField gets the uinteger field value associated with the specified name. If the field is not present, returns nil.
func (*Point) MarshalBinary ¶
func (p *Point) MarshalBinary(precision lineprotocol.Precision) ([]byte, error)
MarshalBinary converts the Point to its binary representation in line protocol format.
Parameters:
- precision: The precision to use for timestamp encoding in line protocol format.
Returns:
- The binary representation of the Point in line protocol format.
- An error, if any.
func (*Point) MarshalBinaryWithDefaultTags ¶ added in v0.5.0
func (p *Point) MarshalBinaryWithDefaultTags(precision lineprotocol.Precision, defaultTags map[string]string) ([]byte, error)
MarshalBinaryWithDefaultTags converts the Point to its binary representation in line protocol format with default tags.
Parameters:
- precision: The precision to use for timestamp encoding in line protocol format.
- DefaultTags: Tags added to each point during writing. If a point already has a tag with the same key, it is left unchanged.
Returns:
- The binary representation of the Point in line protocol format.
- An error, if any.
func (*Point) RemoveField ¶ added in v0.4.0
RemoveField removes a field with the specified name if it exists; otherwise, it does nothing.
func (*Point) RemoveTag ¶ added in v0.4.0
RemoveTag Removes a tag with the specified name if it exists; otherwise, it does nothing.
func (*Point) SetBooleanField ¶ added in v0.4.0
SetBooleanField adds or replaces a bool field.
func (*Point) SetDoubleField ¶ added in v0.4.0
SetDoubleField adds or replaces a double field.
func (*Point) SetField ¶ added in v0.4.0
SetField adds or replaces a field with an interface{} value.
func (*Point) SetIntegerField ¶ added in v0.4.0
SetIntegerField adds or replaces an integer field.
func (*Point) SetMeasurement ¶ added in v0.4.0
SetMeasurement sets the measurement name and returns the modified PointValues
func (*Point) SetStringField ¶ added in v0.4.0
SetStringField adds or replaces a string field.
func (*Point) SetTimestamp ¶
SetTimestamp sets the timestamp using a time.Time and returns the modified PointValues
func (*Point) SetTimestampWithEpoch ¶ added in v0.4.0
SetTimestampWithEpoch sets the timestamp using an int64 which represents start of epoch in nanoseconds and returns the modified PointDataValues
type PointValues ¶ added in v0.4.0
type PointValues struct { MeasurementName string Tags map[string]string Fields map[string]interface{} Timestamp time.Time }
PointValues is representing InfluxDB time series point, holding tags and fields
func NewPointValues ¶ added in v0.4.0
func NewPointValues(measurementName string) *PointValues
NewPointValues returns a new PointValues
func (*PointValues) AsPoint ¶ added in v0.4.0
func (pv *PointValues) AsPoint() (*Point, error)
AsPoint returns a Point. If the PointValues does not have a measurement name, an error is returned.
func (*PointValues) AsPointWithMeasurement ¶ added in v0.4.0
func (pv *PointValues) AsPointWithMeasurement(measurement string) (*Point, error)
AsPointWithMeasurement returns a Point with the specified measurement name
func (*PointValues) Copy ¶ added in v0.4.0
func (pv *PointValues) Copy() *PointValues
Copy returns a copy of the PointValues
func (*PointValues) GetBooleanField ¶ added in v0.4.0
func (pv *PointValues) GetBooleanField(name string) *bool
GetBooleanField gets the bool field value associated with the specified name. If the field is not present, returns nil.
func (*PointValues) GetDoubleField ¶ added in v0.4.0
func (pv *PointValues) GetDoubleField(name string) *float64
GetDoubleField gets the double field value associated with the specified name. If the field is not present, returns nil.
func (*PointValues) GetField ¶ added in v0.4.0
func (pv *PointValues) GetField(name string) interface{}
GetField gets field of given name. Can be nil if field doesn't exist.
func (*PointValues) GetFieldNames ¶ added in v0.4.0
func (pv *PointValues) GetFieldNames() []string
GetFieldNames gets an array of field names associated with this object.
func (*PointValues) GetIntegerField ¶ added in v0.4.0
func (pv *PointValues) GetIntegerField(name string) *int64
GetIntegerField gets the integer field value associated with the specified name. If the field is not present, returns nil.
func (*PointValues) GetMeasurement ¶ added in v0.4.0
func (pv *PointValues) GetMeasurement() string
GetMeasurement returns the measurement name
func (*PointValues) GetStringField ¶ added in v0.4.0
func (pv *PointValues) GetStringField(name string) *string
GetStringField gets the string field value associated with the specified name. If the field is not present, returns nil.
func (*PointValues) GetTag ¶ added in v0.4.0
func (pv *PointValues) GetTag(name string) (string, bool)
GetTag retrieves a tag value
func (*PointValues) GetTagNames ¶ added in v0.4.0
func (pv *PointValues) GetTagNames() []string
GetTagNames retrieves all tag names
func (*PointValues) GetUIntegerField ¶ added in v0.4.0
func (pv *PointValues) GetUIntegerField(name string) *uint64
GetUIntegerField gets the uint field value associated with the specified name. If the field is not present, returns nil.
func (*PointValues) HasFields ¶ added in v0.4.0
func (pv *PointValues) HasFields() bool
HasFields checks if the point contains any fields.
func (*PointValues) RemoveField ¶ added in v0.4.0
func (pv *PointValues) RemoveField(name string) *PointValues
RemoveField removes a field with the specified name if it exists; otherwise, it does nothing.
func (*PointValues) RemoveTag ¶ added in v0.4.0
func (pv *PointValues) RemoveTag(name string) *PointValues
RemoveTag Removes a tag with the specified name if it exists; otherwise, it does nothing.
func (*PointValues) SetBooleanField ¶ added in v0.4.0
func (pv *PointValues) SetBooleanField(name string, value bool) *PointValues
SetBooleanField adds or replaces a bool field.
func (*PointValues) SetDoubleField ¶ added in v0.4.0
func (pv *PointValues) SetDoubleField(name string, value float64) *PointValues
SetDoubleField adds or replaces a double field.
func (*PointValues) SetField ¶ added in v0.4.0
func (pv *PointValues) SetField(name string, value interface{}) *PointValues
SetField adds or replaces a field with an interface{} value.
func (*PointValues) SetIntegerField ¶ added in v0.4.0
func (pv *PointValues) SetIntegerField(name string, value int64) *PointValues
SetIntegerField adds or replaces an integer field.
func (*PointValues) SetMeasurement ¶ added in v0.4.0
func (pv *PointValues) SetMeasurement(measurementName string) *PointValues
SetMeasurement sets the measurement name and returns the modified PointValues
func (*PointValues) SetStringField ¶ added in v0.4.0
func (pv *PointValues) SetStringField(name string, value string) *PointValues
SetStringField adds or replaces a string field.
func (*PointValues) SetTag ¶ added in v0.4.0
func (pv *PointValues) SetTag(name string, value string) *PointValues
SetTag sets a tag value and returns the modified PointValues
func (*PointValues) SetTimestamp ¶ added in v0.4.0
func (pv *PointValues) SetTimestamp(timestamp time.Time) *PointValues
SetTimestamp sets the timestamp using a time.Time and returns the modified PointValues
func (*PointValues) SetTimestampWithEpoch ¶ added in v0.4.0
func (pv *PointValues) SetTimestampWithEpoch(timestamp int64) *PointValues
SetTimestampWithEpoch sets the timestamp using an int64 which represents start of epoch in nanoseconds and returns the modified PointDataValues
func (*PointValues) SetUIntegerField ¶ added in v0.4.0
func (pv *PointValues) SetUIntegerField(name string, value uint64) *PointValues
SetUIntegerField adds or replaces an unsigned integer field.
type QueryIterator ¶
type QueryIterator struct {
// contains filtered or unexported fields
}
QueryIterator is a custom query iterator that encapsulates and simplifies the logic for the flight reader. It provides methods such as Next, Value, and Index to consume the flight reader, or users can use the underlying reader directly with the Raw method.
func (*QueryIterator) AsPoints ¶ added in v0.4.0
func (i *QueryIterator) AsPoints() *PointValues
AsPoints return data from InfluxDB IOx into PointValues structure.
func (*QueryIterator) Done ¶
func (i *QueryIterator) Done() bool
Done returns a boolean value indicating whether the iteration is complete or not.
Returns:
- true if the iteration is complete, false otherwise.
func (*QueryIterator) Index ¶
func (i *QueryIterator) Index() interface{}
Index returns the current index of Value.
Returns:
- The current index value.
func (*QueryIterator) Next ¶
func (i *QueryIterator) Next() bool
Next reads the next value of the flight reader and returns true if a value is present.
Returns:
- true if a value is present, false otherwise.
func (*QueryIterator) Raw ¶
func (i *QueryIterator) Raw() *flight.Reader
Raw returns the underlying flight.Reader associated with the QueryIterator. WARNING: It is imperative to use either the Raw method or the Value and Next functions, but not both at the same time, as it can lead to unpredictable behavior.
Returns:
- The underlying flight.Reader.
func (*QueryIterator) Value ¶
func (i *QueryIterator) Value() map[string]interface{}
Value returns the current value from the flight reader as a map object. The map contains the fields and tags as key-value pairs.
Returns:
- A map[string]interface{} object representing the current value.
type QueryOption ¶ added in v0.6.0
type QueryOption = Option
QueryOption is a functional option type that can be passed to Client.Query. Available options:
- WithDatabase
- WithQueryType
- WithHeader
type QueryOptions ¶
type QueryOptions struct { // Database for querying. Use to override default database in `ClientConfig`. Database string // Query type. QueryType QueryType // Headers to be included in requests. Use to add or override headers in `ClientConfig`. Headers http.Header }
QueryOptions holds options for query
type QueryParameters ¶ added in v0.6.0
QueryParameters is a type for query parameters.
type ServerError ¶
type ServerError struct { // Code holds the Influx error code, or empty if the code is unknown. Code string `json:"code"` // Message holds the error message. Message string `json:"message"` // StatusCode holds the HTTP response status code. StatusCode int `json:"-"` // RetryAfter holds the value of Retry-After header if sent by server, otherwise zero RetryAfter int `json:"-"` }
ServerError represents an error returned from an InfluxDB API server.
func NewServerError ¶
func NewServerError(message string) *ServerError
NewServerError returns new with just a message
type WriteOption ¶ added in v0.6.0
type WriteOption = Option
WriteOption is a functional option type that can be passed to Client.Write methods. Available options:
- WithDatabase
- WithPrecision
- WithGzipThreshold
- WithDefaultTags
type WriteOptions ¶
type WriteOptions struct { // Database for writing. Use to override default database in `ClientConfig`. Database string // Precision of timestamp to use when writing data. // Default value: lineprotocol.Nanosecond Precision lineprotocol.Precision // Tags added to each point during writing. If a point already has a tag with the same key, it is left unchanged. DefaultTags map[string]string // Write body larger than the threshold is gzipped. 0 for no compression. GzipThreshold int }
WriteOptions holds options for write