diff --git a/packages/worker-relay/src/sqlite/sqlite-relay.ts b/packages/worker-relay/src/sqlite/sqlite-relay.ts index 40ba81f8..7e7614e8 100644 --- a/packages/worker-relay/src/sqlite/sqlite-relay.ts +++ b/packages/worker-relay/src/sqlite/sqlite-relay.ts @@ -325,9 +325,9 @@ export class SqliteRelay extends EventEmitter implements Rel operation = "delete"; } let sql = `${operation} from events`; - const tags = Object.entries(req).filter(([k]) => k.startsWith("#")); + const orTags = Object.entries(req).filter(([k]) => k.startsWith("#")); let tx = 0; - for (const [key, values] of tags) { + for (const [key, values] of orTags) { const vArray = values as Array; sql += ` inner join tags t_${tx} on events.id = t_${tx}.event_id and t_${tx}.key = ? and t_${tx}.value in (${this.#repeatParams( vArray.length, @@ -336,6 +336,15 @@ export class SqliteRelay extends EventEmitter implements Rel params.push(...vArray); tx++; } + const andTags = Object.entries(req).filter(([k]) => k.startsWith("&")); + for (const [key, values] of andTags) { + for (const value of values as Array) { + sql += ` inner join tags t_${tx} on events.id = t_${tx}.event_id and t_${tx}.key = ? and t_${tx}.value = ?`; + params.push(key.slice(1)); + params.push(value); + tx++; + } + } if (req.search) { sql += " inner join search_content on search_content.id = events.id"; conditions.push("search_content match ?");