| tierno | 5c01261 | 2018-04-19 16:01:59 +0200 | [diff] [blame] | 1 | from http import HTTPStatus |
| 2 | |
| 3 | __author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>" |
| 4 | |
| 5 | |
| 6 | class DbException(Exception): |
| 7 | |
| 8 | def __init__(self, message, http_code=HTTPStatus.NOT_FOUND): |
| tierno | ebbf353 | 2018-05-03 17:49:37 +0200 | [diff] [blame] | 9 | # TODO change to http.HTTPStatus instead of int that allows .value and .name |
| tierno | 5c01261 | 2018-04-19 16:01:59 +0200 | [diff] [blame] | 10 | self.http_code = http_code |
| 11 | Exception.__init__(self, "database exception " + message) |
| 12 | |
| 13 | |
| 14 | class DbBase(object): |
| 15 | |
| 16 | def __init__(self): |
| 17 | pass |
| 18 | |
| 19 | def db_connect(self, config): |
| 20 | pass |
| 21 | |
| 22 | def db_disconnect(self): |
| 23 | pass |
| 24 | |
| 25 | def get_list(self, table, filter={}): |
| tierno | ebbf353 | 2018-05-03 17:49:37 +0200 | [diff] [blame] | 26 | raise DbException("Method 'get_list' not implemented") |
| tierno | 5c01261 | 2018-04-19 16:01:59 +0200 | [diff] [blame] | 27 | |
| 28 | def get_one(self, table, filter={}, fail_on_empty=True, fail_on_more=True): |
| tierno | ebbf353 | 2018-05-03 17:49:37 +0200 | [diff] [blame] | 29 | raise DbException("Method 'get_one' not implemented") |
| tierno | 5c01261 | 2018-04-19 16:01:59 +0200 | [diff] [blame] | 30 | |
| 31 | def create(self, table, indata): |
| tierno | ebbf353 | 2018-05-03 17:49:37 +0200 | [diff] [blame] | 32 | raise DbException("Method 'create' not implemented") |
| tierno | 5c01261 | 2018-04-19 16:01:59 +0200 | [diff] [blame] | 33 | |
| 34 | def del_list(self, table, filter={}): |
| tierno | ebbf353 | 2018-05-03 17:49:37 +0200 | [diff] [blame] | 35 | raise DbException("Method 'del_list' not implemented") |
| tierno | 5c01261 | 2018-04-19 16:01:59 +0200 | [diff] [blame] | 36 | |
| 37 | def del_one(self, table, filter={}, fail_on_empty=True): |
| tierno | ebbf353 | 2018-05-03 17:49:37 +0200 | [diff] [blame] | 38 | raise DbException("Method 'del_one' not implemented") |