def init(cls): """ This method initializes the model. :rtype: None """ query = """ CREATE TABLE IF NOT EXISTS frame_sets ( id INTEGER PRIMARY KEY, video_id INTEGER ) """ Model.execute(query)
def update(self, video_id, uri=None): """ This method performs an update operation. :param int video_id: The video ID. :param str uri: The URI. :rtype: None """ fields = [] params = () if uri is not None: fields.append('uri = ?') params += (uri,) if len(fields) == 0: return False params += (video_id,) query = f""" UPDATE videos SET {', '.join(fields)} WHERE id = ? """ result = Model.execute(query, params) return True if result.rowcount == 1 else False
def update(self, transform_id, metadata=None, rejected=None): """ This method performs an update operation. :param int transform_id: The transform ID. :param str metadata: Metadata from the transform. :param int rejected: 1 or 0 for rejected or not rejected respectively. :rtype: bool """ fields = [] params = () if metadata is not None: fields.append('metadata = ?') params += (metadata, ) if rejected is not None: fields.append('rejected = ?') params += (rejected, ) if len(fields) == 0: return False params += (transform_id, ) query = f""" UPDATE transforms SET {', '.join(fields)} WHERE id = ? """ result = Model.execute(query, params) return True if result.rowcount == 1 else False
def init(cls): """ This method initializes the model. :rtype: None """ query = """ CREATE TABLE IF NOT EXISTS videos ( id INTEGER PRIMARY KEY, uri TEXT, filename TEXT, description TEXT ) """ Model.execute(query)
def init(cls): """ This method initializes the model. :rtype: None """ query = """ CREATE TABLE IF NOT EXISTS frames ( id INTEGER PRIMARY KEY, fk_frame_sets INTEGER, rejected INTEGER, FOREIGN KEY(fk_frame_sets) REFERENCES frame_sets(id) ON DELETE CASCADE ) """ Model.execute(query)
def init(cls): """ This method initializes the model. :rtype: None """ query = """ CREATE TABLE IF NOT EXISTS transform_sets ( id INTEGER PRIMARY KEY, name TEXT, fk_frame_sets INTEGER, fk_prev_transform_sets INTEGER, FOREIGN KEY(fk_frame_sets) REFERENCES frame_sets(id), FOREIGN KEY(fk_prev_transform_sets) REFERENCES transform_sets(id) ) """ Model.execute(query)
def list(self): """ This method performs a list operation. :rtype: tuple """ query = """ SELECT id, video_id FROM frame_sets """ result = Model.execute(query) return result.fetchall()
def list(self): """ This method performs a list operation. :rtype: tuple """ query = """ SELECT id, uri, filename, description FROM videos """ result = Model.execute(query) return result.fetchall()
def list(self): """ This method performs a list operation. :rtype: tuple """ query = """ SELECT id, name, fk_frame_sets, fk_prev_transform_sets FROM transform_sets """ result = Model.execute(query) return result.fetchall()
def select(self, video_id): """ This method performs a select operation. :param int video_id: The video ID. :rtype: tuple """ query = """ SELECT id, uri, filename, description FROM videos WHERE id = ? """ result = Model.execute(query, (video_id,)) return result.fetchone()
def delete(self, video_id): """ This method performs a delete operation. :param int video_id: The video ID. :rtype: bool """ query = """ DELETE FROM videos WHERE id = ? """ result = Model.execute(query, (video_id,)) return True if result.rowcount == 1 else False
def delete(self, frame_set_id): """ This method performs a delete operation. :param int frame_set_id: The frame set ID. :rtype: bool """ query = """ DELETE FROM frame_sets WHERE id = ? """ result = Model.execute(query, (frame_set_id,)) return True if result.rowcount == 1 else False
def select(self, frame_set_id): """ This method performs a select operation. :param int frame_set_id: The frame set ID. :rtype: tuple """ query = """ SELECT id, video_id FROM frame_sets WHERE id = ? """ result = Model.execute(query, (frame_set_id,)) return result.fetchone()
def select(self, transform_id): """ This method performs a select operation. :param int transform_id: The transform ID. :rtype: tuple """ query = """ SELECT id, fk_transform_sets, fk_frames, metadata, rejected FROM transforms WHERE id = ? """ result = Model.execute(query, (transform_id, )) return result.fetchone()
def select(self, transform_set_id): """ This method performs a select operation. :param int transform_set_id: The transform set ID. :rtype: tuple """ query = """ SELECT id, name, fk_frame_sets, fk_prev_transform_sets FROM transform_sets WHERE id = ? """ result = Model.execute(query, (transform_set_id, )) return result.fetchone()
def update(self, frame_id, rejected): """ This method performs an update operation. :param int frame_id: The frame ID. :param int rejected: 1 or 0 for rejected or not rejected respectively. :rtype: None """ query = """ UPDATE frames SET rejected = ? WHERE id = ? """ result = Model.execute(query, (rejected, frame_id)) return True if result.rowcount == 1 else False
def insert(self, video_id): """ This method performs an insert operation. :param int video_id: The foreign key video ID. :rtype: int """ query = """ INSERT INTO frame_sets (video_id) VALUES (?) """ result = Model.execute(query, (video_id,)) return result.lastrowid
def insert(self, uri, filename, description=None): """ This method performs an insert operation. :param str uri: The URI to the video. :param str filename: The filename for the video. :rtype: int """ query = """ INSERT INTO videos (uri, filename, description) VALUES (?, ?, ?) """ result = Model.execute(query, (uri, filename, description)) return result.lastrowid
def insert(self, frame_set_id, rejected): """ This method performs an insert operation. :param int frame_set_id: The frame set ID. :param int rejected: 1 or 0 for rejected or not rejected respectively. :rtype: int """ query = """ INSERT INTO frames (fk_frame_sets, rejected) VALUES (?, ?) """ result = Model.execute(query, (frame_set_id, rejected)) return result.lastrowid
def insert(self, name, frame_set_id, prev_transform_set_id=None): """ This method performs an insert operation. :param str name: The comma separated list of transform names. :param int frame_set_id: The frame set ID. :param int prev_transform_set_id: The previous transform set ID. :rtype: int """ query = """ INSERT INTO transform_sets (name, fk_frame_sets, fk_prev_transform_sets) VALUES (?, ?, ?) """ result = Model.execute(query, (name, frame_set_id, prev_transform_set_id)) return result.lastrowid
def insert(self, transform_set_id, frame_id, metadata, rejected): """ This method performs an insert operation. :param int transform_set_id: The transform set ID. :param int frame_id: The frame ID. :param str metadata: Metadata from the transform. :param int rejected: 1 or 0 for rejected or not rejected respectively. :rtype: int """ query = """ INSERT INTO transforms (fk_transform_sets, fk_frames, metadata, rejected) VALUES (?, ?, ?, ?) """ result = Model.execute( query, (transform_set_id, frame_id, metadata, rejected)) return result.lastrowid
def list(self, frame_set_id, length=-1, offset=None, rejected=True): """ This method performs a list operation. :param int frame_set_id: The frame set ID. :param int length: The optional length. :param int offset: The optional offset. :param bool rejected: True if should include rejected frames else False if should not. The defalut value is True. :rtype: tuple """ result = FrameSetModel().select(frame_set_id) if result is None: return None params = (frame_set_id, ) query = """ SELECT id, fk_frame_sets, rejected FROM frames WHERE fk_frame_sets = ? """ if rejected is False: query += ' AND rejected = 0' if length is not None: query += ' LIMIT ?' params += (length, ) if offset is not None: query += ' OFFSET ?' params += (offset, ) result = Model.execute(query, params) return result.fetchall()
def count(self, frame_set_id, rejected=True): """ This method performs a count operation. :param int frame_set_id: The frame set ID. :param bool rejected: True if should include rejected frames else False if should not. The default value is True. :rtype: int """ params = (frame_set_id, ) query = """ SELECT count(*) FROM frames WHERE fk_frame_sets = ? """ if rejected is False: query += ' AND rejected = 0' result = Model.execute(query, params) return result.fetchone()[0]