Exemplo n.º 1
0
def create_user(data: dict):
    user = User()
    user.login = data.get("login")
    user.password = data.get("password")
    try:
        with db.atomic() as transaction:
            try:
                user.save()
            except peewee.InternalError:
                transaction.rollback()
            else:
                transaction.commit()
    except peewee.IntegrityError:
        print(f"{data.get('login')}: Already exist.")
    return user.id
Exemplo n.º 2
0
def create_user(data):
    user = User()
    user.login = data.get("login")
    user.password = data.get("password")
    try:
        # атомик - если все транзакции успешные,
        # тогда сохр, а если нет, то ничего не сохр
        with db.atomic() as transaction:
            try:
                user.save()
            except peewee.InternalError as e:
                transaction.rollback()
                print(e)
                print("ERROR")
            else:
                transaction.commit()
                print("COMMIT")
    except peewee.IntegrityError:
        print(f"{data.get('login')}: Already exist.")
    return user.id