示例#1
0
 def get_first(cls):
     """Fetch oldest VoiceActivity record from database."""
     with open_database() as database:
         cursor = database.cursor()
         sql = """SELECT member_id, member_name, date_time, channel_name, status
             FROM voice_activity
             ORDER BY id
             LIMIT 1"""
         cursor.execute(sql)
         result = cursor.fetchone()
         if result is None:
             return None
         return cls(*result)
示例#2
0
 def get_last(cls, member_id):
     """Fetch most recent VoiceActivity record for member from database."""
     with open_database() as database:
         cursor = database.cursor()
         sql = """SELECT member_id, member_name, date_time, channel_name, status
             FROM voice_activity
             WHERE member_id = ?
             ORDER BY id DESC
             LIMIT 1"""
         cursor.execute(sql, (member_id, ))
         result = cursor.fetchone()
         if result is None:
             return None
         return cls(*result)
示例#3
0
 def __store(self):
     """Store VoiceActivity instance in database."""
     with open_database() as database:
         cursor = database.cursor()
         sql = """INSERT 
             INTO voice_activity
             VALUES (?,?,?,?,?,?)"""
         values = [
             None, self.member_id, self.member_name, self.date_time,
             self.channel_name, self.status
         ]
         cursor.execute(sql, values)
         database.commit()
     return self
示例#4
0
 def get_all(cls, member_id, start, end):
     """Fetch all VoiceActivity records for member in database within [start, end] datetime interval."""
     with open_database() as database:
         cursor = database.cursor()
         sql = """SELECT member_id, member_name, date_time, channel_name, status
             FROM voice_activity
             WHERE member_id = ?
             AND date_time >= ?
             AND date_time <= ?
             ORDER BY id"""
         cursor.execute(sql, (member_id, start, end))
         results = cursor.fetchall()
         voice_activities = []
         for result in results:
             voice_activities.append(cls(*result))
         return voice_activities
def open_database_2(name_container):
    response = open_database(name_container)
    print("imprimiendo response")
    print(response)
    print("llamando a odb")
    return response