diff options
author | 2021-05-29 19:36:54 +0200 | |
---|---|---|
committer | 2021-05-29 19:36:54 +0200 | |
commit | 0fe853b1ee644703e2273ed4ce331cfd377af268 (patch) | |
tree | 4ada75ed683fa5ed302957c61aa91f4cf409ca01 /internal/db | |
parent | federate account updates (diff) | |
download | gotosocial-0fe853b1ee644703e2273ed4ce331cfd377af268.tar.xz |
first implementation of search feature
Diffstat (limited to 'internal/db')
-rw-r--r-- | internal/db/db.go | 5 | ||||
-rw-r--r-- | internal/db/pg/pg.go | 7 |
2 files changed, 9 insertions, 3 deletions
diff --git a/internal/db/db.go b/internal/db/db.go index e71484a6d..ea6f808cf 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -45,8 +45,9 @@ func (e ErrAlreadyExists) Error() string { } type Where struct { - Key string - Value interface{} + Key string + Value interface{} + CaseInsensitive bool } // DB provides methods for interacting with an underlying database or other storage mechanism (for now, just postgres). diff --git a/internal/db/pg/pg.go b/internal/db/pg/pg.go index 64d6fb636..92aa2849a 100644 --- a/internal/db/pg/pg.go +++ b/internal/db/pg/pg.go @@ -223,7 +223,12 @@ func (ps *postgresService) GetWhere(where []db.Where, i interface{}) error { q := ps.conn.Model(i) for _, w := range where { - q = q.Where("? = ?", pg.Safe(w.Key), w.Value) + if w.CaseInsensitive { + q = q.Where("LOWER(?) = LOWER(?)", pg.Safe(w.Key), w.Value) + } else { + q = q.Where("? = ?", pg.Safe(w.Key), w.Value) + } + } if err := q.Select(); err != nil { |