-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
26 lines (21 loc) · 820 Bytes
/
database.py
File metadata and controls
26 lines (21 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import sqlite3
# Connect to the database
conn = sqlite3.connect('f1_database.db')
cursor = conn.cursor()
# Read the schema.sql file
with open('schema.sql', 'r') as file:
schema = file.read()
# Execute the schema
cursor.executescript(schema)
# Sample data insertion (optional)
# Insert some data to test the schema
cursor.executescript('''
INSERT INTO Teams (name, headquarters) VALUES ('Team A', 'Headquarters A');
INSERT INTO Drivers (name, nationality, team_id) VALUES ('Driver 1', 'Country 1', 1);
INSERT INTO Races (location, date) VALUES ('Location 1', '2024-07-01');
INSERT INTO Results (race_id, driver_id, position, points) VALUES (1, 1, 1, 25);
INSERT INTO Predictions (race_id, driver_id, predicted_position) VALUES (1, 1, 1);
''')
# Commit changes and close the connection
conn.commit()
conn.close()