This repository was archived by the owner on Jan 22, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHoneyCodeORM.template
More file actions
171 lines (150 loc) · 5.75 KB
/
HoneyCodeORM.template
File metadata and controls
171 lines (150 loc) · 5.75 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import boto3
class {{classNameEditor}}:
def __init__(self) -> object:
self.tableid = "{{tableID}}"
self.workbookid = "{{workbookID}}"
self.tablename = "{{tableName}}"
self.honeycode_client = boto3.client('honeycode')
#list all rows in the table
def listAllRows(self):
rowRet = []
nextToken2 = ""
response = self.honeycode_client.list_table_rows(
workbookId=self.workbookid,
tableId=self.tableid, maxResults=100)
if "nextToken" in response:
nextToken2 = response["nextToken"]
for row in response["rows"]:
rowRet.append(self.__convertRowOfHoneycodeDataToObject(row))
while nextToken2:
response = self.honeycode_client.list_table_rows(
workbookId=self.workbookid,
tableId=self.tableid, maxResults=100, nextToken=nextToken2)
nextToken2 = ""
if "nextToken" in response:
nextToken2 = response["nextToken"]
for row in response["rows"]:
rowRet.append(self.__convertRowOfHoneycodeDataToObject(row))
return rowRet
#find rows with criteria
def find(self, columnName, operator, value):
searchVal = "=Filter("+self.tablename+",\""+self.tablename+"["+columnName+"]"+operator+"%\", \""+value+"\")"
response = self.honeycode_client.query_table_rows(
workbookId=self.workbookid,
tableId=self.tableid,
filterFormula={"formula": searchVal})
retValue = []
for row in response["rows"]:
retValue.append(self.__convertRowOfHoneycodeDataToObject(row))
return retValue
#Update one row
def updateRow(self, o_row):
response = self.honeycode_client.batch_update_table_rows(
workbookId=self.workbookid,
tableId=self.tableid,
rowsToUpdate=
self.__convertRowsOfObjectsToHoneyCodeUpdateRows([o_row])
)
#Update multipule rows
def updateRows(self, o_rows):
rows = self.__convertRowsOfObjectsToHoneyCodeUpdateRows(o_rows)
for i in range(0, len(rows), 100):
response = self.honeycode_client.batch_update_table_rows(
workbookId=self.workbookid,
tableId=self.tableid,
rowsToUpdate=rows[i:i + 100]
)
#takes a row or an id
def deleteRow(self, o_row):
response = self.honeycode_client.batch_delete_table_rows(
workbookId=self.workbookid,
tableId=self.tableid,
rowIds=[o_row.rowId])
#deletes all rows in this table
def deleteAllRows(self):
rows = self.listAllRows()
for i in range(0, len(rows), 100):
response = self.honeycode_client.batch_delete_table_rows(
workbookId=self.workbookid,
tableId=self.tableid,
rowIds=rows[i:i + 100]
)
def batchSaveRows(self, o_rows):
maxBatchSize = 100
currentPage = 0
rows = self.__convertRowsOfObjectsToHoneyCodeRows(o_rows)
while currentPage*maxBatchSize < len(rows):
begin = currentPage * maxBatchSize
end = (currentPage * maxBatchSize) + maxBatchSize
if end > len(rows):
end = len(rows)
currentPage+=1
response = self.honeycode_client.batch_create_table_rows(
workbookId=self.workbookid,
tableId=self.tableid,
rowsToCreate=rows[begin:end])
for batchid in response["createdRows"]:
for row in o_rows:
if row.batchid == batchid:
row.rowId = response["createdRows"][batchid]
#convert honeycode row to object
def __convertRowOfHoneycodeDataToObject(self, row):
ar = {{classnameRow}}({{findDataFromColumn}}, row["rowId"])
return ar
#convience function to convert objects to rows
def __convertRowsOfObjectsToHoneyCodeRows(self, rows):
insertableRows = []
batchID = 0
for row in rows:
batchID += 1
convertedRow = row.createInsertRowData("insert" + str(batchID))
row.batchid = "insert" + str(batchID)
insertableRows.append(convertedRow)
return insertableRows
#convience function to convert objects to updates
def __convertRowsOfObjectsToHoneyCodeUpdateRows(self, rows):
insertableRows = []
batchID = 0
for row in rows:
batchID += 1
convertedRow = row.createUpdateRowData()
insertableRows.append(convertedRow)
return insertableRows
#Class For data
class {{classnameRow}}:
def __init__(self{{variableNamesParams}}, rowId=None) -> object:
self.rowId = rowId
self.batchid = ""
{{variableNamesAlloc}}
def __repr__(self):
return "{{classnameRow}}<" + str(self.rowId) + ">"
def __str__(self):
return "{{classnameRow}}<" + {{printstatment}} + ">"
def save(self):
iface = {{classNameEditor}}()
if self.rowId:
iface.updateRow(self)
else:
iface.batchSaveRows([self])
def delete(self):
iface = {{classNameEditor}}()
iface.deleteRow(self)
self.rowId = ""
def createInsertRowData(self, batch_item_id):
operation = "cellsToCreate"
dictToAdd = {
"batchItemId": batch_item_id,
operation: {
}
}
{{honeyCodeRowDefs}}
return dictToAdd
def createUpdateRowData(self):
operation = "cellsToUpdate"
dictToAdd = {
"rowId": self.rowId,
operation: {
}
}
{{honeyCodeRowDefs}}
return dictToAdd