From ddc120d5e6e0f18f235a6b5bbe5ceec86efedc41 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Thu, 26 Aug 2021 11:28:16 +0200 Subject: fix public timeline bug (#150) --- internal/db/bundb/util.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'internal/db/bundb/util.go') 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)) + } +} -- cgit v1.2.3