예제 #1
0
class AbstractDao:
    """Classe abstraite dont les DAO doivent hériter. Permet de gérer simplement la connection, et d'avoir des noms
    méthodes de base des DAO identique. Permet une meilleure lisibilité du code"""

    connection = get_connection()

    def find_by_id(self, id):
        """Va chercher une élément de la base grâce à son id et retourne l'objet python associé"""
        return NotImplementedError

    def find_all(self):
        """Retourne tous les éléments d'une table sous forme de liste d'objets python"""
        return NotImplementedError

    def update(self, business_object):
        """Met à jour la ligne en base de donnée associé à l'objet métier en paramètre"""
        return NotImplementedError

    def create(self, business_object):
        """Insère une ligne en base avec l'objet en paramètre. Retourne l'objet mise à jour avec son id de la base"""
        return NotImplementedError

    def delete(self, business_object):
        """Supprime la ligne en base représentant l'objet en paramètre"""
        return NotImplementedError
예제 #2
0
def get_actor_by_name(app, name):
    connect, cursor = connection.get_connection(app)
    cursor.execute(f"SELECT * FROM actors WHERE name LIKE '%{name}%'")
    data = cursor.fetchone()
    actor_by_name = actor.Actor(data[0], data[1], data[2], data[3], data[4],
                                data[5])
    return actor_by_name
예제 #3
0
def get_tv_show_by_name(app, name):
    connect, cursor = connection.get_connection(app)
    cursor.execute(f"SELECT * FROM tv_shows WHERE name LIKE '%{name}%'")
    data = cursor.fetchone()
    tvshow = tv_show.TvShow(data[0], data[1], data[2], data[3], data[4],
                            data[5], data[6], data[7])
    return tvshow
예제 #4
0
def get_actor(app, id):
    connect, cursor = connection.get_connection(app)
    cursor.execute(
        f"SELECT name, biografy, birthplace, birth, picture FROM actors WHERE id={id}"
    )
    data = cursor.fetchone()
    actor_by_id = actor.Actor(id, data[0], data[1], data[2], data[3], data[4])
    return actor_by_id
예제 #5
0
def edit_tv_show(app, id, name, description, seasons, birth, poster, trailer,
                 id_genre):
    print(id)
    connect, cursor = connection.get_connection(app)
    cursor.execute(
        f"UPDATE tv_shows SET name='{name}', description='{description}', seasons='{seasons}', "
        f"birth='{birth}', poster='{poster}', trailer='{trailer}', id_genre='{id_genre}' WHERE id={id}"
    )
    connect.commit()
예제 #6
0
def get_tv_show(app, id):
    connect, cursor = connection.get_connection(app)
    cursor.execute(
        f"SELECT name, description, seasons, birth, poster, trailer, id_genre FROM tv_shows WHERE id={id}"
    )
    data = cursor.fetchone()
    tvshow = tv_show.TvShow(id, data[0], data[1], data[2], data[3], data[4],
                            data[5], data[6])
    return tvshow
예제 #7
0
def insert_tv_show(app, name, description, seasons, birth, poster, trailer,
                   id_genre):
    connect, cursor = connection.get_connection(app)
    cursor.execute(
        f"INSERT INTO tv_shows (name, description, seasons, birth, poster, trailer, id_genre) "
        f"VALUES ('{name}', '{description}', '{seasons}', '{birth}', '{poster}', '{trailer}', '{id_genre}')"
    )
    cursor.close()
    connect.commit()
    connect.close()
예제 #8
0
def get_tv_show_by_genre(app, id):
    connect, cursor = connection.get_connection(app)
    cursor.execute(f"SELECT * FROM tv_shows WHERE id_genre={id}")
    datas = cursor.fetchall()
    tv_shows = []
    for data in datas:
        _tv_show = tv_show.TvShow(data[0], data[1], data[2], data[3], data[4],
                                  data[5], data[6], data[7])
        tv_shows.append(_tv_show)

    return tv_shows
예제 #9
0
파일: genre.py 프로젝트: pedromelo98/isdbpy
def get_all_genres(app):
    connect, cursor = connection.get_connection(app)
    cursor.execute(f"SELECT * FROM genres")
    data = cursor.fetchall()
    return data
예제 #10
0
파일: genre.py 프로젝트: pedromelo98/isdbpy
def get_genre_by_name(app, name):
    connect, cursor = connection.get_connection(app)
    cursor.execute(f"SELECT * FROM genres WHERE name='{name}'")
    data = cursor.fetchone()
    genre_by_name = genre.Genre(data[0], data[1])
    return genre_by_name
예제 #11
0
파일: genre.py 프로젝트: pedromelo98/isdbpy
def get_genre(app, id):
    connect, cursor = connection.get_connection(app)
    cursor.execute(f"SELECT name FROM genres WHERE id={id}")
    data = cursor.fetchone()
    genre_by_id = genre.Genre(id, data[0])
    return genre_by_id
예제 #12
0
def get_director(app, id):
    connect, cursor = connection.get_connection(app)
    cursor.execute(f"SELECT * from director WHERE id ={id}")
    data = cursor.fetchone()
    return data
예제 #13
0
def get_cast_ad(app, id_tvshow):
    connect, cursor = connection.get_connection(app)
    cursor.execute(
        f"SELECT id_actor, id_director FROM cast WHERE id_tvshow ={id_tvshow}")
    data = cursor.fetchall()
    return data
예제 #14
0
def init_db(self):
    Base.metadata.create_all(get_connection())
예제 #15
0
def get_all_actors(app):
    connect, cursor = connection.get_connection(app)
    cursor.execute(f"SELECT * FROM actors ORDER BY name")
    data = cursor.fetchall()
    return data
예제 #16
0
def delete_tv_show(app, id):
    connect, cursor = connection.get_connection(app)
    cursor.execute(f"DELETE FROM tv_shows WHERE id={id}")
    connect.commit()