Skip to content

Commit 521198f

Browse files
committed
refactor: modified Query and QueryWithCtx functions from pgxpool Service
1 parent 3f02afe commit 521198f

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

sql/pgxpool/service.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (d *DefaultService) ExecWithCtx(
115115
) {
116116
// Check if the query is nil
117117
if query == nil {
118-
return nil, godatabases.ErrNilQuery
118+
panic(godatabases.ErrNilQuery)
119119
}
120120

121121
// Run the exec
@@ -134,21 +134,6 @@ func (d *DefaultService) Exec(query *string, params ...interface{}) (
134134
return d.ExecWithCtx(context.Background(), query, params...)
135135
}
136136

137-
// QueryRowWithCtx runs a query row with parameters and returns the result row with a context
138-
func (d *DefaultService) QueryRowWithCtx(
139-
ctx context.Context,
140-
query *string,
141-
params ...interface{},
142-
) pgx.Row {
143-
// Check if the query is nil
144-
if query == nil {
145-
return nil
146-
}
147-
148-
// Run the query row
149-
return d.pool.QueryRow(ctx, *query, params...)
150-
}
151-
152137
// QueryWithCtx runs a query with parameters and returns the result with a context
153138
func (d *DefaultService) QueryWithCtx(
154139
ctx context.Context,
@@ -157,7 +142,7 @@ func (d *DefaultService) QueryWithCtx(
157142
) (pgx.Rows, error) {
158143
// Check if the query is nil
159144
if query == nil {
160-
return nil, godatabases.ErrNilQuery
145+
panic(godatabases.ErrNilQuery)
161146
}
162147

163148
// Run the query
@@ -172,6 +157,21 @@ func (d *DefaultService) Query(
172157
return d.QueryWithCtx(context.Background(), query, params...)
173158
}
174159

160+
// QueryRowWithCtx runs a query row with parameters and returns the result row with a context
161+
func (d *DefaultService) QueryRowWithCtx(
162+
ctx context.Context,
163+
query *string,
164+
params ...interface{},
165+
) pgx.Row {
166+
// Check if the query is nil
167+
if query == nil {
168+
panic(godatabases.ErrNilQuery)
169+
}
170+
171+
// Run the query row
172+
return d.pool.QueryRow(ctx, *query, params...)
173+
}
174+
175175
// QueryRow runs a query row with parameters and returns the result row
176176
func (d *DefaultService) QueryRow(
177177
query *string,

0 commit comments

Comments
 (0)