jschaf / pggen

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

Commit broke generation of custom types #67

Closed flamedmg closed 2 years ago

flamedmg commented 2 years ago

Good morning, It looks like commit #2489d54a806652d73f2c83bb5736a7574582092c broke generation of custom types. I'm using citext type which was generated previously to proper golang code

// newUserEmails creates a new pgtype.ValueTranscoder for the Postgres
// composite type 'user_emails'.
func (tr *typeResolver) newUserEmails() pgtype.ValueTranscoder {
    return tr.newCompositeValue(
        "user_emails",
        compositeField{"id", "uuid", &pgtype.UUID{}},
        compositeField{"user_id", "uuid", &pgtype.UUID{}},
        compositeField{"email", "citext", &pgtype.Text{}},
        compositeField{"is_verified", "bool", &pgtype.Bool{}},
        compositeField{"is_primary", "bool", &pgtype.Bool{}},
        compositeField{"created_at", "timestamptz", &pgtype.Timestamptz{}},
        compositeField{"updated_at", "timestamptz", &pgtype.Timestamptz{}},
    )
}

but after i upgraded it generates like this:

// newUserEmails creates a new pgtype.ValueTranscoder for the Postgres
// composite type 'user_emails'.
func (tr *typeResolver) newUserEmails() pgtype.ValueTranscoder {
    return tr.newCompositeValue(
        "user_emails",
        compositeField{"id", "uuid", &pgtype.UUID{}},
        compositeField{"user_id", "uuid", &pgtype.UUID{}},
        compositeField{"email", "citext", &Text{}},
        compositeField{"is_verified", "bool", &pgtype.Bool{}},
        compositeField{"is_primary", "bool", &pgtype.Bool{}},
        compositeField{"created_at", "timestamptz", &pgtype.Timestamptz{}},
        compositeField{"updated_at", "timestamptz", &pgtype.Timestamptz{}},
    )
}

what's wrong is field email does not have package specified:

compositeField{"email", "citext", &Text{}},
jschaf commented 2 years ago

Thanks for the report. Is citext the only one that's broken?

flamedmg commented 2 years ago

Yes, my other custom types are generated as expected

flamedmg commented 2 years ago

I just realized i not specified how do i generate files:

    pggen gen go --postgres-connection "user=postgres host=localhost port=6432 dbname=utility password=flame" \
        --query-glob app/repository/user.sql \
        --query-glob app/repository/utility.sql \
        --query-glob app/repository/payment.sql \
        --query-glob app/repository/subscriptions.sql \
        --query-glob app/repository/submissions.sql \
        --go-type 'citext=github.com/jackc/pgtype.Text' \
        --go-type 'int4=*int' \
        --go-type 'int8=*int64'

I.e. i specify what type to use explicitly: citext=github.com/jackc/pgtype.Text

jschaf commented 2 years ago

Should be fixed on the latest release https://github.com/jschaf/pggen/releases. Let me know if that doesn't work.

flamedmg commented 2 years ago

Just tested, works really well, no issues found! Thank you!