bring in updates from relayer.

This commit is contained in:
fiatjaf
2023-10-31 15:49:01 -03:00
parent 473d817cc6
commit e95c3cb033
8 changed files with 48 additions and 34 deletions

View File

@@ -1,6 +1,7 @@
package postgresql
import (
"github.com/fiatjaf/eventstore"
"github.com/jmoiron/sqlx"
"github.com/jmoiron/sqlx/reflectx"
_ "github.com/lib/pq"
@@ -14,6 +15,8 @@ const (
queryTagsLimit = 10
)
var _ eventstore.Storage = (*PostgresBackend)(nil)
func (b *PostgresBackend) Init() error {
db, err := sqlx.Connect("postgres", b.DatabaseURL)
if err != nil {

View File

@@ -17,11 +17,13 @@ func (b PostgresBackend) QueryEvents(ctx context.Context, filter nostr.Filter) (
query, params, err := b.queryEventsSql(filter, false)
if err != nil {
close(ch)
return nil, err
}
rows, err := b.DB.Query(query, params...)
if err != nil && err != sql.ErrNoRows {
close(ch)
return nil, fmt.Errorf("failed to fetch events using query %q: %w", query, err)
}
@@ -155,11 +157,11 @@ func (b PostgresBackend) queryEventsSql(filter nostr.Filter, doCount bool) (stri
}
if filter.Since != nil {
conditions = append(conditions, "created_at > ?")
conditions = append(conditions, "created_at >= ?")
params = append(params, filter.Since)
}
if filter.Until != nil {
conditions = append(conditions, "created_at < ?")
conditions = append(conditions, "created_at <= ?")
params = append(params, filter.Until)
}