This is very cool! It's an interesting compromise between using a fully featured ORM and interacting with SQL queries directly, and may be a good sweet spot.
Have you considered supporting documentation in generated code? Maybe by allowing for syntax like this for queries:
-- name: ListAuthors :many
--
-- ListAuthors retrieves all authors from the database blah blah.
SELECT * FROM authors
ORDER BY name;
... that would generate code like this:
// ListAuthors retrieves all authors from the database blah blah.
func (q *Queries) ListAuthors(ctx context.Context) ([]Author, error) {
...
}
I'm not too familiar with Postgres, but in MySQL you can create tables with comments. It looks like there's a similar feature in Postgres.
CREATE TABLE authors (
id int,
name VARCHAR(255) COMMENT "The name of the author who wrote the book",
bio VARCHAR(512) COMMENT "A short description of the author"
) COMMENT "Author is the author of a piece of literature.";
It might be nice if those comments propagated to the struct definition automatically.
// Author is the author of a piece of literature.
type Author struct {
ID int64
// The name of the author who wrote the book
Name string
// A short description of the author
Bio sql.NullString
}