Skip to content

Request for comments: SQL to Go code generator that leverages pgx #915

@jschaf

Description

@jschaf

Hi! I'm working on sqld, a code generator that takes SQL queries and outputs type-safe Go code using pgx. I'm a big fan of pgx and if you have some time, I'd love to get your thoughts on the usage of pgx, especially around:

  1. Safe usage of the pgx APIs in the generated code (example/author/queries.sql.go).
  2. Possible collaboration on a future ClientTrace API similar to the Go stdlib http tracing: https://blog.golang.org/http-tracing. There's a ton of useful metrics we could surface in pgx (DNS resolution for host names, response parse time, pool queue time). I've created an initial pgx-focused ClientTrace.go that I use in the generated code.

RFC: sqld: Go code generation for Postgres (Google doc)

To summarize, sqld takes a query like:

SELECT * FROM author where first_name = sqld.arg('FirstName');

And generates:

func (q *DBQuerier) FindAuthors(ctx context.Context, firstName string) ([]Author, error) {}

sqld is heavily inspired by sqlc. The main differences are sqld gets type information from Postgres directly and sqld uses pgx instead of the standard library sql types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions