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

Allow using complex types in try_from when deriving FromRow #2115

Merged
merged 2 commits into from
Feb 14, 2023

Conversation

95ulisse
Copy link
Contributor

Hello 👋

The new attribute try_from for the FromRow derive introduced by #1081 expects the value of try_from to be a simple identifier instead of a full-fledged type. This means that that attribute cannot be used unless the referenced type is already in scope.

#[derive(sqlx::FromRow)]
struct Record {
    #[sqlx(try_from = "SomeType")] // <- This is fine
    id: u64,
}

#[derive(sqlx::FromRow)]
struct Record {
    #[sqlx(try_from = "another::SomeType")] // <- This currently fails, but it should be allowed
    id: u64,
}

This PR allows using complex types as the argument of try_from instead of just simple identifiers.

@abonander
Copy link
Collaborator

@95ulisse current development is on the 0.7-dev branch which just had some major refactors merged. Do you mind rebasing?

@95ulisse 95ulisse force-pushed the from-row-try-from-fix-ident branch 3 times, most recently from 7e87900 to dc3f7fe Compare February 2, 2023 23:29
@95ulisse 95ulisse changed the base branch from main to 0.7-dev February 2, 2023 23:29
@95ulisse 95ulisse force-pushed the from-row-try-from-fix-ident branch 2 times, most recently from 7e244d6 to 0e35590 Compare February 2, 2023 23:34
@95ulisse
Copy link
Contributor Author

95ulisse commented Feb 2, 2023

@abonander I've just rebased my PR on top of 0.7-dev 👍

@abonander
Copy link
Collaborator

@95ulisse can you amend and force-push to trigger a Github Actions run?

@95ulisse 95ulisse force-pushed the from-row-try-from-fix-ident branch from 0e35590 to 6a3cba1 Compare February 5, 2023 01:24
@95ulisse
Copy link
Contributor Author

95ulisse commented Feb 5, 2023

@abonander Done 👍 The workflow is now pending approval.

@95ulisse
Copy link
Contributor Author

95ulisse commented Feb 8, 2023

@abonander I fixed the tests and they are green on my machine. Could you re-run the workflow when you have some time, please? 🙏

@abonander abonander merged commit 7970dad into launchbadge:0.7-dev Feb 14, 2023
grgi pushed a commit to faccts/sqlx that referenced this pull request Feb 14, 2023
…chbadge#2115)

* Use `syn::Type` instead of `syn::Ident` to parse the value of `#[sqlx(try_from = "...")]`

* Fix broken test after rebase
@95ulisse 95ulisse deleted the from-row-try-from-fix-ident branch February 14, 2023 21:30
abonander pushed a commit that referenced this pull request Feb 18, 2023
* Use `syn::Type` instead of `syn::Ident` to parse the value of `#[sqlx(try_from = "...")]`

* Fix broken test after rebase
abonander pushed a commit that referenced this pull request Feb 21, 2023
* Use `syn::Type` instead of `syn::Ident` to parse the value of `#[sqlx(try_from = "...")]`

* Fix broken test after rebase
Aandreba pushed a commit to Aandreba/sqlx that referenced this pull request Mar 31, 2023
…chbadge#2115)

* Use `syn::Type` instead of `syn::Ident` to parse the value of `#[sqlx(try_from = "...")]`

* Fix broken test after rebase
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.

2 participants