diff --git a/sqldb/sqlutils.go b/sqldb/sqlutils.go index 1bf9164e2..bafba8416 100644 --- a/sqldb/sqlutils.go +++ b/sqldb/sqlutils.go @@ -11,6 +11,18 @@ import ( // reset function ExecTx calls. var NoOpReset = func() {} +// SQLInt16 turns a numerical integer type into the NullInt16 that sql/sqlc +// uses when an integer field can be permitted to be NULL. +// +// We use this constraints.Integer constraint here which maps to all signed and +// unsigned integer types. +func SQLInt16[T constraints.Integer](num T) sql.NullInt16 { + return sql.NullInt16{ + Int16: int16(num), + Valid: true, + } +} + // SQLInt32 turns a numerical integer type into the NullInt32 that sql/sqlc // uses when an integer field can be permitted to be NULL. //