sqldb: add SQLInt16 helper

This commit is contained in:
Elle Mouton
2025-06-30 12:28:55 +02:00
parent fa32f97c05
commit 90aacaae2a

View File

@@ -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.
//