4 ms·
I think I'm missing something, but I don't get sqlc. Let's say I want to "get a list of authors", so in sqlc I would write: -- name: ListAuthors :many
by sdevonoes 5y ago
I think I'm missing something, but I don't get sqlc. Let's say I want to "get a list of authors", so in sqlc I would write:
-- name: ListAuthors :many
SELECT * FROM authors
ORDER BY name;
and in Go I can then say `authors, err := queries.ListAuthors(ctx)`. This is cool. Now, if I want to "get a list of American authors" I would write:
-- name: ListAuthorsByNationality :many
SELECT * FROM authors
WHERE nationality = $1;
and in Go I can then say `americanAuthors, err := queries.ListAuthorsByNationality(ctx, "American")`. Now, if I want to "get a list of American authors that are dead", I would have to write:
-- name: ListDeadAuthorsByNationality :many
SELECT * FROM authors
WHERE nationality = $1 AND dead = 1;
... I like the idea of getting Go structs that represent table rows, but I don't want to keep a record of every query variation I may need to execute in Go code. I want to write in Go:
deadAmericanAuthors, err := magic.GetAuthorsBy(Params{
Nationality: "American",
Dead: true
})
without having to write manually the N potential sql queries that the above code may represent.
- Cthulhu_ 5y ago> without having to write manually the N potential sql queries that the above code may represent. The article provides an alternative by using conditionals inside of the SQL, but honestly it's not an improvement.
- jd3 5y agothis is the reason why I chose upper/db over pgx/sqlc for my current cockroachdb side project while upper/db is not as type safe, with proper testing infrastructure, it felt most similar to django due to its simplicity/composability/query building support i'm also excited to see how upper/db grows after generics land in Go later this year https://github.com/upper/db https://github.com/upper/db https://upper.io/ https://upper.io/