-
-
Notifications
You must be signed in to change notification settings - Fork 176
WIP: Add support for pgx v5 interface #523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
# Conflicts: # go.mod # go.sum # internal/testutils/test_utils.go # qrm/scan_context.go # tests/postgres/main_test.go # tests/postgres/northwind_test.go
feat: add preliminary json support for qrm_pgx.
# Conflicts: # go.mod # go.sum
# Conflicts: # tests/postgres/alltypes_test.go # tests/postgres/select_json_test.go
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (65.89%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #523 +/- ##
==========================================
- Coverage 92.18% 91.68% -0.50%
==========================================
Files 139 140 +1
Lines 8576 8736 +160
==========================================
+ Hits 7906 8010 +104
- Misses 493 532 +39
- Partials 177 194 +17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thank you so much for this @go-jet I'm reviewing this and the adapter thread now. |
|
Works great so far! We may have covered this in the past but I'm trying to refresh my memory. Any reason for Doing Generated public.table Generated model Both are right, but including them it case TimestampTz matters. The same generated table and model work when not using |
The reason is because
Does it work with standard |
Makes sense. Though V5 Has been out for ~4 years now so not expecting a major update any time soon, having the latest PGX version under I tried to JsonPQ version, same issue, must be something destination wise but the normal PQ/PGX versions work with the same dest which is odd. Just doing the typical Jet Generated Type type News struct {
Title string `json:"title"`
Body string `json:"body"`
Type string `json:"type"`
CreatedAt time.Time `json:"created_at"`
ID uuid.UUID `sql:"primary_key" json:"id"`
}My Custom Type package models
import "jetpgxpoc/gen/public/model"
type News struct {
model.News
} Then stmt := postgres.
SELECT_JSON_ARR(table.News.AllColumns).
FROM(table.News).
ORDER_BY(table.News.CreatedAt.DESC()).
LIMIT(limit)
var newsSlice []models.News // My custom type news
if err := stmt.QueryContext(ctx, db, &newsSlice); err != nil {We don't have to pollute this PR with this probably separate issue though. |
|
Aha I see where the issue is. CreatedAt time.Time `json:"created_at"you are using snake case. So the fix is: CreatedAt time.Time `json:"createdAt" // or `json:"CreatedAt" or you can remove json tag completely.Also |
Gotcha, I'll play more with it another time when optimizing complex join queries. I haven't run into any issues yet with implementing this PR into prod. Appreciate your great work as always! |
|
@go-jet How best to preform a pgx5 .Exec with query params()? |
|
@go-jet Bump 😇 |
Added pgxV5.Exec method. |
|
@go-jet May have found a bug, can you attempt to replicate? stmt := postgres.Select(table.News.ID).From(table.News).Limit(1)
var id uuid.UUID
err := pgxV5.Query(ctx, stmt, db, &id)When attempting to scan into a pointer to uuid.UUID, I'm getting the following: |
It's known bug- #412. Workaround: stmt := postgres.Select(
table.News.ID.AS("id"),
).From(table.News).Limit(1)
var dest struct {
ID uuid.UUID
}
err := pgxV5.Query(ctx, stmt, db, &dest) |
How to use:
where
pgxDBcan be*pgx.Tx,*pgxpool.Poolor*pgx.Conn.Default jet generator will work in most cases, except for some postgres specific types like
numeric,bit,point, etc...For those types you'll need to customize generator to use
pgtype.Numeric,pgtype.Bits,pgtype.Point, etc...The full list of such types can be found in this test.
The reason why it haven't been merged to master and released is:
All the tests are passing and you can give it a try.
Even if pgx branch doesn't get into next release I'll keep it in sync with master.