Skip to content

Commit

Permalink
add sqlite test and fix sqlite tag queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Jul 23, 2024
1 parent db5f761 commit 7115e66
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 7 additions & 3 deletions sqlite3/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions test/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7115e66

Please sign in to comment.