MCPcopy Index your code
hub / github.com/tinyplex/tinybase / loadTable

Function loadTable

src/persisters/common/database/commands.ts:98–145  ·  view source on GitHub ↗
(
    tableName: string,
    rowIdColumnName: string,
    condition?: DpcTabularCondition,
    contentSubIds?: Ids,
  )

Source from the content-addressed store, hash-verified

96 };
97
98 const loadTable = async (
99 tableName: string,
100 rowIdColumnName: string,
101 condition?: DpcTabularCondition,
102 contentSubIds?: Ids,
103 ): Promise<Table> => {
104 const contentSubIdSet = isUndefined(contentSubIds)
105 ? undefined
106 : setNew(contentSubIds);
107 const includeContentSubId = (contentSubId: Id): boolean =>
108 isUndefined(contentSubIdSet) || collHas(contentSubIdSet, contentSubId);
109 return canSelect(tableName, rowIdColumnName)
110 ? objNew(
111 arrayFilter(
112 arrayMap(
113 await databaseExecuteCommand(
114 SELECT_STAR_FROM +
115 escapeId(tableName) +
116 getWhereCondition(tableName, condition),
117 ),
118 (row): [Id | undefined, Row] => {
119 const rowId = row[rowIdColumnName];
120 const rowContent = decode
121 ? objMap(objDel(row, rowIdColumnName), decode)
122 : objDel(row, rowIdColumnName);
123 return [
124 rowId,
125 isUndefined(contentSubIdSet)
126 ? rowContent
127 : objNew(
128 arrayFilter(
129 objToArray(
130 rowContent,
131 (cellOrValue, contentSubId) =>
132 [contentSubId, cellOrValue] as [Id, any],
133 ),
134 ([contentSubId]) => includeContentSubId(contentSubId),
135 ),
136 ),
137 ];
138 },
139 ),
140 (entry): entry is [Id, Row] =>
141 !isUndefined(entry[0]) && !objIsEmpty(entry[1]),
142 ),
143 )
144 : {};
145 };
146
147 const saveTable = async (
148 tableName: string,

Callers 3

loadTablesFunction · 0.85
loadValuesFunction · 0.85
getPersistedFunction · 0.85

Calls 13

isUndefinedFunction · 0.90
setNewFunction · 0.90
objNewFunction · 0.90
arrayFilterFunction · 0.90
arrayMapFunction · 0.90
escapeIdFunction · 0.90
getWhereConditionFunction · 0.90
objMapFunction · 0.90
objDelFunction · 0.90
objToArrayFunction · 0.90
objIsEmptyFunction · 0.90
canSelectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…