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

Function extractInField

packages/db/src/query/predicate-utils.ts:1236–1269  ·  view source on GitHub ↗
(func: Func)

Source from the content-addressed store, hash-verified

1234}
1235
1236function extractInField(func: Func): InField | null {
1237 if (func.name === `in`) {
1238 const firstArg = func.args[0]
1239 const secondArg = func.args[1]
1240
1241 if (
1242 firstArg?.type === `ref` &&
1243 secondArg?.type === `val` &&
1244 Array.isArray(secondArg.value)
1245 ) {
1246 let values = secondArg.value
1247 // Precompute optimization metadata once
1248 const allPrimitives = areAllPrimitives(values)
1249 let primitiveSet: Set<any> | null = null
1250
1251 if (allPrimitives && values.length > 10) {
1252 // Build Set and dedupe values at the same time
1253 primitiveSet = new Set(values)
1254 // If we found duplicates, use the deduped array going forward
1255 if (primitiveSet.size < values.length) {
1256 values = Array.from(primitiveSet)
1257 }
1258 }
1259
1260 return {
1261 ref: firstArg,
1262 values,
1263 areAllPrimitives: allPrimitives,
1264 primitiveSet,
1265 }
1266 }
1267 }
1268 return null
1269}
1270
1271function isComparisonSubset(
1272 subsetFunc: Func,

Callers 4

isWhereSubsetInternalFunction · 0.85
minusSameFieldPredicatesFunction · 0.85
groupPredicatesByFieldFunction · 0.85
unionSameFieldPredicatesFunction · 0.85

Calls 2

areAllPrimitivesFunction · 0.85
fromMethod · 0.80

Tested by

no test coverage detected