-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDemo123.py
93 lines (78 loc) · 2.77 KB
/
Demo123.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# DEMO: How to generate a database WITHOUT
# using an SQL / external file
#
# Author: Soft9000.com
# 2018/05/31: Demonstration Created
import os
import sys
sys.path.insert(1, os.path.join(sys.path[0], '..'))
from collections import OrderedDict
# ######
# STEP 1: Define your tables
# ######
employee = OrderedDict()
employee["ObjectName"] = "Employee"
employee["Description"] = "Someone who works for someone else"
employee["Fields"] = [('Name', 'Text'),
('Email1', 'Text'),
('Email2', 'Text'),
('Email3', 'Text'),
('Phone1', 'Text'),
('Phone2', 'Text'),
('Phone3', 'Text'),
('Notes', 'Text')
]
principal = OrderedDict(employee)
principal['ObjectName'] = 'Principal'
principal['Description'] = 'Someone who can make a financial decision'
event = OrderedDict()
event["ObjectName"] = "Event"
event["Description"] = "Officially scheduled activity"
event["Fields"] = [('Name', 'Text'),
('Start', 'Text'),
('Stop', 'Text')
]
todo = OrderedDict()
todo["ObjectName"] = "ToDo"
todo["Description"] = "Activity in-progress"
todo["Fields"] = [('Name', 'Text'),
('Description', 'Text')
]
entry = OrderedDict()
entry["ObjectName"] = "Entry"
entry["Description"] = "Official status / log entry"
entry["Fields"] = [('DateTime','Text'),
('ObjectName', 'Text'),
('ObjectId', 'Integer'),
('Description', 'Text')
]
tables = [employee, principal, event, todo, entry]
# ######
# STEP 2: Define your artifact (code and database) names
# ######
output_file = "./~CrudMeister"
try:
import os
os.remove(output_file + '.py')
# os.remove(output_file + '.sqlt3')
except:
pass
# ######
# STEP 3: Enjoy!
# ######
from SqltDAO.CodeGen01.OrderClass import OrderClass
from SqltDAO.CodeGen01.SqlSyntax import SqliteCrud
for table in tables:
zname = table["ObjectName"]
print("Table:", zname)
order = OrderClass(
db_name=output_file + ".sqlt3",
class_name=zname,
table_name=zname,
file_name="./" + zname + ".py")
zfields = table["Fields"]
sql = SqliteCrud(order, zfields)
data_file = str(zname + '.csv')
result = sql.code_class_template(data_file)
with open(output_file + ".py", 'a') as fh:
print(result, file=fh)