mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-09 21:53:07 +02:00
sqldb: add SQLStrValid helper
The SQL* helpers are meant to always set the `Valid` field of the sql.Null* type to true. Otherwise they cannot be used to set a valid, empty field. However, we dont want to break the behaviour of the existing SQLStr helper and so this commit adds a new helper with the desired functionality.
This commit is contained in:
@@ -49,6 +49,10 @@ func SQLInt64[T constraints.Integer](num T) sql.NullInt64 {
|
||||
|
||||
// SQLStr turns a string into the NullString that sql/sqlc uses when a string
|
||||
// can be permitted to be NULL.
|
||||
//
|
||||
// NOTE: If the input string is empty, it returns a NullString with Valid set to
|
||||
// false. If this is not the desired behavior, consider using SQLStrValid
|
||||
// instead.
|
||||
func SQLStr(s string) sql.NullString {
|
||||
if s == "" {
|
||||
return sql.NullString{}
|
||||
@@ -60,6 +64,17 @@ func SQLStr(s string) sql.NullString {
|
||||
}
|
||||
}
|
||||
|
||||
// SQLStrValid turns a string into the NullString that sql/sqlc uses when a
|
||||
// string can be permitted to be NULL.
|
||||
//
|
||||
// NOTE: Valid is always set to true, even if the input string is empty.
|
||||
func SQLStrValid(s string) sql.NullString {
|
||||
return sql.NullString{
|
||||
String: s,
|
||||
Valid: true,
|
||||
}
|
||||
}
|
||||
|
||||
// SQLTime turns a time.Time into the NullTime that sql/sqlc uses when a time
|
||||
// can be permitted to be NULL.
|
||||
func SQLTime(t time.Time) sql.NullTime {
|
||||
|
Reference in New Issue
Block a user