-
Notifications
You must be signed in to change notification settings - Fork 39
Description
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+