diff options
Diffstat (limited to 'pysite/database.py')
-rw-r--r-- | pysite/database.py | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/pysite/database.py b/pysite/database.py index 015eeb13..82e1e84e 100644 --- a/pysite/database.py +++ b/pysite/database.py @@ -8,7 +8,6 @@ from flask import abort from rethinkdb.ast import RqlMethodQuery, Table, UserError from rethinkdb.net import DefaultConnection - ALL_TABLES = { # table: primary_key @@ -25,7 +24,7 @@ class RethinkDB: self.host = os.environ.get("RETHINKDB_HOST", "127.0.0.1") self.port = os.environ.get("RETHINKDB_PORT", "28016") self.database = os.environ.get("RETHINKDB_DATABASE", "pythondiscord") - self.log = logging.getLogger() + self.log = logging.getLogger(__name__) self.conn = None if loop_type: @@ -47,7 +46,7 @@ class RethinkDB: return created - def get_connection(self, connect_database: bool=True) -> DefaultConnection: + def get_connection(self, connect_database: bool = True) -> DefaultConnection: """ Grab a connection to the RethinkDB server, optionally without selecting a database @@ -83,8 +82,8 @@ class RethinkDB: # region: Convenience wrappers - def create_table(self, table_name: str, primary_key: str="id", durability: str="hard", shards: int=1, - replicas: Union[int, Dict[str, int]]=1, primary_replica_tag: Optional[str]=None) -> bool: + def create_table(self, table_name: str, primary_key: str = "id", durability: str = "hard", shards: int = 1, + replicas: Union[int, Dict[str, int]] = 1, primary_replica_tag: Optional[str] = None) -> bool: """ Attempt to create a new table on the current database @@ -126,7 +125,7 @@ class RethinkDB: def delete(self, table_name: str, primary_key: Union[str, None] = None, - durability: str="hard", + durability: str = "hard", return_changes: Union[bool, str] = False) -> dict: """ Delete one or all documents from a table. This can only delete @@ -195,8 +194,8 @@ class RethinkDB: return rethinkdb.table(table_name) - def run(self, query: RqlMethodQuery, *, new_connection: bool=False, - connect_database: bool=True, coerce: type=None) -> Union[rethinkdb.Cursor, List, Dict, object]: + def run(self, query: RqlMethodQuery, *, new_connection: bool = False, + connect_database: bool = True, coerce: type = None) -> Union[rethinkdb.Cursor, List, Dict, object]: """ Run a query using a table object obtained from a call to `query()` @@ -238,14 +237,14 @@ class RethinkDB: # region: RethinkDB wrapper functions def insert(self, table_name: str, *objects: Dict[str, Any], - durability: str="hard", - return_changes: Union[bool, str]=False, + durability: str = "hard", + return_changes: Union[bool, str] = False, conflict: Union[ # Any of... str, Callable[ # ...str, or a callable that... [Dict[str, Any], Dict[str, Any]], # ...takes two dicts with string keys and any values... Dict[str, Any] # ...and returns a dict with string keys and any values ] - ]="error") -> Union[List, Dict]: # flake8: noqa + ] = "error") -> Union[List, Dict]: # flake8: noqa """ Insert an object or a set of objects into a table @@ -285,7 +284,7 @@ class RethinkDB: return dict(result) if result else None # pragma: no cover - def get_all(self, table_name: str, *keys: str, index: str="id") -> List[Any]: + def get_all(self, table_name: str, *keys: str, index: str = "id") -> List[Any]: """ Get a list of documents matching a set of keys, on a specific index @@ -301,7 +300,7 @@ class RethinkDB: coerce=list ) - def wait(self, table_name: str, wait_for: str="all_replicas_ready", timeout: int=0) -> bool: + def wait(self, table_name: str, wait_for: str = "all_replicas_ready", timeout: int = 0) -> bool: """ Wait until an operation has happened on a specific table; will block the current function @@ -335,9 +334,9 @@ class RethinkDB: return result.get("synced", 0) > 0 # pragma: no cover - def changes(self, table_name: str, squash: Union[bool, int]=False, changefeed_queue_size: int=100_000, - include_initial: Optional[bool]=None, include_states: bool=False, - include_types: bool=False) -> Iterator[Dict[str, Any]]: + def changes(self, table_name: str, squash: Union[bool, int] = False, changefeed_queue_size: int = 100_000, + include_initial: Optional[bool] = None, include_states: bool = False, + include_types: bool = False) -> Iterator[Dict[str, Any]]: """ A complicated function allowing you to follow a changefeed for a specific table @@ -443,8 +442,9 @@ class RethinkDB: self.query(table_name).without(*selectors) ) - def between(self, table_name: str, *, lower: Any=rethinkdb.minval, upper: Any=rethinkdb.maxval, - index: Optional[str]=None, left_bound: str="closed", right_bound: str ="open") -> List[Dict[str, Any]]: + def between(self, table_name: str, *, lower: Any = rethinkdb.minval, upper: Any = rethinkdb.maxval, + index: Optional[str] = None, left_bound: str = "closed", right_bound: str = "open") -> List[ + Dict[str, Any]]: """ Get all documents between two keys @@ -506,7 +506,7 @@ class RethinkDB: ) def filter(self, table_name: str, predicate: Callable[[Dict[str, Any]], bool], - default: Union[bool, UserError]=False) -> List[Dict[str, Any]]: + default: Union[bool, UserError] = False) -> List[Dict[str, Any]]: """ Return all documents in a table for which `predicate` returns true. |