Commit
·
57c4258
1
Parent(s):
90349c4
Initialized database with sample data
Browse files- AI Basics Assignment AJACKUS.docx +0 -0
- app/db.py +52 -0
- data/database.sqlite +0 -0
AI Basics Assignment AJACKUS.docx
ADDED
|
Binary file (446 kB). View file
|
|
|
app/db.py
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sqlite3
|
| 2 |
+
|
| 3 |
+
DB_PATH = "data/database.sqlite"
|
| 4 |
+
|
| 5 |
+
def get_connection():
|
| 6 |
+
return sqlite3.connect(DB_PATH)
|
| 7 |
+
|
| 8 |
+
def create_tables():
|
| 9 |
+
conn = get_connection()
|
| 10 |
+
cursor = conn.cursor()
|
| 11 |
+
|
| 12 |
+
cursor.execute('''CREATE TABLE IF NOT EXISTS Employees(
|
| 13 |
+
ID INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 14 |
+
Name TEXT NOT NULL,
|
| 15 |
+
Department TEXT NOT NULL,
|
| 16 |
+
Salary INTEGER NOT NULL,
|
| 17 |
+
Hire_Date TEXT NOT NULL
|
| 18 |
+
)
|
| 19 |
+
''')
|
| 20 |
+
|
| 21 |
+
cursor.execute('''CREATE TABLE IF NOT EXISTS Departments(
|
| 22 |
+
ID INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 23 |
+
Name TEXT NOT NULL,
|
| 24 |
+
Manager TEXT NOT NULL
|
| 25 |
+
)
|
| 26 |
+
''')
|
| 27 |
+
|
| 28 |
+
employees = [
|
| 29 |
+
(1, 'Alice', 'Sales', 50000, '2021-01-15'),
|
| 30 |
+
(2, 'Bob', 'Engineering', 70000, '2020-06-10'),
|
| 31 |
+
(3, 'Charlie', 'Marketing', 60000, '2022-03-20')
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
+
departments = [
|
| 35 |
+
(1, 'Sales', 'Alice'),
|
| 36 |
+
(2, 'Engineering', 'Bob'),
|
| 37 |
+
(3, 'Marketing', 'Charlie')
|
| 38 |
+
]
|
| 39 |
+
|
| 40 |
+
cursor.executemany('INSERT INTO Employees VALUES (?,?,?,?,?)', employees)
|
| 41 |
+
cursor.executemany('INSERT INTO Departments VALUES (?,?,?)', departments)
|
| 42 |
+
|
| 43 |
+
conn.commit()
|
| 44 |
+
conn.close()
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
if __name__ == "__main__":
|
| 49 |
+
create_tables()
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
data/database.sqlite
ADDED
|
Binary file (16.4 kB). View file
|
|
|