aboutsummaryrefslogtreecommitdiffstats
path: root/pysite/database.py
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2018-03-06 20:05:44 +0100
committerGravatar Jeremiah Boby <[email protected]>2018-03-06 19:05:44 +0000
commit5d685b27c5454e29809fe6039e0cf8945cbbb52f (patch)
tree2782bd8144f744bfc46924f64fb57f465cf31d67 /pysite/database.py
parentFix user API test (diff)
API for tags (#34)
* Help page and misc improvements Committing so I can go home >:| * [WIP] - API improvements for the tag features. Not completed. * renaming tag.py to tags.py and refactoring the nomenclature of docs to tags * fixed error message in tags, cleaning up app_test.py * tests for the tags feature * ignoring jsonify returns cause coverall can't handle them * Catch-all error view for the API blueprint * cleaning up APIErrorView a little * bringing coverage for tags.py to 100% * how did this get in here? * how did this get in here? ROUND 2 * Removing the 503 database error handling. It's not in use and we should probably rethink that whole custom error handling system anyway. * Converting the tags file to use the @api_params decorator instead of validating manually. Tested with bot staging.
Diffstat (limited to 'pysite/database.py')
-rw-r--r--pysite/database.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/pysite/database.py b/pysite/database.py
index 78c4368a..add76923 100644
--- a/pysite/database.py
+++ b/pysite/database.py
@@ -103,6 +103,34 @@ class RethinkDB:
self.log.debug(f"Table created: '{table_name}'")
return True
+ def delete(self, table_name: str, primary_key: Optional[str] = None,
+ durability: str = "hard", return_changes: Union[bool, str] = False
+ ) -> Union[Dict[str, Any], None]:
+ """
+ Delete one or all documents from a table. This can only delete
+ either the contents of an entire table, or a single document.
+ For more complex delete operations, please use self.query.
+
+ :param table_name: The name of the table to delete from. This must be provided.
+ :param primary_key: The primary_key to delete from that table. This is optional.
+ :param durability: "hard" (the default) to write the change immediately, "soft" otherwise
+ :param return_changes: Whether to return a list of changed values or not - defaults to False
+ :return: if return_changes is True, returns a dict containing all changes. Else, returns None.
+ """
+
+ if primary_key:
+ query = self.query(table_name).get(primary_key).delete(
+ durability=durability, return_changes=return_changes
+ )
+ else:
+ query = self.query(table_name).delete(
+ durability=durability, return_changes=return_changes
+ )
+
+ if return_changes:
+ return self.run(query, coerce=dict)
+ self.run(query)
+
def drop_table(self, table_name: str):
"""
Attempt to drop a table from the database, along with its data
@@ -168,7 +196,7 @@ class RethinkDB:
:param connect_database: If creating a new connection, whether to connect to the database immediately
:param coerce: Optionally, an object type to attempt to coerce the result to
- :return: THe result of the operation
+ :return: The result of the operation
"""
if not new_connection: