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 for diesel @ 2.2 #404

Merged
merged 5 commits into from
Nov 12, 2024
Merged

Conversation

sinasab
Copy link
Contributor

@sinasab sinasab commented Nov 8, 2024

Motivation

I noticed there were some comment notes in the repo indicating a desire for diesel support. I had implemented something similar using a newtype pattern in my own project, so I figured I'd attempt to contribute it back upstream.

Solution

This PR implements the required traits for the generic uint types to work out of the box with diesel. The implementation closely matches the sqlx feature implementation in this repo. I have an example repo illustrating simple usage (schema, querying, inserting) @ https://github.com/sinasab/diesel_uint_test/.

PR Checklist

  • Added Tests
  • Added Documentation
  • Updated the changelog

@sinasab sinasab requested a review from prestwich as a code owner November 8, 2024 09:05
src/lib.rs Outdated
@@ -144,6 +144,8 @@ pub mod nightly {
///
/// [std-overflow]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow
#[derive(Clone, Copy, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "diesel", derive(diesel::AsExpression, diesel::FromSqlRow))]
#[cfg_attr(feature = "diesel", diesel(sql_type = diesel::sql_types::Binary))]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer not to have these leak into the codebase, is it possible to expand these and include them in the support/diesel.rs file? How many LoC would that add?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just pushed up these changes! 😁

It adds ~125 LoC (see latest commit):
image

Tested with my demo repo against a fresh DB and regenerating migrations to sanity check! 🫡

Copy link
Collaborator

Choose a reason for hiding this comment

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

cool. I will review, and may do a style pass on the generated code if you don't mind

Choose a reason for hiding this comment

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

Yes of course, feel free-- I mostly kept it the same as the generated code, minus deduping some long namespaced variables. Lmk if I can adjust anything else! 🫡

Thanks James 😁

Copy link
Collaborator

@prestwich prestwich left a comment

Choose a reason for hiding this comment

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

LGTM :)

@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Support for diesel @ 2.2 ([#404])
Copy link
Collaborator

Choose a reason for hiding this comment

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

pr not found 😂

Copy link
Collaborator

Choose a reason for hiding this comment

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

(I fixed the link)

@prestwich prestwich enabled auto-merge November 12, 2024 04:42
@prestwich prestwich merged commit 1419508 into recmo:main Nov 12, 2024
15 of 16 checks passed
@sinasab sinasab deleted the sina/diesel-support branch November 12, 2024 04:48
@prestwich
Copy link
Collaborator

why does it merge if clippy fails -_-

@prestwich prestwich mentioned this pull request Nov 28, 2024
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