aboutsummaryrefslogtreecommitdiff
path: root/db.go
diff options
context:
space:
mode:
Diffstat (limited to 'db.go')
-rw-r--r--db.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/db.go b/db.go
index 6aa53a5..7521666 100644
--- a/db.go
+++ b/db.go
@@ -156,7 +156,7 @@ func (db *SqliteDB) Stats() (*Stats, error) {
}
func (db *SqliteDB) ListEntries(limit int, offset int, user string,
- guild string, channel string) (*[]Entry, error) {
+ guild string, channel string, search string) (*[]Entry, error) {
query := `
SELECT urls.id, urls.url, users.user_id, guilds.guild_id, channels.channel_id, status_code
@@ -202,6 +202,20 @@ func (db *SqliteDB) ListEntries(limit int, offset int, user string,
args = append(args, channel)
}
}
+ if search != "" {
+ if !hasWhere {
+ query = fmt.Sprintf(`%s
+ WHERE urls.url LIKE '%%' || ? || '%%'
+ `, query)
+ args = append(args, search)
+ hasWhere = true
+ } else {
+ query = fmt.Sprintf(`%s
+ AND urls.url LIKE '%%' || ? || '%%'
+ `, query)
+ args = append(args, search)
+ }
+ }
query = fmt.Sprintf(`%s
ORDER BY urls.id DESC
LIMIT ? OFFSET ?;`, query)