Gaurav-2273 commited on
Commit
9ca206d
·
verified ·
1 Parent(s): 67530c6

Create generate_db.py

Browse files
Files changed (1) hide show
  1. generate_db.py +30 -0
generate_db.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sqlite3
2
+
3
+ def init_db():
4
+ # Connect to a file-based DB. If it doesn't exist, it creates it.
5
+ conn = sqlite3.connect('sales.db')
6
+ c = conn.cursor()
7
+
8
+ # Create Tables (Schema)
9
+ c.execute('''CREATE TABLE IF NOT EXISTS customers
10
+ (id INTEGER PRIMARY KEY, name TEXT, region TEXT)''')
11
+ c.execute('''CREATE TABLE IF NOT EXISTS products
12
+ (id INTEGER PRIMARY KEY, name TEXT, category TEXT, price REAL)''')
13
+ c.execute('''CREATE TABLE IF NOT EXISTS orders
14
+ (id INTEGER PRIMARY KEY, customer_id INTEGER, product_id INTEGER,
15
+ quantity INTEGER, order_date DATE)''')
16
+
17
+ # Insert Dummy Data (So you have something to query)
18
+ c.execute("INSERT OR IGNORE INTO customers VALUES (1, 'Acme Corp', 'North')")
19
+ c.execute("INSERT OR IGNORE INTO customers VALUES (2, 'Globex', 'West')")
20
+ c.execute("INSERT OR IGNORE INTO products VALUES (1, 'AI Widget', 'Software', 1000.0)")
21
+ c.execute("INSERT OR IGNORE INTO products VALUES (2, 'Cloud Server', 'Hardware', 5000.0)")
22
+ c.execute("INSERT OR IGNORE INTO orders VALUES (101, 1, 1, 5, '2023-10-01')")
23
+ c.execute("INSERT OR IGNORE INTO orders VALUES (102, 2, 2, 1, '2023-10-05')")
24
+
25
+ conn.commit()
26
+ conn.close()
27
+ print("Database initialized as sales.db")
28
+
29
+ if __name__ == "__main__":
30
+ init_db()