Skip to content

Conversation

badge
Copy link
Contributor

@badge badge commented Aug 9, 2025

Description

This PR enables two new features in the crate:

  1. Structs with DateTime<Utc> fields that become nanosecond-encoded uint64s
  2. Setting a DateTime<Utc> field other than time to be the time field for the struct in the InfluxDbWriteable proc macro

For (1), this is now possible:

    #[derive(Debug, Deserialize, InfluxDbWriteable)]
    struct WeatherReading {
        time: DateTime<Utc>,
        humidity: i32,
        #[influxdb(tag)]
        wind_direction: String,
        forecast_time: DateTime<Utc>,
    }

Previously, forecast_time would have not worked. As type have to implement From<T> rather than TryFrom<T>, it defaults to zero if the DateTime<Utc> field is OOB.

For (2), we can now do:

    #[derive(Debug, Deserialize, InfluxDbWriteable)]
    struct WeatherReading {
        #[influxdb(time)]
        #[serde(rename = "time")]
        reading_time: DateTime<Utc>,
        humidity: i32,
        #[influxdb(tag)]
        wind_direction: String,
        forecast_time: DateTime<Utc>,
    }

The derive macro does sensible checks:

  1. It enumerates the struct's fields and checks for any tagged with #[influxdb(time)] or named time and not tagged with #[influxdb(ignore)]
  2. If it finds more than one such field, it gives a compile error
  3. If it finds no such fields, it gives a compile error
  4. Otherwise, it uses the name of the field as the time of the created WriteQuery instance

Have to dash but opening anyway, will be back soon!

Copy link
Collaborator

@msrd0 msrd0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR!

@msrd0 msrd0 requested a review from Empty2k12 August 22, 2025 15:06
Empty2k12
Empty2k12 previously approved these changes Aug 22, 2025
Copy link
Collaborator

@Empty2k12 Empty2k12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀 Does it make sense to amend the ticket you created about the 0 problematic, or open a separate one?

@msrd0
Copy link
Collaborator

msrd0 commented Aug 22, 2025

Yeah sure we can track that under the same ticket

@Empty2k12 Empty2k12 merged commit c8ddae4 into influxdb-rs:main Aug 22, 2025
18 checks passed
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

Successfully merging this pull request may close these issues.

3 participants