diff options
Diffstat (limited to 'internal/db/bundb/util.go')
-rw-r--r-- | internal/db/bundb/util.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/internal/db/bundb/util.go b/internal/db/bundb/util.go index 115d18de2..faa80221f 100644 --- a/internal/db/bundb/util.go +++ b/internal/db/bundb/util.go @@ -76,3 +76,17 @@ func notExists(ctx context.Context, q *bun.SelectQuery) (bool, db.Error) { return notExists, nil } + +// whereEmptyOrNull is a convenience function to return a bun WhereGroup that specifies +// that the given column should be EITHER an empty string OR null. +// +// Use it as follows: +// +// q = q.WhereGroup(" AND ", whereEmptyOrNull("whatever_column")) +func whereEmptyOrNull(column string) func(*bun.SelectQuery) *bun.SelectQuery { + return func(q *bun.SelectQuery) *bun.SelectQuery { + return q. + WhereOr("? IS NULL", bun.Ident(column)). + WhereOr("? = ''", bun.Ident(column)) + } +} |