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

Add sqlx support and test #9

Merged
merged 2 commits into from
Sep 17, 2024

Conversation

paulgb
Copy link
Member

@paulgb paulgb commented Sep 16, 2024

This is an alternative approach to #7. It adds support for use in an sqlx AsRow derive, by implementing TryFrom<Vec<u8>> and TryFrom<Option<Vec<u8>>>.

One limitation of this approach is that for a nullable column, we can only return a FractionalIndex, not an Option<FractionalIndex>. I wish sqlx would implement something like #[sqlx(try_from_option = "Vec<u8>")] that would handle nullable columns by returning a None, but unfortunately this seems to be the best we can do.

This also improves the ergonomics of inserting a FractionalIndex, by implementing Deref.

This adds tests using sqlx and sqlite, which double as a demonstration of a usage example.

@paulgb paulgb mentioned this pull request Sep 16, 2024
@sergiomeneses
Copy link

What is AsRow?

@paulgb
Copy link
Member Author

paulgb commented Sep 17, 2024

What is AsRow?

Sorry, I mean FromRow

@paulgb paulgb merged commit 9cd8498 into main Sep 17, 2024
1 check passed
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