forked from Tribler/tribler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorm_query.py
53 lines (38 loc) · 1.09 KB
/
orm_query.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from __future__ import annotations
from typing import TYPE_CHECKING
from pony import orm
if TYPE_CHECKING:
from dataclasses import dataclass
from typing import Iterator
from pony.orm import Database
from pony.orm.core import Entity
class IterQuery(type): # noqa: D101
def __iter__(cls) -> Iterator[Query]: ... # noqa: D105
@dataclass
class Query(Entity, metaclass=IterQuery):
"""
A generic query data object.
"""
rowid: int
version: int
json: str
"""
{
chosen_index: int,
timestamp: int,
query: str,
results: [{infohash: str, seeders: int, leechers: int}]
}
"""
def define_binding(db: Database) -> type[Query]:
"""
Create the Query binding.
"""
class Query(db.Entity):
"""
This ORM binding class is intended to store generic Query objects.
"""
rowid = orm.PrimaryKey(int, size=64, auto=True)
version = orm.Required(int, size=16)
json = orm.Required(str)
return Query