Пример #1
0
def update_user(user_id, username):
    with INSERTION_LOCK:
        user = SESSION.query(Users).get(user_id)
        if not user:
            user = Users(user_id, username)
            SESSION.add(user)
            SESSION.flush()
        else:
            user.username = username
        SESSION.commit()
Пример #2
0
def update_creds(user_id,
                 spotify_id=None,
                 spotify_access_token=None,
                 spotify_refresh_token=None):
    with SPT_INSERTION_LOCK:
        sptcreds = SESSION.query(SpotifyCreds).get(user_id)
        if not sptcreds:
            sptcreds = SpotifyCreds(user_id, spotify_id, spotify_access_token,
                                    spotify_refresh_token)
            SESSION.add(sptcreds)
            SESSION.flush()
        else:
            sptcreds.spotify_id = spotify_id
            sptcreds.spotify_access_token = spotify_access_token
            sptcreds.spotify_refresh_token = spotify_refresh_token
        SESSION.commit()
Пример #3
0
def get_sptuser(user_id):
    try:
        return SESSION.query(SpotifyCreds).get(user_id)
    finally:
        SESSION.close()
Пример #4
0
def users_count():
    try:
        return SESSION.query(Users).count()
    finally:
        SESSION.close()
Пример #5
0
def get_all_users():
    try:
        return SESSION.query(Users).all()
    finally:
        SESSION.close()
Пример #6
0
def ensure_bot_in_db():
    with INSERTION_LOCK:
        bot = Users(dp.bot.id, dp.bot.username)
        SESSION.merge(bot)
        SESSION.commit()