コード例 #1
0
ファイル: repository.py プロジェクト: news-collector/backend
    def update_last_activity_time(self, last_activity_time: datetime,
                                  _id: int):
        formatted_time = DateParser.parse(last_activity_time)

        bare_query = Query.update(users).set(
            self._fields['last_activity_time'],
            formatted_time).where(self._fields['id'] == _id)
        query = query_to_str(bare_query)

        rows_count = 0

        try:
            self._cursor.execute(query)
        except DBError as e:
            logging.error(
                f"Repository [{self._table}]: update_last_activity_time -> [{e.errno}]{e.msg}"
            )
            self._connection.rollback()
        else:
            self._connection.commit()
            rows_count = self._cursor.rowcount
            logging.info(
                f"Repository [{self._table}]: update_last_activity_time -> updated last activity time for user with id = {_id}"
            )

        return rows_count
コード例 #2
0
 def update_record(self, table, record, **where_values):
     table = Table(table)
     q = Query.update(table)
     for k, v in record.items():
         q = q.set(getattr(table, k), v)
     for k, v in where_values.items():
         q = q.where(getattr(table, k) == v)
     return q.get_sql()
コード例 #3
0
ファイル: app.py プロジェクト: huynhducduy/momo-backend
def disconnect(user_id):
    user = Table("user")
    q = Query.update(user).set(user.fb_id, None).where(user.id == user_id)

    cursor = get_db().cursor()
    cursor.execute(str(q))
    cursor.close()

    get_db().commit()

    return {"message": "success"}, 200
コード例 #4
0
    def updateDance(self, danceID, properties):

        properties.pop("id", None)
        t = Table("Dance")
        q = Query.update(t)
        for aKey in properties:
            q = q.set(aKey, properties[aKey])
        q = q.where(t.id == danceID)
        logger.debug(f'executing update string: {str(q)}')
        with self.connection.cursor() as cur:
            #TODO combine these into single atomic statement?
            cur.execute(str(q))
            rowCount = cur.execute(
                f'SELECT * FROM `Dance` where id = {danceID}')
            if (rowCount):
                rows = cur.fetchall()
                return rows[0]
            else:
                return None
コード例 #5
0
ファイル: app.py プロジェクト: huynhducduy/momo-backend
def connect(user_id):
    if request.is_json:
        data = request.get_json(silent=True)
        if data == None:
            abort(400)
        else:
            fb_id = data.get("fb_id")

            if fb_id == None:
                abort(400)

            cursor = get_db().cursor()

            user = Table("user")
            q = Query.from_(user).select(
                user.id).where(user.fb_id == fb_id).limit(1)

            cursor.execute(str(q))
            record = cursor.fetchone()
            cursor.close()

            if record != None:
                return (
                    jsonify({
                        "mesage":
                        "facebok account connected to another user"
                    }),
                    400,
                )
            else:
                q = Query.update(user).set(user.fb_id,
                                           fb_id).where(user.id == user_id)

                cursor = get_db().cursor()
                cursor.execute(str(q))
                cursor.close()

                get_db().commit()

                return {"message": "success"}, 200
    else:
        abort(400)
コード例 #6
0
ファイル: app.py プロジェクト: huynhducduy/momo-backend
def change_info(user_id):
    if request.is_json:
        data = request.get_json(silent=True)
        if data == None:
            abort(400)
        else:
            phone = data.get("phone")
            password = data.get("password")
            name = data.get("name")

            cursor = get_db().cursor()

            user = Table("user")

            q = Query.update(user)

            if phone:
                q = q.set(user.phone, phone)

            if password:
                q = q.set(user.password, password)

            if name:
                q = q.set(user.name, name)

            q = q.where(user.id == user_id)

            cursor = get_db().cursor()
            cursor.execute(str(q))
            cursor.close()

            get_db().commit()

            return {"message": "success"}, 200
    else:
        abort(400)
コード例 #7
0
 def test_update_with_limit_order(self):
     q = (MySQLQuery.update(self.table_abc).set(
         self.table_abc.lname, "test").limit(1).orderby(self.table_abc.id))
     self.assertEqual(
         "UPDATE `abc` SET `lname`='test' ORDER BY `id` LIMIT 1", str(q))