mirror of
https://github.com/fiatjaf/khatru.git
synced 2025-04-07 03:18:15 +02:00
add kind to filter and rebind query.
This commit is contained in:
parent
9c992c90dc
commit
e2adc6bc85
14
query.go
14
query.go
@ -24,6 +24,11 @@ func queryEvents(filter *filter.EventFilter) (events []event.Event, err error) {
|
||||
params = append(params, filter.Author)
|
||||
}
|
||||
|
||||
if filter.Kind != 0 {
|
||||
conditions = append(conditions, "kind = ?")
|
||||
params = append(params, filter.Kind)
|
||||
}
|
||||
|
||||
if filter.Authors != nil {
|
||||
inkeys := make([]string, 0, len(filter.Authors))
|
||||
for _, key := range filter.Authors {
|
||||
@ -58,10 +63,11 @@ func queryEvents(filter *filter.EventFilter) (events []event.Event, err error) {
|
||||
conditions = append(conditions, "true")
|
||||
}
|
||||
|
||||
err = db.Select(&events, "SELECT * FROM event WHERE "+
|
||||
strings.Join(conditions, " AND ")+
|
||||
"ORDER BY created_at LIMIT 100", params...,
|
||||
)
|
||||
query := db.Rebind("SELECT * FROM event WHERE " +
|
||||
strings.Join(conditions, " AND ") +
|
||||
"ORDER BY created_at LIMIT 100")
|
||||
|
||||
err = db.Select(&events, query, params...)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
log.Warn().Err(err).Interface("filter", filter).Msg("failed to fetch events")
|
||||
err = fmt.Errorf("failed to fetch events: %w", err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user