From 90aacaae2a2d5b8462c9c5f6c6b619f5bf7b5d90 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Mon, 30 Jun 2025 12:28:55 +0200 Subject: [PATCH] sqldb: add SQLInt16 helper --- sqldb/sqlutils.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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. //