Skip to content

feat: support for diesel @ 2.2#404

Merged
prestwich merged 5 commits into
alloy-rs:mainfrom
sinasab:sina/diesel-support
Nov 12, 2024
Merged

feat: support for diesel @ 2.2#404
prestwich merged 5 commits into
alloy-rs:mainfrom
sinasab:sina/diesel-support

Conversation

@sinasab
Copy link
Copy Markdown
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
Comment thread src/lib.rs Outdated
/// [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
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
Member

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

Copy link
Copy Markdown

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
Copy Markdown
Member

@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 :)

Comment thread CHANGELOG.md

### Added

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

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
Copy Markdown
Member

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 alloy-rs:main Nov 12, 2024
@sinasab sinasab deleted the sina/diesel-support branch November 12, 2024 04:48
@prestwich
Copy link
Copy Markdown
Member

why does it merge if clippy fails -_-

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