2020-05-15 12:27:34 +02:00

25 lines
656 B
Python

import DataBase
from Camera import Camera
class CameraModel:
def getById(self, id):
db = DataBase.GetConnection()
cursor = db.cursor()
cursor.execute("""SELECT * FROM camera WHERE id=%s""", (id,))
row = cursor.fetchone()
cursor.close()
db.close()
if row:
return Camera(row[0], row[1], bool(row[2]), bool(row[3]), row[4])
return None
def update(self, camera):
db = DataBase.GetConnection()
cursor = db.cursor()
cursor.execute("""UPDATE camera SET available=%s, enabled=%s, rtmp_handle=%s WHERE id=%s""", (int(camera.available), int(camera.enabled), camera.rtmp_handle, camera.id))
cursor.close()
db.commit()
db.close()