(
tableName: string,
rowIdColumnName: string,
content:
| {
[contentId: Id]:
| {[contentSubId: Id]: CellOrUndefined | ValueOrUndefined}
| undefined;
}
| undefined,
deleteEmptyColumns: boolean,
deleteEmptyTable: boolean,
partial = false,
condition: DpcTabularCondition = TRUE,
contentSubIds?: Ids,
)
| 145 | }; |
| 146 | |
| 147 | const saveTable = async ( |
| 148 | tableName: string, |
| 149 | rowIdColumnName: string, |
| 150 | content: |
| 151 | | { |
| 152 | [contentId: Id]: |
| 153 | | {[contentSubId: Id]: CellOrUndefined | ValueOrUndefined} |
| 154 | | undefined; |
| 155 | } |
| 156 | | undefined, |
| 157 | deleteEmptyColumns: boolean, |
| 158 | deleteEmptyTable: boolean, |
| 159 | partial = false, |
| 160 | condition: DpcTabularCondition = TRUE, |
| 161 | contentSubIds?: Ids, |
| 162 | ): Promise<void> => { |
| 163 | const contentSubIdSet = isUndefined(contentSubIds) |
| 164 | ? undefined |
| 165 | : setNew(contentSubIds); |
| 166 | const includeContentSubId = (contentSubId: Id): boolean => |
| 167 | isUndefined(contentSubIdSet) || collHas(contentSubIdSet, contentSubId); |
| 168 | const settingColumnNameSet = setNew<string>(); |
| 169 | objMap(content ?? {}, (contentRow) => |
| 170 | arrayMap( |
| 171 | arrayFilter(objIds(contentRow ?? {}), includeContentSubId), |
| 172 | (cellOrValueId) => setAdd(settingColumnNameSet, cellOrValueId), |
| 173 | ), |
| 174 | ); |
| 175 | const settingColumnNames = collValues(settingColumnNameSet); |
| 176 | |
| 177 | // Delete the table |
| 178 | if ( |
| 179 | isUndefined(contentSubIdSet) && |
| 180 | !partial && |
| 181 | deleteEmptyTable && |
| 182 | condition == TRUE && |
| 183 | arrayIsEmpty(settingColumnNames) && |
| 184 | collHas(schemaMap, tableName) |
| 185 | ) { |
| 186 | await databaseExecuteCommand('DROP ' + TABLE + escapeId(tableName)); |
| 187 | mapSet(schemaMap, tableName); |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | const currentColumnNames = mapGet(schemaMap, tableName); |
| 192 | const unaccountedColumnNames = setNew( |
| 193 | arrayFilter( |
| 194 | collValues(currentColumnNames), |
| 195 | (columnName) => |
| 196 | columnName == rowIdColumnName || includeContentSubId(columnName), |
| 197 | ), |
| 198 | ); |
| 199 | if (!arrayIsEmpty(settingColumnNames)) { |
| 200 | if (!collHas(schemaMap, tableName)) { |
| 201 | // Create the table |
| 202 | await databaseExecuteCommand( |
| 203 | CREATE_TABLE + |
| 204 | escapeId(tableName) + |
no test coverage detected
searching dependent graphs…