aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-11-10 00:11:37 +0100
committerStefan Majewsky <majewsky@gmx.net>2026-11-10 00:11:37 +0100
commitedf487f2e1ff6f392a5b9ddc69a4a44a36ca4985 (patch)
tree3310b90b155ff7b7ab31ac6f566a3369c853637a
parentd2de069dd272447d0709beccd5afda7431a9021e (diff)
downloadgo-gg-edf487f2e1ff6f392a5b9ddc69a4a44a36ca4985.tar.gz
replace selectSeveralValues() with oblast.Select()
-rw-r--r--pgruntime/connector.go3
-rw-r--r--pgruntime/helpers.go20
2 files changed, 2 insertions, 21 deletions
diff --git a/pgruntime/connector.go b/pgruntime/connector.go
index 5276a26..c60b8d4 100644
--- a/pgruntime/connector.go
+++ b/pgruntime/connector.go
@@ -15,6 +15,7 @@ import (
"go.xyrillian.de/gg/assert"
"go.xyrillian.de/gg/errext"
"go.xyrillian.de/gg/gsql"
+ "go.xyrillian.de/gg/oblast"
)
// Connector describes how to connect to a PostgreSQL database given a [libpq-style connection URI].
@@ -158,7 +159,7 @@ func resetTestDatabase(ctx context.Context, db gsql.Handle, params testSetupPara
condition += ` AND table_name != 'schema_migrations'`
}
query := fmt.Sprintf(`SELECT quote_ident(table_name) FROM information_schema.tables WHERE %s ORDER BY table_name`, condition)
- quotedTableNames, err := selectSeveralValues[string](ctx, db, query)
+ quotedTableNames, err := oblast.Select[string](ctx, db, query).Collect()
if err != nil {
return fmt.Errorf("while listing tables to truncate: %w", err)
}
diff --git a/pgruntime/helpers.go b/pgruntime/helpers.go
index 1019e6e..3f4723a 100644
--- a/pgruntime/helpers.go
+++ b/pgruntime/helpers.go
@@ -47,26 +47,6 @@ func selectOneValue[T any](ctx context.Context, db gsql.Handle, query string, ar
return result, errext.WithCleanup(err, "stmt.Close", stmt.Close())
}
-// Convenience function for executing a one-off SQL query returning several single-column rows.
-// TODO: move to gsql (and also add ForeachValue with a callback instead of a slice return, maybe even ForeachPair and ForeachTriple)
-func selectSeveralValues[T any](ctx context.Context, db gsql.Handle, query string, args ...any) ([]T, error) {
- rows, err := db.GSQLQuery(ctx, query, args)
- if err != nil {
- return nil, err
- }
- var result []T
- for rows.Next() {
- // TODO: this should share growRecordSlice() from Oblast to optimize allocations
- var value T
- err := rows.Scan(&value)
- if err != nil {
- return nil, errext.WithCleanup(err, "rows.Close", rows.Close())
- }
- result = append(result, value)
- }
- return result, errext.WithCleanup(nil, "rows.Err", rows.Err())
-}
-
// Convenience function for preparing an identifier that needs to be inserted into a query verbatim
// (e.g. a database name for CREATE DATABASE).
func quoteIdentifier(name string) string {