-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_joining.py
More file actions
41 lines (31 loc) · 1.22 KB
/
test_joining.py
File metadata and controls
41 lines (31 loc) · 1.22 KB
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
39
40
41
import pickle
from databasestructure import *
if __name__ == '__main__':
try:
db_test = CustomDatabase()
# Create tables
db_test.create_table('users', ['id', 'name', 'age'], key_index=0)
db_test.create_table('orders', ['order_id', 'user_id', 'product'], key_index=0)
# Insert data into tables
db_test.insert('users', [None, 'Charlie', 28])
db_test.insert('users', [None, 'Alice', 30])
db_test.insert('orders', [101, 0, 'Laptop'])
db_test.insert('orders', [102, 1, 'Smartphone'])
db_test.insert('orders', [103, 0, 'Phone'])
# Commit transactions
print("starting commits")
db_test.commit('users')
db_test.commit('orders')
# Perform the join
print("starting joinin")
headers, joined_data = db_test.join('users', 'orders', key_index1=0, key_index2=1)
# Display the joined data
#print("Joined Data:\n", joined_data)
print("Joined Data:\n")
print(headers)
for data in joined_data:
print(data)
# Save the database in binary format
db_test.save('./test_joining_db.pkl')
except Exception as err:
print("Error: ", str(err))