def select_by_ids(video_ids: list): """ select count(*) from audios :return: record size """ tupVar = tuple(video_ids) # sql语句 建表 sql = """SELECT * FROM videos where id in %s;""" db = PostgreSql() results = db.select_by_ids(sql, (tupVar, )) videos = list() for result in results: video_id = result['id'] video_name = result['name'] video_md5 = result['md5'] video_format = result['format'] local_video_path = result['local_video_path'] cloud_video_path = result['cloud_video_path'] cloud_cover_path = result['cloud_cover_path'] date_created = result['date_created'] size = result['size'] video = Video(video_id, video_name, video_md5, video_format, local_video_path, cloud_video_path, cloud_cover_path, size, date_created) videos.append(video) return videos
def select_by_id(video_id: str): """ SELECT * FROM videos where id = :return: record size """ sql = """SELECT * FROM videos where id = %s;""" db = PostgreSql() params = (video_id, ) result = db.select_one(sql, params) return result
def count_by_md5(md5: str) -> int: """ select count(*) from videos :return: record size """ # sql语句 建表 sql = """SELECT count(*) FROM videos where md5 = %s;""" params = (md5, ) db = PostgreSql() count = db.count(sql, params) return count
def select_by_md5(md5: str) -> Dict[str, any]: """ SELECT * FROM audios where md5 = %s; :return: audio """ # sql语句 建表 sql = """SELECT * FROM audios where md5 = %s;""" params = (md5,) db = PostgreSql() audio = db.select_one(sql, params) return audio
def insert(id: str, name: str, format: str, md5: str, local_audio_path: str, video_id: str, date_created: str): """ insert into videos :return: """ sql = """INSERT INTO audios (id, name, format, md5, local_audio_path, video_id, date_created) VALUES (%(id)s, %(name)s, %(format)s, %(md5)s, %(local_audio_path)s, %(video_id)s, %(date_created)s)""" params = {'id': id, 'name': name, 'format': format, 'md5': md5, 'local_audio_path': local_audio_path, 'video_id': video_id, 'date_created': date_created} db = PostgreSql() db.execute(sql, params)
def insert(id: str, name: str, live_id: str, local_video_path: str, duration: int, stage: int, segment: bool): sql = """INSERT INTO videos (id, name, live_id, local_video_path, duration, stage, segment) VALUES (%(id)s, %(name)s, %(live_id)s, %(local_video_path)s, %(duration)s, %(stage)s, %(segment)s)""" params = { 'id': id, 'name': name, 'live_id': live_id, 'local_video_path': local_video_path, 'duration': duration, 'stage': stage, 'segment': segment } db = PostgreSql() db.execute(sql, params)
def insert(id: str, name: str, format: str, md5: str, local_video_path: str, cloud_video_path: str, cloud_cover_path: str, size: int, date_created: str): sql = """INSERT INTO videos (id, name, format, md5, local_video_path, cloud_video_path, cloud_cover_path, size, date_created) VALUES (%(id)s, %(name)s, %(format)s, %(md5)s, %(local_video_path)s, %(cloud_video_path)s, %(cloud_cover_path)s, %(size)s, %(date_created)s)""" params = { 'id': id, 'name': name, 'format': format, 'md5': md5, 'local_video_path': local_video_path, 'cloud_video_path': cloud_video_path, 'cloud_cover_path': cloud_cover_path, 'size': size, 'date_created': date_created } db = PostgreSql() db.execute(sql, params)
def select_by_ids(audio_ids: list): """ select count(*) from audios :return: record size """ tupVar = tuple(audio_ids) # sql语句 建表 sql = """SELECT * FROM audios where id in %s;""" db = PostgreSql() results = db.select_by_ids(sql, (tupVar,)) audios = list() for result in results: audio_id = result['id'] audio_name = result['name'] audio_md5 = result['md5'] video_id = result['video_id'] local_audio_path = result['local_audio_path'] format = result['format'] date_created = result['date_created'] audio = Audio(audio_id,audio_name,audio_md5,video_id,local_audio_path,format,date_created) audios.append(audio) return audios