summaryrefslogtreecommitdiff
path: root/internal/db/bundb/account.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-06-10 10:56:49 +0200
committerLibravatar GitHub <noreply@github.com>2022-06-10 10:56:49 +0200
commit2385b51d5851195f6c418e72c35d1526519f23b0 (patch)
tree62c9c011b63c393913fd48656a525fa6be0f8132 /internal/db/bundb/account.go
parent[bugfix] Fix domain blocks get regression (#642) (diff)
downloadgotosocial-2385b51d5851195f6c418e72c35d1526519f23b0.tar.xz
[bugfix] Make accounts media_only query also work with pg (#643)
Diffstat (limited to 'internal/db/bundb/account.go')
-rw-r--r--internal/db/bundb/account.go26
1 files changed, 19 insertions, 7 deletions
diff --git a/internal/db/bundb/account.go b/internal/db/bundb/account.go
index 6061676c5..30510bb8e 100644
--- a/internal/db/bundb/account.go
+++ b/internal/db/bundb/account.go
@@ -25,11 +25,13 @@ import (
"strings"
"time"
+ "github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/cache"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/uptrace/bun"
+ "github.com/uptrace/bun/dialect"
)
type accountDB struct {
@@ -268,14 +270,24 @@ func (a *accountDB) GetAccountStatuses(ctx context.Context, accountID string, li
if mediaOnly {
// attachments are stored as a json object;
// this implementation differs between sqlite and postgres,
- // so we have to be very thorough to cover all eventualities
+ // so we have to be thorough to cover all eventualities
q = q.WhereGroup(" AND ", func(q *bun.SelectQuery) *bun.SelectQuery {
- return q.
- Where("? IS NOT NULL", bun.Ident("attachments")).
- Where("? != ''", bun.Ident("attachments")).
- Where("? != 'null'", bun.Ident("attachments")).
- Where("? != '{}'", bun.Ident("attachments")).
- Where("? != '[]'", bun.Ident("attachments"))
+ switch a.conn.Dialect().Name() {
+ case dialect.PG:
+ return q.
+ Where("? IS NOT NULL", bun.Ident("attachments")).
+ Where("? != '{}'", bun.Ident("attachments"))
+ case dialect.SQLite:
+ return q.
+ Where("? IS NOT NULL", bun.Ident("attachments")).
+ Where("? != ''", bun.Ident("attachments")).
+ Where("? != 'null'", bun.Ident("attachments")).
+ Where("? != '{}'", bun.Ident("attachments")).
+ Where("? != '[]'", bun.Ident("attachments"))
+ default:
+ logrus.Panic("db dialect was neither pg nor sqlite")
+ return q
+ }
})
}