add sqlite test and fix sqlite tag queries.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user