From 7e3400de029406ed110f5a4c249303d7f104c03f Mon Sep 17 00:00:00 2001 From: Dmitry Anderson <4nd3r5z0n@gmail.com> Date: Tue, 12 Nov 2024 09:53:46 +0100 Subject: [PATCH] Minor changes --- pg/pg.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pg/pg.go b/pg/pg.go index 65967d8..035a531 100644 --- a/pg/pg.go +++ b/pg/pg.go @@ -25,14 +25,13 @@ type PgxQuerier interface { // Usage: // // type User struct { -// id int -// name string +// id int `db:"id"` +// name string `db:"name"` // } // // db := pgx.Connect(context.Background(), "") -// users, err := pgUtils.Select[User](context.Background(), db, "SELECT * FROM users") +// users, err := pgUtils.Select[User](context.Background(), db, "SELECT id, name FROM users") func Select[T any](ctx context.Context, db PgxQuerier, query string, args ...any) (out []*T, err error) { - out = []*T{} rows, err := db.Query(ctx, query, args) if err != nil { switch { @@ -47,7 +46,8 @@ func Select[T any](ctx context.Context, db PgxQuerier, query string, args ...any for i, fd := range rows.FieldDescriptions() { columns[i] = fd.Name } - itemFieldPtrs := make([]interface{}, len(columns)) + itemFieldPtrs := make([]any, len(columns)) + out = []*T{} defer rows.Close() for rows.Next() {