def addFilm(self, film): try: film = objectview(film) _sqls = [{ 'query': FilmSql.INSERT_FILM, 'args': (film.title or None, film.description or None, film.release_year or None, film.language_id or None, film.original_language_id or None, film.rental_duration or 0, film.rental_rate or 0, film.length or None, film.replacement_cost or 0, film.rating or None, film.special_features or None) }] _sqls.append({ 'query': FilmSql.INSERT_FILM_CATEGORY, 'args': (film.category_id) }) for actor_id in film.actor_ids: _sqls.append({ 'query': FilmSql.INSERT_FILM_ACTOR, 'args': (actor_id) }) DButils.executeSqls(_sqls) return True except Exception as e: raise Exception(e)
def deleteFilm(self, id): try: sqls = [{ 'query': FilmSql.DELETE_ACTOR_FILM, 'args': id }, { 'query': FilmSql.DELETE_CATEGORY_FILM, 'args': id }, { 'query': FilmSql.DELETE_FILM, 'args': id }] return DButils.executeSqls(sqls) except Exception as e: raise e
def updateFilm(self, film): try: pass # get film filmDB = DButils.execute(FilmSql.SELECT_FILM_BY_ID, film['film_id']) film = objectview({**filmDB, **film}) # update film film_actor film_category _sqls = [] _sqls.append({ 'query': FilmSql.UPDATE_FILM, 'args': (film.title or None, film.description or None, film.release_year or None, film.language_id or None, film.original_language_id or None, film.rental_duration or 0, film.rental_rate or 0, film.length or None, film.replacement_cost or 0, film.rating or None, film.special_features or None, film.film_id) }) if film.category_id is not None: _sqls.append({ 'query': FilmSql.UPDATE_CATEGORY_FILM, 'args': (film.category_id, film.film_id) }) if film.actor_ids is not None and len(film.actor_ids) > 0: _sqls.append({ 'query': FilmSql.DELETE_ACTOR_FILM, 'args': film.film_id }) for actor_id in film.actor_ids: _sqls.append({ 'query': FilmSql.INSERT_ACTOR_FILM_WITH_ID, 'args': (actor_id, film.film_id) }) return DButils.executeSqls(_sqls) except Exception as e: raise e