@@ -8,62 +8,31 @@ extension InfluxDBClient {
88 /// Point defines the values that will be written to the database.
99 ///
1010 /// - SeeAlso: http://bit.ly/influxdata-point
11- public class Point {
11+ public struct Point : Sendable {
1212 /// The measurement name.
13- private let measurement : String
13+ public let measurement : String
1414 // The measurement tags.
15- private var tags : [ String : String ? ] = [ : ]
15+ public var tags : [ String : String ? ]
1616 // The measurement fields.
17- private var fields : [ String : FieldValue ? ] = [ : ]
17+ public var fields : [ String : FieldValue ? ]
1818 /// The data point time.
19- var time : TimestampValue ?
19+ public var time : TimestampValue ?
2020
2121 /// Create a new Point with specified a measurement name and precision.
2222 ///
2323 /// - Parameters:
2424 /// - measurement: the measurement name
2525 /// - precision: the data point precision
26- public init ( _ measurement: String ) {
26+ public init (
27+ _ measurement: String ,
28+ tags: [ String : String ? ] = [ : ] ,
29+ fields: [ String : FieldValue ? ] = [ : ] ,
30+ time: TimestampValue ? = nil
31+ ) {
2732 self . measurement = measurement
28- }
29-
30- /// Adds or replaces a tag value for this point.
31- ///
32- /// - Parameters:
33- /// - key: the tag name
34- /// - value: the tag value
35- /// - Returns: self
36- @discardableResult
37- public func addTag( key: String ? , value: String ? ) -> Point {
38- if let key = key {
39- tags [ key] = value
40- }
41- return self
42- }
43-
44- /// Adds or replaces a field value for this point.
45- ///
46- /// - Parameters:
47- /// - key: the field name
48- /// - value: the field value
49- /// - Returns: self
50- @discardableResult
51- public func addField( key: String ? , value: FieldValue ? ) -> Point {
52- if let key = key {
53- fields [ key] = value
54- }
55- return self
56- }
57-
58- /// Updates the timestamp for the point.
59- ///
60- /// - Parameters:
61- /// - time: the timestamp. It can be `Int` or `Date`.
62- /// - Returns: self
63- @discardableResult
64- public func time( time: TimestampValue ) -> Point {
33+ self . tags = tags
34+ self . fields = fields
6535 self . time = time
66- return self
6736 }
6837
6938 /// Creates Line Protocol from Data Point.
@@ -134,7 +103,7 @@ extension InfluxDBClient {
134103
135104extension InfluxDBClient . Point {
136105 /// Possible value types of Field
137- public enum FieldValue {
106+ public enum FieldValue : Sendable {
138107 /// Support for Int8
139108 init ( _ value: Int8 ) {
140109 self = . int( Int ( value) )
@@ -185,7 +154,7 @@ extension InfluxDBClient.Point {
185154 }
186155
187156 /// Possible value types of Field
188- public enum TimestampValue : CustomStringConvertible {
157+ public enum TimestampValue : CustomStringConvertible , Sendable {
189158 // The number of ticks since the UNIX epoch. The value has to be specified with correct precision.
190159 case interval( Int , InfluxDBClient . TimestampPrecision = InfluxDBClient . defaultTimestampPrecision)
191160 // The date timestamp.
@@ -205,29 +174,22 @@ extension InfluxDBClient.Point {
205174extension InfluxDBClient . Point {
206175 /// Tuple definition for construct `Point`.
207176 public typealias Tuple = ( measurement: String ,
208- tags: [ String ? : String ? ] ? ,
209- fields: [ String ? : InfluxDBClient . Point . FieldValue ? ] ,
177+ tags: [ String : String ? ] ? ,
178+ fields: [ String : InfluxDBClient . Point . FieldValue ? ] ,
210179 time: InfluxDBClient . Point . TimestampValue ? )
211180 /// Create a new Point from Tuple.
212181 ///
213182 /// - Parameters:
214183 /// - tuple: the tuple with keys: `measurement`, `tags`, `fields` and `time`
215184 /// - precision: the data point precision
216185 /// - Returns: created Point
217- public class func fromTuple( _ tuple: Tuple ) -> InfluxDBClient . Point {
218- let point = InfluxDBClient . Point ( tuple. measurement)
219- if let tags = tuple. tags {
220- for tag in tags {
221- point. addTag ( key: tag. 0 , value: tag. 1 )
222- }
223- }
224- for field in tuple. fields {
225- point. addField ( key: field. 0 , value: field. 1 )
226- }
227- if let time = tuple. time {
228- point. time ( time: time)
229- }
230- return point
186+ public static func fromTuple( _ tuple: Tuple ) -> InfluxDBClient . Point {
187+ . init(
188+ tuple. measurement,
189+ tags: tuple. tags ?? [ : ] ,
190+ fields: tuple. fields,
191+ time: tuple. time
192+ )
231193 }
232194}
233195
@@ -386,3 +348,86 @@ extension InfluxDBClient.Point {
386348 return " \( sinceEpoch) "
387349 }
388350}
351+
352+ extension InfluxDBClient . Point {
353+ /// Adds or replaces a tag value for this point.
354+ ///
355+ /// - Parameters:
356+ /// - key: the tag name
357+ /// - value: the tag value
358+ /// - Returns: self
359+ @_disfavoredOverload
360+ @available ( * , deprecated, message: " Pass tags to Point.init or use the tags property " )
361+ public func addTag( key: String ? , value: String ? ) -> Self {
362+ var point = self
363+ if let key = key {
364+ point. tags [ key] = value
365+ }
366+ return point
367+ }
368+
369+ /// Adds or replaces a tag value for this point.
370+ ///
371+ /// - Parameters:
372+ /// - key: the tag name
373+ /// - value: the tag value
374+ /// - Returns: self
375+ @available ( * , deprecated, message: " Pass tags to Point.init or use the tags property " )
376+ public mutating func addTag( key: String ? , value: String ? ) {
377+ if let key = key {
378+ tags [ key] = value
379+ }
380+ }
381+
382+ /// Adds or replaces a field value for this point.
383+ ///
384+ /// - Parameters:
385+ /// - key: the field name
386+ /// - value: the field value
387+ /// - Returns: self
388+ @_disfavoredOverload
389+ @available ( * , deprecated, message: " Pass fields to Point.init or use the fields property " )
390+ public func addField( key: String ? , value: FieldValue ? ) -> Self {
391+ var point = self
392+ if let key = key {
393+ point. fields [ key] = value
394+ }
395+ return point
396+ }
397+
398+ /// Adds or replaces a field value for this point.
399+ ///
400+ /// - Parameters:
401+ /// - key: the field name
402+ /// - value: the field value
403+ /// - Returns: self
404+ @available ( * , deprecated, message: " Pass fields to Point.init or use the fields property " )
405+ public mutating func addField( key: String ? , value: FieldValue ? ) {
406+ if let key = key {
407+ fields [ key] = value
408+ }
409+ }
410+
411+ /// Updates the timestamp for the point.
412+ ///
413+ /// - Parameters:
414+ /// - time: the timestamp. It can be `Int` or `Date`.
415+ /// - Returns: self
416+ @_disfavoredOverload
417+ @available ( * , deprecated, message: " Pass time to Point.init or use the time property " )
418+ public func time( time: TimestampValue ) -> Self {
419+ var point = self
420+ point. time = time
421+ return point
422+ }
423+
424+ /// Updates the timestamp for the point.
425+ ///
426+ /// - Parameters:
427+ /// - time: the timestamp. It can be `Int` or `Date`.
428+ /// - Returns: self
429+ @available ( * , deprecated, message: " Pass time to Point.init or use the time property " )
430+ public mutating func time( time: TimestampValue ) {
431+ self . time = time
432+ }
433+ }
0 commit comments