Replace database methods with peewee ORM #39
4 changed files with 12 additions and 11 deletions
|
@ -1,14 +1,15 @@
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import math
|
import math
|
||||||
import timeit
|
|
||||||
|
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from peewee import ModelSelect
|
|
||||||
from playhouse.shortcuts import model_to_dict
|
|
||||||
from peewee import *
|
from peewee import *
|
||||||
|
import nacl.hash
|
||||||
|
|
||||||
|
from src.server.validation import is_valid_base_comment
|
||||||
|
from src.misc import clean
|
||||||
|
|
||||||
|
|
||||||
def get_database_connection():
|
def get_database_connection():
|
||||||
|
@ -125,10 +126,6 @@ def comment_list(claim_id: str = None, parent_id: str = None,
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def clean(thing: dict) -> dict:
|
|
||||||
return {k: v for k, v in thing.items() if v is not None}
|
|
||||||
|
|
||||||
|
|
||||||
def get_comment(comment_id: str) -> dict:
|
def get_comment(comment_id: str) -> dict:
|
||||||
return (comment_list(expressions=(Comment.comment_id == comment_id), page_size=1)
|
return (comment_list(expressions=(Comment.comment_id == comment_id), page_size=1)
|
||||||
.get('items')
|
.get('items')
|
||||||
|
|
|
@ -7,7 +7,7 @@ from src.server.validation import is_valid_base_comment
|
||||||
from src.server.validation import is_valid_credential_input
|
from src.server.validation import is_valid_credential_input
|
||||||
from src.server.validation import validate_signature_from_claim
|
from src.server.validation import validate_signature_from_claim
|
||||||
from src.server.validation import body_is_valid
|
from src.server.validation import body_is_valid
|
||||||
from src.server.misc import get_claim_from_id
|
from src.misc import get_claim_from_id
|
||||||
from src.server.external import send_notifications
|
from src.server.external import send_notifications
|
||||||
from src.server.external import send_notification
|
from src.server.external import send_notification
|
||||||
import src.database.queries as db
|
import src.database.queries as db
|
||||||
|
|
|
@ -20,3 +20,7 @@ def clean_input_params(kwargs: dict):
|
||||||
kwargs[k] = v.strip()
|
kwargs[k] = v.strip()
|
||||||
if k in ID_LIST:
|
if k in ID_LIST:
|
||||||
kwargs[k] = v.lower()
|
kwargs[k] = v.lower()
|
||||||
|
|
||||||
|
|
||||||
|
def clean(thing: dict) -> dict:
|
||||||
|
return {k: v for k, v in thing.items() if v is not None}
|
|
@ -9,7 +9,7 @@ import src.database.queries as db
|
||||||
from src.database.writes import abandon_comment, create_comment
|
from src.database.writes import abandon_comment, create_comment
|
||||||
from src.database.writes import hide_comments
|
from src.database.writes import hide_comments
|
||||||
from src.database.writes import edit_comment
|
from src.database.writes import edit_comment
|
||||||
from src.server.misc import clean_input_params
|
from src.misc import clean_input_params
|
||||||
from src.server.errors import make_error, report_error
|
from src.server.errors import make_error, report_error
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
Loading…
Reference in a new issue