From a9c88a040a3c8b178e50bdd4dc5fde0012b96baf Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Thu, 30 Jul 2026 22:53:28 +0200 Subject: gsql: add context.Context argument to GSQLClose() Required for pgx.Conn.Close(). --- gsql/gsql.go | 3 ++- gsql/std.go | 2 +- pgruntime/connector.go | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/gsql/gsql.go b/gsql/gsql.go index 939194b..7df830c 100644 --- a/gsql/gsql.go +++ b/gsql/gsql.go @@ -24,7 +24,8 @@ type ConnectionHandle interface { Handle // GSQLClose closes the connection represented by this handle. - GSQLClose() error + // Once this method has been called, other methods must not be called. + GSQLClose(ctx context.Context) error // GSQLTransact executes an action within a database transaction. // The callback will be provided with a [Handle] referring to the transaction. diff --git a/gsql/std.go b/gsql/std.go index 1d61371..321f32a 100644 --- a/gsql/std.go +++ b/gsql/std.go @@ -185,7 +185,7 @@ type sqlConnectionHandle[T sqlConnection] struct { } // GSQLClose implements the [ConnectionHandle] interface. -func (h sqlConnectionHandle[T]) GSQLClose() error { +func (h sqlConnectionHandle[T]) GSQLClose(ctx context.Context) error { return h.Base.Close() } diff --git a/pgruntime/connector.go b/pgruntime/connector.go index 082f970..5d74266 100644 --- a/pgruntime/connector.go +++ b/pgruntime/connector.go @@ -47,7 +47,7 @@ func (c Connector[T]) Connect(ctx context.Context, target ConnectionTarget, beha } err = behavior.applyTo(ctx, db) if err != nil { - return none, errext.WithCleanup(err, "db.Close", db.GSQLClose()) + return none, errext.WithCleanup(err, "db.Close", db.GSQLClose(ctx)) } return db, nil } @@ -105,8 +105,8 @@ func (c Connector[T]) prepareTestDatabase(ctx context.Context, target Connection } _, err = execQuery(ctx, db, "DROP DATABASE IF EXISTS "+quoteIdentifier(dbName), nil) if err != nil { - return errext.WithCleanup(err, "db.Close", db.GSQLClose()) + return errext.WithCleanup(err, "db.Close", db.GSQLClose(ctx)) } _, err = execQuery(ctx, db, "CREATE DATABASE "+quoteIdentifier(dbName), nil) - return errext.WithCleanup(err, "db.Close", db.GSQLClose()) + return errext.WithCleanup(err, "db.Close", db.GSQLClose(ctx)) } -- cgit v1.3.1