Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
Madison = Customer(name="Madison", age=20)
Johnathan = Customer(name="Johnathan", age=18)

Cosmo = Drinks(name="Cosmo")
Manhattan = Drinks(name="Manhattan")
Tequila_Sunrise = Drinks(name="Tequila Sunrise")
Rum_Runner = Drinks(name="Rum Runner")
Bees_Knees = Drinks(name="Bees Knees")



Customer.delete_all()
Drinks.delete_all()
Expand Down
9 changes: 5 additions & 4 deletions lib/models/Drinks.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from models.__init__ import CONN, CURSOR
import ipdb


class Drinks():
age_requirement = 21

def __init__(self, id, name):
self.id = id
def __init__(self, name):
# self.id = id
self.name = name

@property
Expand All @@ -27,7 +28,7 @@ def name(self, value):
if not isinstance(value, str):
raise TypeError("Name has to be a string")
self._name = value

def save(self):
sql = """
INSERT INTO drinks (name)
Expand Down Expand Up @@ -119,5 +120,5 @@ def drop_table(cls):
CONN.commit()

def __repr__(self):
return f'<Drinks id={self.id} name={self.name} >'
return f'<drinks id={self.id} name={self.name} >'

45 changes: 30 additions & 15 deletions lib/models/seed.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import sqlite3
import ipdb

# Create a connection to an SQLite database (it will create the file if it doesn't exist)
conn = sqlite3.connect('company.db')

# Create a cursor object to interact with the database
cursor = conn.cursor()

cursor.execute('''
DROP TABLE IF EXISTS customer
''')
# Create table (if not already created)
# Drop the tables if they exist
cursor.execute('DROP TABLE IF EXISTS customer')
cursor.execute('DROP TABLE IF EXISTS drinks')

# Create tables
cursor.execute('''
CREATE TABLE IF NOT EXISTS customer (
id INTEGER PRIMARY KEY,
Expand All @@ -20,32 +19,48 @@
)
''')

cursor.execute('''
CREATE TABLE IF NOT EXISTS drinks (
id INTEGER PRIMARY KEY,
name TEXT
)
''')


# Function to insert data into the customer table
# Function to insert data into the customer and drinks tables
def seed_db():
# Sample user data
customer = [
customers = [
('Jay', 23),
('Victoria', 25),
('Kerissa', 33),
('Madison', 20),
('Johnathan', 18)
]
drinks = [
('Cosmo',),
('Manhattan',),
('Tequila Sunrise',),
('Rum Runner',),
('Bees Knees',)
]



# Insert sample customer into the database
# Insert sample customers into the database
cursor.executemany('''
INSERT INTO customer (name, age)
VALUES (?, ?)
''', customer)

''', customers)

# Insert sample drinks into the database
cursor.executemany('''
INSERT INTO drinks (name)
VALUES (?)
''', drinks)

# Commit the transaction
conn.commit()
# cursor.execute()
print(f"{len(customer)} customer added to the database.")

print(f"{len(customers)} customers added to the database.")
print(f"{len(drinks)} drinks added to the database.")

# Run the seed function
if __name__ == "__main__":
Expand Down