aboutsummaryrefslogtreecommitdiff
path: root/pgruntime/connector.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-08-05 22:06:47 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-08-05 22:06:48 +0200
commit3e9488e22d43cfba0b9306cf916f95fd833fcd97 (patch)
tree97e9dc38cd262c71fa5ba826523b73d4b82c0021 /pgruntime/connector.go
parentbaab5f6fe0aafa7752f8e9ae86fc966afc18fe1a (diff)
downloadgo-gg-3e9488e22d43cfba0b9306cf916f95fd833fcd97.tar.gz
move pgruntime internal helpers to internal/gq
I want to use these in package pgtest.
Diffstat (limited to 'pgruntime/connector.go')
-rw-r--r--pgruntime/connector.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/pgruntime/connector.go b/pgruntime/connector.go
index 5276a26..76a45f1 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/internal/gq"
)
// Connector describes how to connect to a PostgreSQL database given a [libpq-style connection URI].
@@ -135,14 +136,14 @@ func (c Connector[T]) ConnectForTest(t assert.TestingTB, behavior ConnectionBeha
func createDatabaseIfMissing(ctx context.Context, db gsql.Handle, dbName string) error {
// check if database exists
- exists, err := selectOneValue[bool](ctx, db, `SELECT COUNT(*) > 0 FROM pg_catalog.pg_database WHERE datname = $1`, dbName)
+ exists, err := gq.SelectOneValue[bool](ctx, db, `SELECT COUNT(*) > 0 FROM pg_catalog.pg_database WHERE datname = $1`, dbName)
if err != nil {
return fmt.Errorf("while reading from pg_catalog.pg_database: %w", err)
}
// create database if necessary
if !exists {
- _, err = execQuery(ctx, db, "CREATE DATABASE "+quoteIdentifier(dbName), nil)
+ _, err = gq.ExecQuery(ctx, db, "CREATE DATABASE "+quoteIdentifier(dbName), nil)
if err != nil {
return fmt.Errorf("during CREATE DATABASE: %w", err)
}
@@ -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 := gq.SelectSeveralValues[string](ctx, db, query)
if err != nil {
return fmt.Errorf("while listing tables to truncate: %w", err)
}
@@ -166,7 +167,7 @@ func resetTestDatabase(ctx context.Context, db gsql.Handle, params testSetupPara
// truncate all tables at once
if len(quotedTableNames) > 0 {
query = fmt.Sprintf(`TRUNCATE %s RESTART IDENTITY CASCADE`, strings.Join(quotedTableNames, ", "))
- _, err = execQuery(ctx, db, query, nil)
+ _, err = gq.ExecQuery(ctx, db, query, nil)
if err != nil {
return fmt.Errorf("during %s: %w", query, err)
}