How to use the tblib.model.session.rollback function in tblib

To help you get started, we’ve selected a few tblib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shiyanlou / louplus-python / taobei / tbuser / handlers / wallet_transaction.py View on Github external
payer = User.query.get(wallet_transaction.payer_id)
    if payer is None:
        return json_response(ResponseCode.NOT_FOUND)

    payee = User.query.get(wallet_transaction.payee_id)
    if payee is None:
        return json_response(ResponseCode.NOT_FOUND)

    count = User.query.filter(
        and_(User.id == payer.id, User.wallet_money >= wallet_transaction.amount,
             User.wallet_money == payer.wallet_money)
    ).update({
        User.wallet_money: payer.wallet_money - wallet_transaction.amount
    })
    if count == 0:
        session.rollback()
        return json_response(ResponseCode.TRANSACTION_FAILURE)

    count = User.query.filter(
        and_(User.id == payee.id, User.wallet_money == payee.wallet_money)
    ).update({
        User.wallet_money: payee.wallet_money + wallet_transaction.amount
    })
    if count == 0:
        session.rollback()
        return json_response(ResponseCode.TRANSACTION_FAILURE)

    session.add(wallet_transaction)

    session.commit()

    return json_response(wallet_transaction=WalletTransactionSchema().dump(wallet_transaction))
github shiyanlou / louplus-python / taobei / tbuser / handlers / wallet_transaction.py View on Github external
and_(User.id == payer.id, User.wallet_money >= wallet_transaction.amount,
             User.wallet_money == payer.wallet_money)
    ).update({
        User.wallet_money: payer.wallet_money - wallet_transaction.amount
    })
    if count == 0:
        session.rollback()
        return json_response(ResponseCode.TRANSACTION_FAILURE)

    count = User.query.filter(
        and_(User.id == payee.id, User.wallet_money == payee.wallet_money)
    ).update({
        User.wallet_money: payee.wallet_money + wallet_transaction.amount
    })
    if count == 0:
        session.rollback()
        return json_response(ResponseCode.TRANSACTION_FAILURE)

    session.add(wallet_transaction)

    session.commit()

    return json_response(wallet_transaction=WalletTransactionSchema().dump(wallet_transaction))