Cleanup, more typing for queries
This commit is contained in:
0
core/__init__.py
Normal file
0
core/__init__.py
Normal file
19
core/db.py
Normal file
19
core/db.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from enum import Enum
|
||||
from enum import unique
|
||||
from typing import Dict
|
||||
from typing import Any
|
||||
from typing import Optional
|
||||
|
||||
from config import DB
|
||||
|
||||
_Q = Dict[str, Any]
|
||||
_Doc = Optional[Dict[str, Any]]
|
||||
|
||||
|
||||
@unique
|
||||
class CollectionName(Enum):
|
||||
ACTIVITIES = "activities"
|
||||
|
||||
|
||||
def find_one_activity(q: _Q) -> _Doc:
|
||||
return DB[CollectionName.ACTIVITIES.value].find_one(q)
|
@@ -28,6 +28,7 @@ class MetaKey(Enum):
|
||||
GC_KEEP = "gc_keep"
|
||||
OBJECT = "object"
|
||||
OBJECT_ACTOR = "object_actor"
|
||||
PUBLIC = "public"
|
||||
|
||||
|
||||
def _meta(mk: MetaKey) -> str:
|
||||
@@ -56,3 +57,7 @@ def not_undo() -> _SubQuery:
|
||||
|
||||
def by_actor(actor: ap.BaseActivity) -> _SubQuery:
|
||||
return {_meta(MetaKey.ACTOR_ID): actor.id}
|
||||
|
||||
|
||||
def is_public() -> _SubQuery:
|
||||
return {_meta(MetaKey.PUBLIC): True}
|
||||
|
Reference in New Issue
Block a user