From 3dbef65bf37f1b7ccd1f884761341a5a15456ffa Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 31 May 2025 15:27:15 +0000 Subject: database/sql: allow drivers to override Scan behavior Implementing RowsColumnScanner allows the driver to completely control how values are scanned. Fixes #67546 Change-Id: Id8e7c3a973479c9665e4476fe2d29e1255aee687 GitHub-Last-Rev: ed0cacaec4a4feead56b09c0d6eee86ed58fe1ee GitHub-Pull-Request: golang/go#67648 Reviewed-on: https://go-review.googlesource.com/c/go/+/588435 Reviewed-by: David Chase Reviewed-by: Dmitri Shuralyov Reviewed-by: Sean Liao LUCI-TryBot-Result: Go LUCI --- src/database/sql/driver/driver.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/database/sql/driver/driver.go') diff --git a/src/database/sql/driver/driver.go b/src/database/sql/driver/driver.go index d0892e80fc..487870be63 100644 --- a/src/database/sql/driver/driver.go +++ b/src/database/sql/driver/driver.go @@ -515,6 +515,18 @@ type RowsColumnTypePrecisionScale interface { ColumnTypePrecisionScale(index int) (precision, scale int64, ok bool) } +// RowsColumnScanner may be implemented by [Rows]. It allows the driver to completely +// take responsibility for how values are scanned and replace the normal [database/sql]. +// scanning path. This allows drivers to directly support types that do not implement +// [database/sql.Scanner]. +type RowsColumnScanner interface { + Rows + + // ScanColumn copies the column in the current row into the value pointed at by + // dest. It returns [ErrSkip] to fall back to the normal [database/sql] scanning path. + ScanColumn(dest any, index int) error +} + // Tx is a transaction. type Tx interface { Commit() error -- cgit v1.3