MCPcopy Create free account
hub / github.com/TanStack/db / removeConditions

Function removeConditions

packages/db/src/query/predicate-utils.ts:966–993  ·  view source on GitHub ↗

* Remove specified conditions from a predicate. * Returns the predicate with the specified conditions removed, or undefined if all conditions are removed.

(
  predicate: BasicExpression<boolean>,
  conditionsToRemove: Array<BasicExpression<boolean>>,
)

Source from the content-addressed store, hash-verified

964 * Returns the predicate with the specified conditions removed, or undefined if all conditions are removed.
965 */
966function removeConditions(
967 predicate: BasicExpression<boolean>,
968 conditionsToRemove: Array<BasicExpression<boolean>>,
969): BasicExpression<boolean> | undefined {
970 if (predicate.type === `func` && predicate.name === `and`) {
971 const remainingArgs = predicate.args.filter(
972 (arg) =>
973 !conditionsToRemove.some((cond) =>
974 areExpressionsEqual(arg as BasicExpression<boolean>, cond),
975 ),
976 )
977
978 if (remainingArgs.length === 0) {
979 return undefined
980 } else if (remainingArgs.length === 1) {
981 return remainingArgs[0]!
982 } else {
983 return {
984 type: `func`,
985 name: `and`,
986 args: remainingArgs,
987 } as BasicExpression<boolean>
988 }
989 }
990
991 // For non-AND predicates, don't remove anything
992 return predicate
993}
994
995/**
996 * Combine multiple conditions into a single predicate using AND logic.

Callers 1

minusWherePredicatesFunction · 0.85

Calls 2

areExpressionsEqualFunction · 0.85
filterMethod · 0.80

Tested by

no test coverage detected