`no rows returned by a query that expected to return at least one row` could be caught at compile-time

Aperta
#4,137 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
22/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
rust, sql

Direzione di ricerca

The report is about sqlx::query! used with fetch_one on an INSERT that returns no rows. Start from how the query! / query_as! macros classify result arity at compile time and how fetch_one is typed against that. Decide whether INSERT without RETURNING should be a compile error when paired with fetch_one, then add a compile-fail or macro test that encodes this case. Done means the mismatch is rejected at compile time without changing runtime fetch_one behavior for queries that do return a row.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement
I have found these related issues/pull requests

none

Description

this query:

sqlx::query!(
            r#"
            INSERT INTO user_edit_change_logs (item_type, item_id, edited_by_id, edits)
            VALUES ($1, $2, $3, $4)
            "#,
            log.item_type,
            log.item_id,
            log.edited_by_id,
            log.edits
        )
        .fetch_one(...)

doesn't return anything, yet there will be an error at runtime because fetch_one() expects something returned. Couldn't this be caught at compile-time?

Prefered solution

.

Is this a breaking change? Why or why not?

no

Lingua principale
Rust
Stelle
17.5k
Fork
1.7k
Merge medio
1g 17h
PR unite (30g)
7

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di transact-rs/sqlx

Tutte le issue di transact-rs/sqlx

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.