add sqlite test and fix sqlite tag queries.

This commit is contained in:
fiatjaf
2024-07-23 14:48:53 -03:00
committed by fiatjaf_
parent db5f761145
commit 7115e668cc
2 changed files with 13 additions and 3 deletions

View File

@@ -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 // we use a very bad implementation in which we only check the tag values and
// ignore the tag names // ignore the tag names
for _, tagValue := range tagQuery { if len(tagQuery) > 0 {
conditions = append(conditions, `tags LIKE ? ESCAPE '\'`) orTag := make([]string, len(tagQuery))
params = append(params, `%`+strings.ReplaceAll(tagValue, `%`, `\%`)+`%`) 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 { if filter.Since != nil {

View File

@@ -12,6 +12,7 @@ import (
"github.com/fiatjaf/eventstore/bolt" "github.com/fiatjaf/eventstore/bolt"
"github.com/fiatjaf/eventstore/lmdb" "github.com/fiatjaf/eventstore/lmdb"
"github.com/fiatjaf/eventstore/slicestore" "github.com/fiatjaf/eventstore/slicestore"
"github.com/fiatjaf/eventstore/sqlite3"
"github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@@ -41,6 +42,11 @@ func TestBolt(t *testing.T) {
runTestOn(t, &bolt.BoltBackend{Path: dbpath + "bolt"}) 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) { func runTestOn(t *testing.T, db eventstore.Store) {
err := db.Init() err := db.Init()
require.NoError(t, err) require.NoError(t, err)