-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
Discussed in #173
Originally posted by bbenne10 February 26, 2026
Currently, I don't see a great way to ignore conflicts on insert.
I have a File table that looks like this:
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
pub struct Sha256Sum([u8; SHA256_BYTE_LEN]);
// And some traits to make sqlx happy...
impl sqlx::Type<sqlx::Postgres> for Sha256Sum {...}
impl<'r> sqlx::Decode<'r, sqlx::Postgres> for Sha256Sum {...}
impl<'q> sqlx::Encode<'q, sqlx::Postgres> for Sha256Sum {...}
#[derive(WeldsModel)]
struct File {
sha256: Sha256Sum,
bytes: Vec<u8>,
}Asking the DB if this File exists has a race condition (as we're not using linearizable transactions), so we currently write some manual SQL to ignore the failure to insert if the sha256 collides:
INSERT INTO file(sha256, bytes) VALUES (?, ?) ON CONFLICT (sha256) DO NOTHINGBut raw SQL is a code smell (as it means you're not able to use the type system to tell immediately if the currently represented schema is upheld in all consuming code), so I would like to back this code out if possible. I see no way to currently be able to do this.
Does such a thing exist?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels