Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backend/postgres/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ func (c *cursor) Scan(vs ...any) error {
return wrapErr(c.Cursor.Scan(vs...))
}

func (c *cursor) Err() error {
return wrapErr(c.Cursor.Err())
}

func IsPostgresDB(d sql.DB) bool {
_, ok := d.(*db)
return ok
Expand Down
17 changes: 17 additions & 0 deletions integration/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/upfluence/sql"
"github.com/upfluence/sql/sqltest"
Expand Down Expand Up @@ -40,6 +41,22 @@ func TestCanceled(t *testing.T) {
err := db.QueryRow(ctx, "SELECT 1").Scan()

assert.ErrorIs(t, err, context.Canceled)

ctx, done = context.WithCancel(context.Background())
cursor, err := db.Query(ctx, `
WITH RECURSIVE numbers(n) AS (
SELECT 1 UNION ALL SELECT n + 1 FROM numbers WHERE n < 5000
) SELECT n FROM numbers;
`) // postgres will cache the first few results in the first contact, we need more content

require.NoError(t, err)

done()

for cursor.Next() { // wait for error/exhaust
}

assert.ErrorIs(t, cursor.Err(), context.Canceled)
})
}

Expand Down
Loading