def get_task_by_id(task_id):
    q = qb.make('select', __table__)

    qb.set_columns(q, __fields__)
    qb.add_where(q, '%(pk)s = {%(pk)s}' % {'pk': __fields__[0]}, {
        __fields__[0]: task_id
    })

    cursor = raw_query(*qb.to_sql(q))

    return make_task_from_row(cursor.fetchone())
def update_tasks(query):
    if isinstance(query, dict):
        qb.set_table(query, __table__)
        qb.set_columns(query, __fields__)

        query, params = qb.to_sql(query)
    else:
        query, params = query, {}

    cursor = raw_query(query, params)

    return cursor.rowcount
示例#3
0
def get_user_by_credentials(email, password):
    q = qb.make('select', __table__)
    qb.set_columns(q, __fields__)
    qb.add_where(q, 'email = {email}', {'email': email})
    qb.set_limit(q, 1)

    cursor = raw_query(*qb.to_sql(q))

    user = make_user_from_row(cursor.fetchone())

    if user is not None and not check_password(password, user['password']):
        return None

    return user
示例#4
0
def get_user_by_id(user_id):
    user_cached = cache.load(__cache_key__ % user_id)
    if user_cached:
        return user_cached

    q = qb.make('select', __table__)
    qb.set_columns(q, __fields__)
    qb.add_where(q, '%(pk)s = {%(pk)s}' % {'pk': __fields__[0]},
                 {__fields__[0]: user_id})

    cursor = raw_query(*qb.to_sql(q))

    user = make_user_from_row(cursor.fetchone())

    cache.store(__cache_key__ % user_id, user, __cache_ttl__)

    return user
示例#5
0
def select_transactions(query):
    if isinstance(query, dict):
        qb.set_table(query, __table__)
        qb.set_columns(query, __fields__)

        query, params = qb.to_sql(query)
    else:
        query, params = query, {}

    cursor = raw_query(query, params)

    while True:
        row = cursor.fetchone()

        if row is None:
            return

        yield make_transaction_from_row(row)