From 7d22dc5796fb4795f42cfeaee815090c80f45203 Mon Sep 17 00:00:00 2001 From: StormRobert Date: Sat, 16 Dec 2023 02:13:30 +0300 Subject: [PATCH 1/3] trials --- lib/company.py | 0 lib/debug.py | 7 ++++++- lib/freebies.py | 0 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 lib/company.py create mode 100644 lib/freebies.py diff --git a/lib/company.py b/lib/company.py new file mode 100644 index 000000000..e69de29bb diff --git a/lib/debug.py b/lib/debug.py index 4f922eb69..608b06674 100644 --- a/lib/debug.py +++ b/lib/debug.py @@ -2,7 +2,12 @@ from sqlalchemy import create_engine -from models import Company, Dev +from models import Company, Dev, Freebie + +Company.create_table() +Dev.create_table() +Freebie.create_table() + if __name__ == '__main__': engine = create_engine('sqlite:///freebies.db') diff --git a/lib/freebies.py b/lib/freebies.py new file mode 100644 index 000000000..e69de29bb From bee2785c7ea2ed09c0835058eb4f3d22021c7baf Mon Sep 17 00:00:00 2001 From: StormRobert Date: Sat, 16 Dec 2023 02:20:15 +0300 Subject: [PATCH 2/3] in progress --- lib/company.py | 24 ++++++++++++++++++++++++ lib/developer.py | 7 +++++++ lib/freebies.py | 14 ++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 lib/developer.py diff --git a/lib/company.py b/lib/company.py index e69de29bb..30ae619db 100644 --- a/lib/company.py +++ b/lib/company.py @@ -0,0 +1,24 @@ +import sqlite3 +from freebies import Freebie + +CONN = sqlite3.connect("./lib/freebies.db") +CURSOR = CONN.cursor() + +class Company(): + def __init__(self, name, founding_year, id=None): + self.set_name(name) + self.founding_year = founding_year + self.id = id + + + def get_name(self): + return self._name + + def set_name(self, new_name): + if type(new_name) == str and len(new_name) > 0: + self._name = new_name + else: + print("name is not a string") + raise Exception() + + name = property(get_name, set_name) diff --git a/lib/developer.py b/lib/developer.py new file mode 100644 index 000000000..8c40de21d --- /dev/null +++ b/lib/developer.py @@ -0,0 +1,7 @@ +from company import Company +from freebies import Freebie +from developer import Dev + +Company.create_table() +Dev.create_table() +Freebie.create_table() diff --git a/lib/freebies.py b/lib/freebies.py index e69de29bb..d53b8de8d 100644 --- a/lib/freebies.py +++ b/lib/freebies.py @@ -0,0 +1,14 @@ +import sqlite3 + +CONN = sqlite3.connect("./lib/freebies.db") +CURSOR = CONN.cursor() + +#! Create Freebies Class +class Freebie(): + def __init__(self, item_name, value, comp_id=None, dev_id=None, id=None): + self.id = id + self.item_name = item_name + self.value = value + self.comp_id = comp_id + self.dev_id = dev_id + \ No newline at end of file From 9fadf24acb7a3a83a25bbe9928c5e855c38211e4 Mon Sep 17 00:00:00 2001 From: StormRobert Date: Sat, 16 Dec 2023 02:28:06 +0300 Subject: [PATCH 3/3] learnign --- lib/company.py | 25 +++++++++++++++++++++++++ lib/freebies.py | 31 ++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/lib/company.py b/lib/company.py index 30ae619db..72ca5ceca 100644 --- a/lib/company.py +++ b/lib/company.py @@ -22,3 +22,28 @@ def set_name(self, new_name): raise Exception() name = property(get_name, set_name) +@classmethod +def create_table(cls): + sql = """ + CREATE TABLE IF NOT EXISTS companies ( + id INTEGER PRIMARY KEY, + name TEXT, + founding_year INTEGER + ) + """ + CURSOR.execute(sql) + +@classmethod +def drop_table(cls): + sql = "DROP TABLE IF EXISTS companies" + CURSOR.execute(sql) + + +def save(self): + sql = """ + INSERT INTO companies (name, founding_year) + VALUES (?, ?) + """ + CURSOR.execute(sql, (self.name, self.founding_year)) + CONN.commit() + self.id = CURSOR.lastrowid \ No newline at end of file diff --git a/lib/freebies.py b/lib/freebies.py index d53b8de8d..2d52b7269 100644 --- a/lib/freebies.py +++ b/lib/freebies.py @@ -11,4 +11,33 @@ def __init__(self, item_name, value, comp_id=None, dev_id=None, id=None): self.value = value self.comp_id = comp_id self.dev_id = dev_id - \ No newline at end of file + +@classmethod +def create_table(cls): + sql = """ + CREATE TABLE IF NOT EXISTS freebies ( + id INTEGER PRIMARY KEY, + item_name TEXT, + value INTEGER, + comp_id INTEGER, + dev_id INTEGER + ) + """ + + CURSOR.execute(sql) + + #! Create a drop table to refresh every time code is ran +@classmethod +def drop_table(cls): + sql = "DROP TABLE IF EXISTS freebies" + CURSOR.execute(sql) + + #! Create option to save information to Table once created: +def save(self): + sql = """ + INSERT INTO freebies (item_name, value, comp_id, dev_id) + VALUES (?, ?, ?, ?) + """ + CURSOR.execute(sql, (self.item_name, self.value, self.comp_id, self.dev_id)) + CONN.commit() + self.id = CURSOR.lastrowid \ No newline at end of file