From 39b11dbfb6f18c85ebe157ea9f85c7378c2cfb59 Mon Sep 17 00:00:00 2001 From: kim Date: Thu, 26 Jun 2025 14:17:47 +0200 Subject: [bugfix] fix issues with postgres array serialization (#4295) thank you to @kipvandenbos -erino for figuring this out! Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4295 Co-authored-by: kim Co-committed-by: kim --- 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 6c743ffe9..d0d25a236 100644 --- a/internal/db/bundb/util.go +++ b/internal/db/bundb/util.go @@ -29,6 +29,7 @@ import ( "code.superseriousbusiness.org/gotosocial/internal/paging" "github.com/uptrace/bun" "github.com/uptrace/bun/dialect" + "github.com/uptrace/bun/dialect/pgdialect" ) // likeEscaper is a thread-safe string replacer which escapes @@ -60,6 +61,19 @@ func likeOperator(query *bun.SelectQuery) string { return "" } +// bunArrayType wraps the given type in a pgdialect.Array +// if needed, which postgres wants for serializing arrays. +func bunArrayType(db bun.IDB, arr any) any { + switch db.Dialect().Name() { + case dialect.SQLite: + return arr // return as-is + case dialect.PG: + return pgdialect.Array(arr) + default: + panic("unreachable") + } +} + // whereLike appends a WHERE clause to the // given SelectQuery, which searches for // matches of `search` in the given subQuery -- cgit v1.2.3