Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved usability of InfluxDBClient.Point if it was a struct #70

Open
CraigSiemens opened this issue Nov 9, 2024 · 1 comment
Open

Comments

@CraigSiemens
Copy link

Proposal:
This is related to the suggestion in #69.

If InfluxDBClient.Point was changed to be a struct, the usability of it could be improved.

The properties could be made public. This would be a simpler way to modify the values in the point than using the add... methods, which don't do anything other than silently ignore being passed a nil key.

The existing public init can be updated to have parameters with default values for all the properties of the struct.

Current behavior:
Example from the readme

let recordPoint = InfluxDBClient
	.Point("demo")
.addTag(key: "type", value: "point")
	.addField(key: "value", value: .int(2))

let recordPointDate = InfluxDBClient
	.Point("demo")
	.addTag(key: "type", value: "point-timestamp")
	.addField(key: "value", value: .int(2))
	.time(time: .date(Date()))

Desired behavior:

Public properties allow separating the creation of the point from setting the values. It's not always possible to have all the values at the same time the point is created.

var recordPoint = InfluxDBClient.Point("demo")
recordPoint.tags["type"] = "point"
recordPoint.fields["value"] = .int(2)

var recordPointDate = InfluxDBClient.Point("demo")
recordPoint.tags["type"] = "point"
recordPoint.fields["value"] = .int(2)
recordPoint.time = .date(Date())

Public init showing all the properties available to be set on the type though the one initializer instead of needing to chain function calls.

let recordPoint = InfluxDBClient.Point(
	"demo",
    tags: ["type": "point"]
    fields: ["value": .int(2)]
)

let recordPointDate = InfluxDBClient.Point(
	"demo"
	tags: ["type": "point"]
    fields: ["value": .int(2)]
	time: .date(Date())
@bednar
Copy link
Contributor

bednar commented Nov 13, 2024

Hi @CraigSiemens,

thanks for your suggestion.

Is this something you would be willing to help with? All PR is welcome and we will be happy to review your submission.

Best Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants