Skip to content

Allow Bind impl to differ from Serialize impl (for DateTime64) #274

@Smona

Description

@Smona

Use case

AFAICT, ClickHouse when using the row binary format requires integer timestamps with matching precision for DateTime64 fields. However, when using DateTime64 values in queries the that format is not supported. not only that, but there's no way to diretly use those millisecond timestamps in toDateTime64 that I can find. So currently, binding chrono DateTimes to queries requires custom formatting code.

Ideally it would be possible to create a DateTime64(chrono::DateTime<Utc>) newtype that can be both used in Row structs without a serde_with attribute, and passed directly into query.bind() while working as expected, but since the Bind trait is sealed and already implemented for all Serialize types this isn't possible.

Describe the solution you'd like

Either provide an in-house DateTime64 type, or allow users to implement their own types that have disjoint Bind and Serialize implementations.

Describe the alternatives you've considered

Implement a simple helper function to format DateTime<Utc values in a query-compatible format. The problem with this is there is no way to avoid query errors at compile time from directly passing in DateTime<Utc, since bind() will happily accept any value that implements Serialize.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions