diff options
Diffstat (limited to 'db.go')
-rw-r--r-- | db.go | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -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) |