diff --git a/sqlite3/query.go b/sqlite3/query.go index 42b558d..5dde0da 100644 --- a/sqlite3/query.go +++ b/sqlite3/query.go @@ -120,9 +120,13 @@ func (b SQLite3Backend) queryEventsSql(filter nostr.Filter, doCount bool) (strin // we use a very bad implementation in which we only check the tag values and // ignore the tag names - for _, tagValue := range tagQuery { - conditions = append(conditions, `tags LIKE ? ESCAPE '\'`) - params = append(params, `%`+strings.ReplaceAll(tagValue, `%`, `\%`)+`%`) + if len(tagQuery) > 0 { + orTag := make([]string, len(tagQuery)) + for i, tagValue := range tagQuery { + orTag[i] = `tags LIKE ? ESCAPE '\'` + params = append(params, `%`+strings.ReplaceAll(tagValue, `%`, `\%`)+`%`) + } + conditions = append(conditions, "("+strings.Join(orTag, "OR ")+")") } if filter.Since != nil { diff --git a/test/db_test.go b/test/db_test.go index e56134c..bb5af17 100644 --- a/test/db_test.go +++ b/test/db_test.go @@ -12,6 +12,7 @@ import ( "github.com/fiatjaf/eventstore/bolt" "github.com/fiatjaf/eventstore/lmdb" "github.com/fiatjaf/eventstore/slicestore" + "github.com/fiatjaf/eventstore/sqlite3" "github.com/nbd-wtf/go-nostr" "github.com/stretchr/testify/require" ) @@ -41,6 +42,11 @@ func TestBolt(t *testing.T) { runTestOn(t, &bolt.BoltBackend{Path: dbpath + "bolt"}) } +func TestSQLite(t *testing.T) { + os.RemoveAll(dbpath + "sqlite") + runTestOn(t, &sqlite3.SQLite3Backend{DatabaseURL: dbpath + "sqlite"}) +} + func runTestOn(t *testing.T, db eventstore.Store) { err := db.Init() require.NoError(t, err)