feat: update to v1.0.0 (#30)
This commit is contained in:
parent
2bdbbb274d
commit
73054fd5ce
20 changed files with 2029 additions and 2132 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Any, List, Optional, Tuple
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
|
@ -6,11 +6,11 @@ from .event import NostrEvent
|
|||
|
||||
|
||||
class NostrFilter(BaseModel):
|
||||
e: List[str] = Field(default=[], alias="#e")
|
||||
p: List[str] = Field(default=[], alias="#p")
|
||||
ids: List[str] = []
|
||||
authors: List[str] = []
|
||||
kinds: List[int] = []
|
||||
e: list[str] = Field(default=[], alias="#e")
|
||||
p: list[str] = Field(default=[], alias="#p")
|
||||
ids: list[str] = []
|
||||
authors: list[str] = []
|
||||
kinds: list[int] = []
|
||||
subscription_id: Optional[str] = None
|
||||
since: Optional[int] = None
|
||||
until: Optional[int] = None
|
||||
|
|
@ -66,16 +66,13 @@ class NostrFilter(BaseModel):
|
|||
if not self.limit or self.limit > limit:
|
||||
self.limit = limit
|
||||
|
||||
def to_sql_components(
|
||||
self, relay_id: str
|
||||
) -> Tuple[List[str], List[str], List[Any]]:
|
||||
inner_joins: List[str] = []
|
||||
where = ["deleted=false", "nostrrelay.events.relay_id = ?"]
|
||||
values: List[Any] = [relay_id]
|
||||
def to_sql_components(self, relay_id: str) -> tuple[list[str], list[str], dict]:
|
||||
inner_joins: list[str] = []
|
||||
where = ["deleted=false", "nostrrelay.events.relay_id = :relay_id"]
|
||||
values: dict = {"relay_id": relay_id}
|
||||
|
||||
if len(self.e):
|
||||
values += self.e
|
||||
e_s = ",".join(["?"] * len(self.e))
|
||||
e_s = ",".join([f"'{e}'" for e in self.e])
|
||||
inner_joins.append(
|
||||
"INNER JOIN nostrrelay.event_tags e_tags "
|
||||
"ON nostrrelay.events.id = e_tags.event_id"
|
||||
|
|
@ -83,8 +80,7 @@ class NostrFilter(BaseModel):
|
|||
where.append(f" (e_tags.value in ({e_s}) AND e_tags.name = 'e')")
|
||||
|
||||
if len(self.p):
|
||||
values += self.p
|
||||
p_s = ",".join(["?"] * len(self.p))
|
||||
p_s = ",".join([f"'{p}'" for p in self.p])
|
||||
inner_joins.append(
|
||||
"INNER JOIN nostrrelay.event_tags p_tags "
|
||||
"ON nostrrelay.events.id = p_tags.event_id"
|
||||
|
|
@ -92,26 +88,23 @@ class NostrFilter(BaseModel):
|
|||
where.append(f" p_tags.value in ({p_s}) AND p_tags.name = 'p'")
|
||||
|
||||
if len(self.ids) != 0:
|
||||
ids = ",".join(["?"] * len(self.ids))
|
||||
ids = ",".join([f"'{_id}'" for _id in self.ids])
|
||||
where.append(f"id IN ({ids})")
|
||||
values += self.ids
|
||||
|
||||
if len(self.authors) != 0:
|
||||
authors = ",".join(["?"] * len(self.authors))
|
||||
authors = ",".join([f"'{author}'" for author in self.authors])
|
||||
where.append(f"pubkey IN ({authors})")
|
||||
values += self.authors
|
||||
|
||||
if len(self.kinds) != 0:
|
||||
kinds = ",".join(["?"] * len(self.kinds))
|
||||
kinds = ",".join([f"'{kind}'" for kind in self.kinds])
|
||||
where.append(f"kind IN ({kinds})")
|
||||
values += self.kinds
|
||||
|
||||
if self.since:
|
||||
where.append("created_at >= ?")
|
||||
values += [self.since]
|
||||
where.append("created_at >= :since")
|
||||
values["since"] = self.since
|
||||
|
||||
if self.until:
|
||||
where.append("created_at < ?")
|
||||
values += [self.until]
|
||||
where.append("created_at < :until")
|
||||
values["until"] = self.until
|
||||
|
||||
return inner_joins, where, values
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue