import sqlite3


class Database:
    def __init__(self, db):
        self.conn = sqlite3.connect(db)
        self.cur = self.conn.cursor()
        self.cur.execute(
            "CREATE TABLE IF NOT EXISTS parts(id INTEGER PRIMARY KEY,part text,customer name,retailer text,price text)")
        self.conn.commit()

    def fetch(self):
        self.cur.execute("SELECT * FROM parts")
        rows = self.cur.fetchall()
        return rows

    def add(self, part, customer, retailer, price):
        self.cur.execute("INSERT INTO parts VALUES (Null,?,?,?,?)",
                         (part, customer, retailer, price))
        self.conn.commit()

    def remove(self, id):
        self.cur.execute("DELETE FROM parts WHERE id=?", (id,))
        self.conn.commit()

    def update(self, id, part, customer, retailer, price):
        self.cur.execute("UPDATE parts SET part=?,customer=?,retailer=?,price=? WHERE id=?",
                         (part, customer, retailer, price, id))

    def __del__(self):
        self.conn.close()


# db = Database('store.db')
# db.add('32', 'dfmr', '345', '3dfn')
# db.remove(1)
# print(db.fetch())
