Skip to content

Commit 3f02afe

Browse files
committed
feat: added Query and QueryWithCtx functions to pgxpool Service interface and implementation
1 parent fe9171d commit 3f02afe

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

sql/pgxpool/service.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ type (
2424
query *string,
2525
params ...interface{},
2626
) (*pgconn.CommandTag, error)
27+
Query(query *string, params ...interface{}) (pgx.Rows, error)
28+
QueryWithCtx(
29+
ctx context.Context,
30+
query *string,
31+
params ...interface{},
32+
) (pgx.Rows, error)
2733
QueryRow(query *string, params ...interface{}) pgx.Row
2834
QueryRowWithCtx(
2935
ctx context.Context,
@@ -143,6 +149,29 @@ func (d *DefaultService) QueryRowWithCtx(
143149
return d.pool.QueryRow(ctx, *query, params...)
144150
}
145151

152+
// QueryWithCtx runs a query with parameters and returns the result with a context
153+
func (d *DefaultService) QueryWithCtx(
154+
ctx context.Context,
155+
query *string,
156+
params ...interface{},
157+
) (pgx.Rows, error) {
158+
// Check if the query is nil
159+
if query == nil {
160+
return nil, godatabases.ErrNilQuery
161+
}
162+
163+
// Run the query
164+
return d.pool.Query(ctx, *query, params...)
165+
}
166+
167+
// Query runs a query with parameters and returns the result
168+
func (d *DefaultService) Query(
169+
query *string,
170+
params ...interface{},
171+
) (pgx.Rows, error) {
172+
return d.QueryWithCtx(context.Background(), query, params...)
173+
}
174+
146175
// QueryRow runs a query row with parameters and returns the result row
147176
func (d *DefaultService) QueryRow(
148177
query *string,

0 commit comments

Comments
 (0)