150600
This commit is contained in:
53
database.py
Normal file
53
database.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import sqlite3
|
||||
|
||||
def create_tables():
|
||||
conn = sqlite3.connect('bot_data.db')
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS orders (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT,
|
||||
phone TEXT,
|
||||
address TEXT,
|
||||
cleaning_time TEXT,
|
||||
cleaning_type TEXT,
|
||||
payment_method TEXT
|
||||
)
|
||||
''')
|
||||
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
user_id INTEGER PRIMARY KEY,
|
||||
name TEXT,
|
||||
phone TEXT,
|
||||
address TEXT
|
||||
)
|
||||
''')
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def add_order(name, phone, address, cleaning_time, cleaning_type, payment_method):
|
||||
conn = sqlite3.connect('bot_data.db')
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
INSERT INTO orders (name, phone, address, cleaning_time, cleaning_type, payment_method)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
''', (name, phone, address, cleaning_time, cleaning_type, payment_method))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def get_order_history(user_id):
|
||||
conn = sqlite3.connect('bot_data.db')
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
SELECT * FROM orders WHERE user_id = ?
|
||||
''', (user_id,))
|
||||
|
||||
orders = cursor.fetchall()
|
||||
conn.close()
|
||||
return orders
|
||||
Reference in New Issue
Block a user