Example #1
0
def get_user(username: str, columns: list = None):
    columns_formatted = comma_join(columns) if columns else '*'
    return models.get_sql(
        statement="SELECT {} FROM users WHERE user_id=%s;".format(
            columns_formatted),
        values=[username],
        amount=1)
Example #2
0
def check_user_exists(user_id: str):
    '''
    check if the user exists in the database
    :param user_id:
    :return:
    '''
    return models.get_sql("SELECT COUNT(user_id) FROM users WHERE user_id=%s;",
                          values=[user_id],
                          amount=1)["COUNT(user_id)"] > 0
Example #3
0
def query_posts(start, end, user_id: int = None):
    if user_id:
        prepared_statement = "SELECT post_id, title, date_created, preview, user_id FROM posts WHERE user_id = %s ORDER BY date_created ASC;"
        values = [user_id]
    else:
        prepared_statement = "SELECT post_id, title, date_created, preview, user_id FROM posts ORDER BY date_created DESC LIMIT %s, %s;"
        values = [end, start]
    print(prepared_statement, values)
    return models.get_sql(prepared_statement,
                          values=values,
                          amount=start - end)
Example #4
0
def get_post(post_id: int):
    prepared_statement = "SELECT post_id, title, date_created, post_content, user_id FROM posts WHERE post_id = %s;"
    return models.get_sql(prepared_statement, values=[post_id], amount=1)
Example #5
0
def get_user_posts(user_id: int):
    prepared_statement = "SELECT post_id, title, date_created, preview, user_id FROM posts WHERE user_id=%s ORDER BY date_created ASC;"
    values = [user_id]
    return models.get_sql(prepared_statement, values=values, amount=FETCHALL)