influxdata / influxdb-client-swift

InfluxDB (v2+) Client Library for Swift
https://influxdata.github.io/influxdb-client-swift/
MIT License
26 stars 8 forks source link

Ergonomic and idiomatic improvements #27

Closed bednar closed 3 years ago

bednar commented 3 years ago

Originally posted by @stuartcarnie in https://github.com/influxdata/influxdb-client-swift/issues/25#issuecomment-786861429

But the user don't uses toLineProtocol function, they are uses WriteAPI. The question is, "When the user specify the precision of their data?"

Correct, the user interacts with the public API, write, via the WriteAPI class. You already have a precision argument in your original writeRecord API, which also handles the nil case.

User creates following two points:

var point1 = InfluxDBClient.Point("h2o")
     .addTag(key: "location", value: "europe")
     .addField(key: "level", value: .int(2))
     .time(time: .interval(123, .s))
var point2 = InfluxDBClient.Point("server_state")
     .addTag(key: "server_group", value: "production")
     .addField(key: "usage", value: .int(98))
     .time(time: .Date())

and then calls write(points: [Point], precision: TimeStampPrecision) API with a desired precision of .s (seconds):

writeAPI.write(points: [point1, point2], precision: .s) { _, _ in
 // ..
}

What is expected precision for this case? Is it a default value of InfluxDBOptions?

That is already handed by your implementation:

https://github.com/influxdata/influxdb-client-swift/blob/eabb2999f79af7745ab006f253ab2ede5db0585b/Sources/InfluxDBSwift/WriteAPI.swift#L262