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

feat: support NonZero* scalar types #3244

Merged
merged 4 commits into from
Jun 5, 2024

Conversation

AlphaKeks
Copy link
Contributor

This commits adds Type, Encode, and Decode impls for all the NonZero* types from the standard library. They are implemented as direct proxies to their primitive counterparts, except that when decoding, the values are checked to not be zero.

fixes #1926

sqlx-core/Cargo.toml Outdated Show resolved Hide resolved
sqlx-core/src/types/mod.rs Outdated Show resolved Hide resolved
@AlphaKeks
Copy link
Contributor Author

I implemented everything you suggested! Anything else missing?

@abonander
Copy link
Collaborator

Since #3126 was merged, you'll need to rebase and fix the compilation errors.

This commits adds `Type`, `Encode`, and `Decode` impls for all the
`NonZero*` types from the standard library. They are implemented as
direct proxies to their primitive counterparts, except that when
decoding, the values are checked to not be zero.
@abonander abonander merged commit 6561830 into launchbadge:main Jun 5, 2024
4 checks passed
jayy-lmao pushed a commit to jayy-lmao/sqlx that referenced this pull request Jun 6, 2024
* feat: support `NonZero*` scalar types

This commits adds `Type`, `Encode`, and `Decode` impls for all the
`NonZero*` types from the standard library. They are implemented as
direct proxies to their primitive counterparts, except that when
decoding, the values are checked to not be zero.

* fixup!: remove `non-zero` cargo feature

* fixup!: make `non-zero` module private

* fixup!: rebase and fix trait impls
@InAnYan
Copy link

InAnYan commented Sep 11, 2024

@AlphaKeks @abonander hi!

I used sqlx::query_as! with a struct that has a NonZeroI32, but the sqlx still requires NonZero<i32>: From<i32>.

Why? Is it a bug? Should I create a new issue for this?

@abonander
Copy link
Collaborator

You need to tell it to use NonZeroI32 in the generated code using a type override for the column: https://docs.rs/sqlx/latest/sqlx/macro.query.html#force-a-differentcustom-type

@InAnYan
Copy link

InAnYan commented Sep 11, 2024

Thank you!

jrasanen pushed a commit to jrasanen/sqlx that referenced this pull request Oct 14, 2024
* feat: support `NonZero*` scalar types

This commits adds `Type`, `Encode`, and `Decode` impls for all the
`NonZero*` types from the standard library. They are implemented as
direct proxies to their primitive counterparts, except that when
decoding, the values are checked to not be zero.

* fixup!: remove `non-zero` cargo feature

* fixup!: make `non-zero` module private

* fixup!: rebase and fix trait impls
jrasanen pushed a commit to jrasanen/sqlx that referenced this pull request Oct 14, 2024
* feat: support `NonZero*` scalar types

This commits adds `Type`, `Encode`, and `Decode` impls for all the
`NonZero*` types from the standard library. They are implemented as
direct proxies to their primitive counterparts, except that when
decoding, the values are checked to not be zero.

* fixup!: remove `non-zero` cargo feature

* fixup!: make `non-zero` module private

* fixup!: rebase and fix trait impls
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.

Implement FromRow for Option<NonZero*>?
3 participants