dasaproject/fake_db.py
2023-09-27 15:49:36 +07:00

36 lines
839 B
Python

import sqlite3
from faker import Faker
from datetime import datetime
fake = Faker()
# Establish SQLite database connection
conn = sqlite3.connect("database.db")
cursor = conn.cursor()
# Create table
cursor.execute('''
CREATE TABLE your_table (
id INTEGER PRIMARY KEY,
item_name TEXT,
cust_id INTEGER,
cust_name TEXT,
start_date DATE
);
''')
# Generate and insert sample data
for _ in range(100):
item_name = fake.word()
cust_id = fake.random_int(min=1, max=1000)
cust_name = fake.name()
start_date = fake.date_this_decade()
cursor.execute('''
INSERT INTO your_table (item_name, cust_id, cust_name, start_date)
VALUES (?, ?, ?, ?);
''', (item_name, cust_id, cust_name, start_date))
# Commit changes and close connection
conn.commit()
conn.close()