-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_utils.py
More file actions
38 lines (31 loc) · 873 Bytes
/
Copy pathdb_utils.py
File metadata and controls
38 lines (31 loc) · 873 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
27
28
29
30
31
32
33
34
35
36
37
38
import sqlite3
DB_PATH = "operations.db"
def get_order_by_id(order_id: str):
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
cursor.execute("SELECT * FROM orders WHERE order_id = ?", (order_id,))
row = cursor.fetchone()
conn.close()
if not row:
return None
return {
"order_id": row[0],
"customer_name": row[1],
"status": row[2],
"amount": row[3],
"issue": row[4]
}
def get_customer_by_id(customer_id: str):
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
cursor.execute("SELECT * FROM customers WHERE customer_id = ?", (customer_id,))
row = cursor.fetchone()
conn.close()
if not row:
return None
return {
"customer_id": row[0],
"customer_name": row[1],
"industry": row[2],
"region": row[3]
}