Exemple #1
0
 def empty_favorite(self):
     """
     Method that delete product substitute in table favorite
     """
     query = (" truncate `Favorite`")
     self.cursor.execute(query)
     connexion.commit()
Exemple #2
0
 def insert_data(self):
     """
     Insert data from categories list in category table
     """
     query2 = ("INSERT IGNORE INTO Category (id, name) VALUE (%s, %s)")
     for name_category in data_categories:
         self.cursor.execute(query2, (name_category[0], name_category[1]))
         connexion.commit()
Exemple #3
0
    def insert_data(self, name, url, grade, id_category, store):
        """
        Method that inserts data from API to Product table
        """

        query = ("INSERT IGNORE INTO Product "
                 "(name, url, grade, id_category, store)"
                 "VALUES (%s,  %s, %s, %s, %s)")
        self.cursor.execute(query, (name, url, grade, id_category, store))
        connexion.commit()
Exemple #4
0
 def create(self):
     """
     Create category table in database
     """
     query = ("CREATE TABLE IF NOT EXISTS `Category` ("
              "   `id` SMALLINT NOT NULL AUTO_INCREMENT,"
              "   `name` varchar(450) NOT NULL,"
              "   PRIMARY KEY (`id`)"
              ") ENGINE=InnoDB")
     self.cursor.execute(query)
     connexion.commit()
Exemple #5
0
 def insert_data(self, product_choice, product_substituted,
                 id_product_substitute, id_product):
     """Add the DATA in the favorite table
     """
     add_favorite = (
         "INSERT INTO `Favorite`"
         "(`product`,  `substitute`, `id_product_substitute`, `id_product`)"
         " VALUE (%s, %s, %s, %s)")
     data_field = (product_choice, product_substituted,
                   id_product_substitute, id_product)
     self.cursor.execute(add_favorite, data_field)
     connexion.commit()
Exemple #6
0
 def create(self):
     """
     Create Product table
     """
     query = (
         "CREATE TABLE IF NOT EXISTS `Product` ("
         "  `id` SMALLINT NOT NULL AUTO_INCREMENT,"
         "  `name` varchar(450) NOT NULL UNIQUE,"
         "  `url` varchar(450) NOT NULL,"
         "  `grade` varchar(40) ,"
         "  `id_category` SMALLINT NOT NULL ,"
         "  `store` varchar(540) ,"
         "  PRIMARY KEY (`id`),"
         "   CONSTRAINT  `fk_category_id` FOREIGN KEY (`id_category`)"
         "   REFERENCES `Category` (`id`) ON DELETE CASCADE ON UPDATE CASCADE"
         ") ENGINE=InnoDB")
     self.cursor.execute(query)
     connexion.commit()
Exemple #7
0
 def create(self):
     """
     Method that creates favorite table
     """
     query = (
         "CREATE TABLE IF NOT EXISTS `Favorite` ("
         "  `id` SMALLINT NOT NULL AUTO_INCREMENT,"
         "   `product` varchar(450) NOT NULL,"
         "   `substitute` varchar(450) NOT NULL,"
         "   `id_product_substitute` SMALLINT NOT NULL,"
         "   `id_product` SMALLINT NOT NULL,"
         "  PRIMARY KEY (`id`),"
         "   CONSTRAINT  `fk_favorite_id` FOREIGN KEY (`id_product_substitute`)"
         "   REFERENCES `Product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,"
         "   CONSTRAINT  `fk_product_id` FOREIGN KEY (`id_product`)"
         "   REFERENCES `Product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE"
         ") ENGINE=InnoDB")
     self.cursor.execute(query)
     connexion.commit()