Skip to content

Commit df7bb3c

Browse files
committed
feat(utils/coda): Replace updateOrInsertRow with upsertRow
1 parent d3c18fa commit df7bb3c

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

packages/mcl/src/src/mcl/commands/host_info.d

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Info getInfo(Params params)
113113
CodaCell("JSON", info.toJSON(true).toPrettyString(JSONOptions.doNotEscapeSlashes))
114114
]);
115115

116-
coda.updateOrInsertRow(docId, hostTableId, hostValues);
116+
coda.upsertRow(docId, hostTableId, hostValues);
117117

118118
auto cpuValues = RowValues([
119119
CodaCell("Host Name", info.softwareInfo.hostname),
@@ -122,7 +122,7 @@ Info getInfo(Params params)
122122
CodaCell("Architecture", info.hardwareInfo.processorInfo.architectureInfo.architecture),
123123
CodaCell("Flags", info.hardwareInfo.processorInfo.architectureInfo.flags),
124124
]);
125-
coda.updateOrInsertRow(docId, cpuTableId, cpuValues);
125+
coda.upsertRow(docId, cpuTableId, cpuValues);
126126

127127
auto memoryValues = RowValues([
128128
CodaCell("Host Name", info.softwareInfo.hostname),
@@ -134,7 +134,7 @@ Info getInfo(Params params)
134134
CodaCell("Total", info.hardwareInfo.memoryInfo.total),
135135
CodaCell("Speed", info.hardwareInfo.memoryInfo.speed),
136136
]);
137-
coda.updateOrInsertRow(docId, memoryTableId, memoryValues);
137+
coda.upsertRow(docId, memoryTableId, memoryValues);
138138

139139
auto motherboardValues = RowValues([
140140
CodaCell("Host Name", info.softwareInfo.hostname),
@@ -147,15 +147,15 @@ Info getInfo(Params params)
147147
CodaCell("BIOS Release", info.hardwareInfo.motherboardInfo.biosInfo.release),
148148
CodaCell("BIOS Date", info.hardwareInfo.motherboardInfo.biosInfo.date)
149149
]);
150-
coda.updateOrInsertRow(docId, motherboardTableId, motherboardValues);
150+
coda.upsertRow(docId, motherboardTableId, motherboardValues);
151151

152152
auto gpuValues = RowValues([
153153
CodaCell("Host Name", info.softwareInfo.hostname),
154154
CodaCell("Vendor", info.hardwareInfo.graphicsProcessorInfo.vendor),
155155
CodaCell("Model", info.hardwareInfo.graphicsProcessorInfo.model),
156156
CodaCell("VRam", info.hardwareInfo.graphicsProcessorInfo.vram)
157157
]);
158-
coda.updateOrInsertRow(docId, gpuTableId, gpuValues);
158+
coda.upsertRow(docId, gpuTableId, gpuValues);
159159

160160
auto osValues = RowValues([
161161
CodaCell("Host Name", info.softwareInfo.hostname),
@@ -164,15 +164,15 @@ Info getInfo(Params params)
164164
CodaCell("Kernel", info.softwareInfo.operatingSystemInfo.kernel),
165165
CodaCell("Kernel Version", info.softwareInfo.operatingSystemInfo.kernelVersion)
166166
]);
167-
coda.updateOrInsertRow(docId, osTableId, osValues);
167+
coda.upsertRow(docId, osTableId, osValues);
168168

169169
auto storageValues = RowValues([
170170
CodaCell("Host Name", info.softwareInfo.hostname),
171171
CodaCell("Count", info.hardwareInfo.storageInfo.devices.length.to!string),
172172
CodaCell("Total", info.hardwareInfo.storageInfo.total),
173173
CodaCell("JSON", info.hardwareInfo.storageInfo.toJSON(true).toPrettyString(JSONOptions.doNotEscapeSlashes))
174174
]);
175-
coda.updateOrInsertRow(docId, storageTableId, storageValues);
175+
coda.upsertRow(docId, storageTableId, storageValues);
176176
}
177177
else
178178
writeln("No Coda API token specified -> not uploading");

packages/mcl/src/src/mcl/utils/coda.d

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ struct CodaApiClient
496496
string id;
497497
}
498498

499-
string updateRow(string documentId, string tableId, string rowId, RowValues row)
499+
string updateRow(string documentId, string tableId, string rowId, RowValues row, string[] keyColumns = [])
500500
{
501501
string url = "/docs/%s/tables/%s/rows/%s".format(documentId, tableId, rowId);
502502
JSONValue req = JSONValue(
@@ -527,15 +527,8 @@ struct CodaApiClient
527527
coda.deleteRow("dEJJPwdxcw", tables[0].id, resp[0]);
528528
}
529529

530-
void updateOrInsertRow(string docId, string tableId, RowValues values) {
531-
auto table = listRows(docId, tableId);
532-
auto rows = find!(row => row.name == values.cells[0].value)(table);
533-
if (rows.length > 0) {
534-
updateRow(docId, tableId, rows[0].id, values);
535-
}
536-
else {
537-
insertRows(docId, tableId, [values]);
538-
}
530+
void upsertRow(string docId, string tableId, RowValues values, string[] keyColumns = ["name"]) {
531+
insertRows(docId, tableId, [values], keyColumns);
539532
}
540533
struct PushButtonResponse {
541534
string requestId;

0 commit comments

Comments
 (0)