Expose .iter(), .opt(), etc. methods directly on the params struct.

Abierto
#290 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
postgresql, rust

Línea de trabajo

Start by reading the query parameter struct generation and execution APIs in the repository; the issue does not name specific files or tests. Work out how generated parameter structs could expose .iter() and .opt() while supporting the database client APIs, then add or update coverage for the generated methods. Done means callers can invoke these methods on parameter structs and the existing query execution behavior remains covered.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

codegen feature

Migrated from halcyonnouveau/clorinde#85, originally reported by @jvdwrf on 2025-04-06.

Currently, I use the following pattern to execute clorinde methods:

queries::folder::my_query()
    .params(
        client,
        &queries::scoring::MyQueryParams {
            field_a: "value_a",
            field_b: "value_b",
        },
    )
    .iter()

I feel like my code could be cleaned up a lot if the following were instead possible:

queries::folder::MyQueryParams {
    field_a: "value_a",
    field_b: "value_b",
}
.iter(client)

// or even:
client.iter(queries::folder::MyQueryParams {
    field_a: "value_a",
    field_b: "value_b",
})

This removes a lot of code-duplication, and improves readability a lot. I don't like using the method directly without params struct, since it becomes very easy to accidentally map params to the wrong field.

I also think it would be nice if, instead of them being regular methods, it would instead be traits that are implemented. This would allow me to much more easily build abstractions over the various database methods, by implementing them for all param structs at once. (e.g. automatically logging the error in a specific way, using a default impl. super trait)


Original discussion

@beanpuppy (2025-04-06):

client.iter(queries::folder::MyQueryParams {
    field_a: "value_a",
    field_b: "value_b",
})

This isn't possible since client is whatever postgres client you're using, and not something we control.

queries::folder::MyQueryParams {
    field_a: "value_a",
    field_b: "value_b",
}
.iter(client)

But never thought of doing something like this. It seems like a nice idea especially as a trait, and I could see myself using it a lot as well. I'll look into it, thanks for the suggestion.

@jvdwrf (2025-04-07):

For the first version, it would be possible to create an extension trait that would implement these methods for all clients; given that the params structs would implement traits rather than methods. (Though I could also write this myself, it doesnt have to be included in clorinde itself)

(Also, maybe params structs could be generated for single param methods as well? :))

Lenguaje dominante
Rust
Estrellas
1.2k
Forks
77
Merge medio
5 d 12 h
PR fusionados (30 d)
1

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de cornucopia-rs/cornucopia

Todos los issues de cornucopia-rs/cornucopia

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.