diff --git a/graph/db/sql_migration.go b/graph/db/sql_migration.go index b88518fd8..dc615a2ca 100644 --- a/graph/db/sql_migration.go +++ b/graph/db/sql_migration.go @@ -1380,8 +1380,8 @@ func insertNodeSQLMig(ctx context.Context, db SQLQueries, if node.HaveNodeAnnouncement { params.LastUpdate = sqldb.SQLInt64(node.LastUpdate.Unix()) - params.Color = sqldb.SQLStr(EncodeHexColor(node.Color)) - params.Alias = sqldb.SQLStr(node.Alias) + params.Color = sqldb.SQLStrValid(EncodeHexColor(node.Color)) + params.Alias = sqldb.SQLStrValid(node.Alias) params.Signature = node.AuthSigBytes } diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go index c53a0fe5c..340a72fee 100644 --- a/graph/db/sql_store.go +++ b/graph/db/sql_store.go @@ -3391,8 +3391,8 @@ func upsertNode(ctx context.Context, db SQLQueries, if node.HaveNodeAnnouncement { params.LastUpdate = sqldb.SQLInt64(node.LastUpdate.Unix()) - params.Color = sqldb.SQLStr(EncodeHexColor(node.Color)) - params.Alias = sqldb.SQLStr(node.Alias) + params.Color = sqldb.SQLStrValid(EncodeHexColor(node.Color)) + params.Alias = sqldb.SQLStrValid(node.Alias) params.Signature = node.AuthSigBytes } diff --git a/sqldb/sqlutils.go b/sqldb/sqlutils.go index 8745fe2f7..ce99eb682 100644 --- a/sqldb/sqlutils.go +++ b/sqldb/sqlutils.go @@ -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 {