-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
How to insert nullable values? #93
Comments
We do support nullable parameters, it's just the type hack we do to check that |
Thanks for the quick reply. My code appears to still be broken with let name = Some("D1plo1d".to_string());
sqlx::query!(
"INSERT INTO users (name) VALUES ($1)",
name
); Error:
|
That's also not supposed to happen but in general I think I can make the errors here much better; I have a promising prototype in #94 but I still need to integrate it into the macros and I also want to add UI tests to see how it handles type mismatches. |
Also seeing this with other types e.g. |
#94 looks like it's gonna fix this problem more or less for good but it's a breaking change because we can no longer support unsized expressions ( |
@abonander amazing! Let me know if I can help at all! |
Give the branch a try if you don't mind. I've got some testing on it but if it fixes your use-case that would really increase my confidence on it. |
Just tested it out tonight, working perfectly so far with no code change on our end. Will let you know if I see anything funky, but looking good so far! Awesome job! EDIT: I actually did end up having to change some scenarios where we were passing a |
@kilpatty that edit is interesting. I tried to finagle the code so it didn't require ownership but I'm guessing those structs were behind That's suboptimal. I'm pretty sure |
Yes exactly they were behind & references. Looks like it's mimicking the behavior of |
@abonander wow, awesome! #94 even fixed some additional Option issues I was running into. I'm not sure if this is a bug but while on #94 running a Is this expected behavior, bug or a regression? Error: unexpected null for non-null columnsqlx::query!(
"SELECT * FROM invites WHERE public_key=$1",
identity_public_key
) Patched Versionpub struct Invite {
pub id: i32,
pub public_key: String,
pub created_at: DateTime<Utc>,
pub is_admin: bool,
pub slug: Option<String>,
pub private_key: Option<String>,
}
sqlx::query_as!(
Invite,
"SELECT * FROM invites WHERE public_key=$1",
identity_public_key
) |
@abonander That's awesome. Appreciate the work y'all are putting into these quality of life issues! |
Hello, if you want to use |
I am using
Option<String>
to represent a nullable String but my code bellow complains that it expected a String instead of Option. How should nullable values be written with sqlx?My code that doesn't work:
The text was updated successfully, but these errors were encountered: