sqlshell 0.1.6__py3-none-any.whl → 0.1.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of sqlshell might be problematic. Click here for more details.
- sqlshell/__init__.py +4 -2
- sqlshell/create_test_data.py +50 -0
- sqlshell/data/create_test_data.py +137 -0
- sqlshell/db/__init__.py +5 -0
- sqlshell/db/database_manager.py +691 -0
- sqlshell/editor.py +856 -0
- sqlshell/main.py +1904 -961
- sqlshell/query_tab.py +172 -0
- sqlshell/resources/__init__.py +1 -0
- sqlshell/resources/create_icon.py +131 -0
- sqlshell/resources/create_splash.py +96 -0
- sqlshell/resources/icon.png +0 -0
- sqlshell/resources/logo_large.png +0 -0
- sqlshell/resources/logo_medium.png +0 -0
- sqlshell/resources/logo_small.png +0 -0
- sqlshell/resources/splash_screen.gif +0 -0
- sqlshell/setup.py +1 -1
- sqlshell/splash_screen.py +405 -0
- sqlshell/sqlshell/create_test_data.py +4 -23
- sqlshell/sqlshell_demo.png +0 -0
- sqlshell/syntax_highlighter.py +123 -0
- sqlshell/ui/__init__.py +6 -0
- sqlshell/ui/bar_chart_delegate.py +49 -0
- sqlshell/ui/filter_header.py +403 -0
- sqlshell-0.1.9.dist-info/METADATA +122 -0
- sqlshell-0.1.9.dist-info/RECORD +31 -0
- {sqlshell-0.1.6.dist-info → sqlshell-0.1.9.dist-info}/WHEEL +1 -1
- sqlshell-0.1.6.dist-info/METADATA +0 -92
- sqlshell-0.1.6.dist-info/RECORD +0 -11
- {sqlshell-0.1.6.dist-info → sqlshell-0.1.9.dist-info}/entry_points.txt +0 -0
- {sqlshell-0.1.6.dist-info → sqlshell-0.1.9.dist-info}/top_level.txt +0 -0
sqlshell/__init__.py
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import numpy as np
|
|
3
|
+
from datetime import datetime, timedelta
|
|
4
|
+
|
|
5
|
+
def create_sales_data(num_records=1000):
|
|
6
|
+
"""Create sample sales data"""
|
|
7
|
+
# Generate random dates within the last year
|
|
8
|
+
end_date = datetime.now()
|
|
9
|
+
start_date = end_date - timedelta(days=365)
|
|
10
|
+
dates = pd.date_range(start=start_date, end=end_date, periods=num_records)
|
|
11
|
+
|
|
12
|
+
# Generate random data
|
|
13
|
+
data = {
|
|
14
|
+
'orderid': range(1, num_records + 1),
|
|
15
|
+
'orderdate': dates,
|
|
16
|
+
'customerid': np.random.randint(1, 101, num_records),
|
|
17
|
+
'productid': np.random.randint(1, 51, num_records),
|
|
18
|
+
'quantity': np.random.randint(1, 11, num_records),
|
|
19
|
+
'unitprice': np.random.uniform(10.0, 1000.0, num_records).round(2)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return pd.DataFrame(data)
|
|
23
|
+
|
|
24
|
+
def create_customer_data(num_customers=100):
|
|
25
|
+
"""Create sample customer data"""
|
|
26
|
+
# Generate random customer data
|
|
27
|
+
data = {
|
|
28
|
+
'customerid': range(1, num_customers + 1),
|
|
29
|
+
'customername': [f"Customer {i}" for i in range(1, num_customers + 1)],
|
|
30
|
+
'email': [f"customer{i}@example.com" for i in range(1, num_customers + 1)],
|
|
31
|
+
'country': np.random.choice(['USA', 'UK', 'Canada', 'Australia', 'Germany'], num_customers),
|
|
32
|
+
'joindate': pd.date_range(start='2020-01-01', periods=num_customers).tolist()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return pd.DataFrame(data)
|
|
36
|
+
|
|
37
|
+
def create_product_data(num_products=50):
|
|
38
|
+
"""Create sample product data"""
|
|
39
|
+
categories = ['Electronics', 'Books', 'Clothing', 'Home & Garden', 'Sports']
|
|
40
|
+
|
|
41
|
+
# Generate random product data
|
|
42
|
+
data = {
|
|
43
|
+
'productid': range(1, num_products + 1),
|
|
44
|
+
'productname': [f"Product {i}" for i in range(1, num_products + 1)],
|
|
45
|
+
'category': np.random.choice(categories, num_products),
|
|
46
|
+
'baseprice': np.random.uniform(5.0, 500.0, num_products).round(2),
|
|
47
|
+
'instock': np.random.choice([True, False], num_products, p=[0.8, 0.2])
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return pd.DataFrame(data)
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import numpy as np
|
|
3
|
+
from datetime import datetime, timedelta
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
# Set random seed for reproducibility
|
|
7
|
+
np.random.seed(42)
|
|
8
|
+
|
|
9
|
+
# Define output directory
|
|
10
|
+
OUTPUT_DIR = 'test_data'
|
|
11
|
+
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
|
12
|
+
|
|
13
|
+
def create_sales_data(num_records=1000):
|
|
14
|
+
# Generate dates for the last 365 days
|
|
15
|
+
end_date = datetime.now()
|
|
16
|
+
start_date = end_date - timedelta(days=365)
|
|
17
|
+
dates = [start_date + timedelta(days=x) for x in range(366)]
|
|
18
|
+
random_dates = np.random.choice(dates, num_records)
|
|
19
|
+
|
|
20
|
+
# Create product data
|
|
21
|
+
products = ['Laptop', 'Smartphone', 'Tablet', 'Monitor', 'Keyboard', 'Mouse', 'Headphones', 'Printer']
|
|
22
|
+
product_prices = {
|
|
23
|
+
'Laptop': (800, 2000),
|
|
24
|
+
'Smartphone': (400, 1200),
|
|
25
|
+
'Tablet': (200, 800),
|
|
26
|
+
'Monitor': (150, 500),
|
|
27
|
+
'Keyboard': (20, 150),
|
|
28
|
+
'Mouse': (10, 80),
|
|
29
|
+
'Headphones': (30, 300),
|
|
30
|
+
'Printer': (100, 400)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# Generate random data
|
|
34
|
+
data = {
|
|
35
|
+
'OrderID': range(1, num_records + 1),
|
|
36
|
+
'Date': random_dates,
|
|
37
|
+
'ProductID': np.random.randint(1, len(products) + 1, num_records), # Changed to ProductID for joining
|
|
38
|
+
'Quantity': np.random.randint(1, 11, num_records),
|
|
39
|
+
'CustomerID': np.random.randint(1, 201, num_records),
|
|
40
|
+
'Region': np.random.choice(['North', 'South', 'East', 'West'], num_records)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
# Calculate prices based on product
|
|
44
|
+
product_list = [products[pid-1] for pid in data['ProductID']]
|
|
45
|
+
data['Price'] = [np.random.uniform(product_prices[p][0], product_prices[p][1])
|
|
46
|
+
for p in product_list]
|
|
47
|
+
data['TotalAmount'] = [price * qty for price, qty in zip(data['Price'], data['Quantity'])]
|
|
48
|
+
|
|
49
|
+
# Create DataFrame
|
|
50
|
+
df = pd.DataFrame(data)
|
|
51
|
+
|
|
52
|
+
# Round numerical columns
|
|
53
|
+
df['Price'] = df['Price'].round(2)
|
|
54
|
+
df['TotalAmount'] = df['TotalAmount'].round(2)
|
|
55
|
+
|
|
56
|
+
# Sort by Date
|
|
57
|
+
return df.sort_values('Date')
|
|
58
|
+
|
|
59
|
+
def create_customer_data(num_customers=200):
|
|
60
|
+
# Generate customer data
|
|
61
|
+
data = {
|
|
62
|
+
'CustomerID': range(1, num_customers + 1),
|
|
63
|
+
'FirstName': [f'Customer{i}' for i in range(1, num_customers + 1)],
|
|
64
|
+
'LastName': [f'Lastname{i}' for i in range(1, num_customers + 1)],
|
|
65
|
+
'Email': [f'customer{i}@example.com' for i in range(1, num_customers + 1)],
|
|
66
|
+
'JoinDate': [datetime.now() - timedelta(days=np.random.randint(1, 1000))
|
|
67
|
+
for _ in range(num_customers)],
|
|
68
|
+
'CustomerType': np.random.choice(['Regular', 'Premium', 'VIP'], num_customers),
|
|
69
|
+
'CreditScore': np.random.randint(300, 851, num_customers)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return pd.DataFrame(data)
|
|
73
|
+
|
|
74
|
+
def create_product_data():
|
|
75
|
+
# Create detailed product information
|
|
76
|
+
products = {
|
|
77
|
+
'ProductID': range(1, 9),
|
|
78
|
+
'ProductName': ['Laptop', 'Smartphone', 'Tablet', 'Monitor', 'Keyboard', 'Mouse', 'Headphones', 'Printer'],
|
|
79
|
+
'Category': ['Computers', 'Mobile', 'Mobile', 'Accessories', 'Accessories', 'Accessories', 'Audio', 'Peripherals'],
|
|
80
|
+
'Brand': ['TechPro', 'MobileX', 'TabletCo', 'ViewMax', 'TypeMaster', 'ClickPro', 'SoundMax', 'PrintPro'],
|
|
81
|
+
'StockQuantity': np.random.randint(50, 500, 8),
|
|
82
|
+
'MinPrice': [800, 400, 200, 150, 20, 10, 30, 100],
|
|
83
|
+
'MaxPrice': [2000, 1200, 800, 500, 150, 80, 300, 400],
|
|
84
|
+
'Weight_kg': [2.5, 0.2, 0.5, 3.0, 0.8, 0.1, 0.3, 5.0],
|
|
85
|
+
'WarrantyMonths': [24, 12, 12, 36, 12, 12, 24, 12]
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return pd.DataFrame(products)
|
|
89
|
+
|
|
90
|
+
if __name__ == '__main__':
|
|
91
|
+
# Create and save sales data
|
|
92
|
+
sales_df = create_sales_data()
|
|
93
|
+
sales_output = os.path.join(OUTPUT_DIR, 'sample_sales_data.xlsx')
|
|
94
|
+
sales_df.to_excel(sales_output, index=False)
|
|
95
|
+
print(f"Created sales data in '{sales_output}'")
|
|
96
|
+
print(f"Number of sales records: {len(sales_df)}")
|
|
97
|
+
|
|
98
|
+
# Create and save customer data as parquet
|
|
99
|
+
customer_df = create_customer_data()
|
|
100
|
+
customer_output = os.path.join(OUTPUT_DIR, 'customer_data.parquet')
|
|
101
|
+
customer_df.to_parquet(customer_output, index=False)
|
|
102
|
+
print(f"\nCreated customer data in '{customer_output}'")
|
|
103
|
+
print(f"Number of customers: {len(customer_df)}")
|
|
104
|
+
|
|
105
|
+
# Create and save product data
|
|
106
|
+
product_df = create_product_data()
|
|
107
|
+
product_output = os.path.join(OUTPUT_DIR, 'product_catalog.xlsx')
|
|
108
|
+
product_df.to_excel(product_output, index=False)
|
|
109
|
+
print(f"\nCreated product catalog in '{product_output}'")
|
|
110
|
+
print(f"Number of products: {len(product_df)}")
|
|
111
|
+
|
|
112
|
+
# Print sample queries
|
|
113
|
+
print("\nSample SQL queries for joining the data:")
|
|
114
|
+
print("""
|
|
115
|
+
-- Join sales with customer data
|
|
116
|
+
SELECT s.*, c.FirstName, c.LastName, c.CustomerType
|
|
117
|
+
FROM test_data.sample_sales_data s
|
|
118
|
+
JOIN test_data.customer_data c ON s.CustomerID = c.CustomerID;
|
|
119
|
+
|
|
120
|
+
-- Join sales with product data
|
|
121
|
+
SELECT s.*, p.ProductName, p.Category, p.Brand
|
|
122
|
+
FROM test_data.sample_sales_data s
|
|
123
|
+
JOIN test_data.product_catalog p ON s.ProductID = p.ProductID;
|
|
124
|
+
|
|
125
|
+
-- Three-way join with aggregation
|
|
126
|
+
SELECT
|
|
127
|
+
p.Category,
|
|
128
|
+
c.CustomerType,
|
|
129
|
+
COUNT(*) as NumOrders,
|
|
130
|
+
SUM(s.TotalAmount) as TotalRevenue,
|
|
131
|
+
AVG(s.Quantity) as AvgQuantity
|
|
132
|
+
FROM test_data.sample_sales_data s
|
|
133
|
+
JOIN test_data.customer_data c ON s.CustomerID = c.CustomerID
|
|
134
|
+
JOIN test_data.product_catalog p ON s.ProductID = p.ProductID
|
|
135
|
+
GROUP BY p.Category, c.CustomerType
|
|
136
|
+
ORDER BY p.Category, c.CustomerType;
|
|
137
|
+
""")
|