Summary
gorqlite's Scan() supports custom nullable types (gorqlite.NullString, gorqlite.NullInt64, etc.) but does not support the standard library equivalents (sql.NullString, sql.NullInt64, sql.NullFloat64, sql.NullBool).
Attempting to scan into *sql.NullString returns:
unknown destination type (*sql.NullString) to scan into in variable #1
Motivation
Many Go codebases use database/sql nullable types as their standard pattern for handling NULL columns. When migrating to rqlite/gorqlite, users must rewrite all nullable field handling to use gorqlite-specific types or COALESCE workarounds. Supporting sql.Null* types natively would make gorqlite a drop-in replacement for more database/sql patterns.
Proposed Change
Add cases to the type switch in Scan() (query.go) for each sql.Null* type. For example:
case *sql.NullString:
switch src := src.(type) {
case string:
*d = sql.NullString{Valid: true, String: src}
case nil:
*d = sql.NullString{Valid: false}
default:
return fmt.Errorf("invalid string col:%d type:%T val:%v", n, src, src)
}
This would be ~30 lines of additions, fully backward-compatible, and follows the same pattern already used for gorqlite.NullString.
Types to add
*sql.NullString
*sql.NullInt64
*sql.NullInt32
*sql.NullInt16
*sql.NullFloat64
*sql.NullBool
*sql.NullTime
Environment
- gorqlite commit: ac86a4a (2025-06-09)
- Go 1.21+
Summary
gorqlite's
Scan()supports custom nullable types (gorqlite.NullString,gorqlite.NullInt64, etc.) but does not support the standard library equivalents (sql.NullString,sql.NullInt64,sql.NullFloat64,sql.NullBool).Attempting to scan into
*sql.NullStringreturns:Motivation
Many Go codebases use
database/sqlnullable types as their standard pattern for handling NULL columns. When migrating to rqlite/gorqlite, users must rewrite all nullable field handling to use gorqlite-specific types or COALESCE workarounds. Supportingsql.Null*types natively would make gorqlite a drop-in replacement for moredatabase/sqlpatterns.Proposed Change
Add cases to the type switch in
Scan()(query.go) for eachsql.Null*type. For example:This would be ~30 lines of additions, fully backward-compatible, and follows the same pattern already used for
gorqlite.NullString.Types to add
*sql.NullString*sql.NullInt64*sql.NullInt32*sql.NullInt16*sql.NullFloat64*sql.NullBool*sql.NullTimeEnvironment