MCPcopy
hub / github.com/tinyplex/tinybase / setQueryDefinitionImpl

Function setQueryDefinitionImpl

src/queries/index.ts:368–836  ·  view source on GitHub ↗
(queryId: Id)

Source from the content-addressed store, hash-verified

366 };
367
368 const setQueryDefinitionImpl = (queryId: Id): Queries =>
369 getResultStore(queryId).transaction(
370 () =>
371 ifNotUndefined(getQueryArgs(queryId), ([build, , sourceIsQuery]) => {
372 const tableId = getTableId(queryId);
373 const rootStore = sourceIsQuery ? getResultStore(tableId) : store;
374 const resultStore = getResultStore(queryId);
375 const paramValues = getParamValues(queryId);
376
377 setAdd(redefiningQueryIds, queryId);
378 resetPreStores(queryId);
379 resetSourceStores(queryId);
380
381 const selectEntries: [Id, SelectClause][] = [];
382 const joinEntries: [Id | undefined, JoinClause][] = [
383 [
384 undefined,
385 [tableId, undefined, undefined, [], mapNew(), rootStore],
386 ],
387 ];
388 const wheres: WhereClause[] = [];
389 const groupEntries: [Id, GroupClause][] = [];
390 const havings: HavingClause[] = [];
391
392 const param = (paramId: Id) => objGet(paramValues, paramId);
393
394 const select = (
395 arg1:
396 | true
397 | Id
398 | ((getTableCell: GetTableCell, rowId: Id) => CellOrUndefined),
399 arg2?: Id,
400 arg3?: Id,
401 ) => {
402 const joinedTableId = isTrue(arg1) ? arg2 : arg1;
403 const joinedCellId = isTrue(arg1) ? arg3 : arg2;
404 const selectEntry: [Id, SelectClause] = isFunction(arg1)
405 ? [size(selectEntries) + EMPTY_STRING, arg1]
406 : isUndefined(joinedCellId)
407 ? [arg1 as Id, (getTableCell) => getTableCell(arg1 as Id)]
408 : [
409 joinedCellId,
410 (getTableCell) =>
411 isTrue(arg1)
412 ? getTableCell(true, joinedTableId as Id, joinedCellId)
413 : getTableCell(joinedTableId as Id, joinedCellId),
414 ];
415 arrayPush(selectEntries, selectEntry);
416 return {
417 as: (selectedCellId: Id) => (selectEntry[0] = selectedCellId),
418 };
419 };
420
421 const join = (
422 arg1: true | Id,
423 arg2?: Id | ((getCell: GetCell, rowId: Id) => Id | undefined),
424 arg3?: Id | ((getCell: GetCell, rowId: Id) => Id | undefined),
425 arg4?: Id | ((getCell: GetCell, rowId: Id) => Id | undefined),

Callers 1

setQueryDefinitionFunction · 0.70

Calls 15

setAddFunction · 0.90
mapNewFunction · 0.90
collIsEmptyFunction · 0.90
collDelFunction · 0.90
mapForEachFunction · 0.90
mapGetFunction · 0.90
isUndefinedFunction · 0.90
arrayPushFunction · 0.90
arrayIsEmptyFunction · 0.90
mapEnsureFunction · 0.90
setNewFunction · 0.90
collHasFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…