jschaf / pggen

Generate type-safe Go for any Postgres query. If Postgres can run the query, pggen can generate code for it.
MIT License
282 stars 26 forks source link

feature request: --version/tag flag, add config file. #30

Closed landbed closed 3 years ago

landbed commented 3 years ago

1, --version/tag flag is necessary to know what version or tag is using. 2, a config file instead of copy&paste command line or add an alias to the shell.

Thanks for your nice work!

jschaf commented 3 years ago

Thanks for the request! A version is a good idea. I'll add that soon-ish.

The config file request comes up a decent amount. I think persistent configuration is better solved with a Makefile or a similar build system like Bazel. I have a similar preference to esbuild, which is that a config file is just another interface to the command line flags. I'd like to limit the ways to interact with pggen to only the flags. Here's how I use pggen with a Makefile:

pggen:
    DOCKER_API_VERSION=1.39 \
    pggen gen go \
    --schema-glob schema.sql \
    --query-glob '../server/domain/product/*_query.sql' \
    --go-type int2=int16 \
    --go-type int4=int32 \
    --go-type int8=int \
    --go-type float4=float32 \
    --go-type float8=float64 \
    --go-type text=string
landbed commented 3 years ago

Thanks @jschaf !

    row := q.conn.QueryRow(ctx, getUserSQL, identifier)
    var item GetUserRow
    if err := row.Scan(&item.ID, &item.Status); err != nil {
        return item, fmt.Errorf("query GetUser: %w", err) // <--- this line
    }
    return item, nil

The above generated code can not get the pgx error(ex: pgx.ErrNoRows), so caller don't know the error is real error or just no rows.

jschaf commented 3 years ago

I think you can do errors.Is(err, pgx.ErrNoRows).

landbed commented 3 years ago

!!!!!!

Thanks!