diff options
author | 2021-08-26 11:28:16 +0200 | |
---|---|---|
committer | 2021-08-26 11:28:16 +0200 | |
commit | ddc120d5e6e0f18f235a6b5bbe5ceec86efedc41 (patch) | |
tree | 08869fd4514e7ba67c57e81e001df0e1c329414c /internal/db/bundb/util.go | |
parent | Pg to bun (#148) (diff) | |
download | gotosocial-ddc120d5e6e0f18f235a6b5bbe5ceec86efedc41.tar.xz |
fix public timeline bug (#150)
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)) + } +} |