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

Function count

packages/db-ivm/src/operators/count.ts:31–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

29 * Counts the number of elements by key (version-free)
30 */
31export function count<
32 KType extends T extends KeyValue<infer K, infer _V> ? K : never,
33 VType extends T extends KeyValue<KType, infer V> ? V : never,
34 T,
35>() {
36 return (
37 stream: IStreamBuilder<T>,
38 ): IStreamBuilder<KeyValue<KType, number>> => {
39 const output = new StreamBuilder<KeyValue<KType, number>>(
40 stream.graph,
41 new DifferenceStreamWriter<KeyValue<KType, number>>(),
42 )
43 const operator = new CountOperator<KType, VType>(
44 stream.graph.getNextOperatorId(),
45 stream.connectReader() as DifferenceStreamReader<KeyValue<KType, VType>>,
46 output.writer,
47 )
48 stream.graph.addOperator(operator)
49 return output
50 }
51}

Callers 7

groupBy.test.tsFile · 0.50
testCountFunction · 0.50
ListsScreenFunction · 0.50

Calls 3

getNextOperatorIdMethod · 0.80
connectReaderMethod · 0.80
addOperatorMethod · 0.80

Tested by 1

testCountFunction · 0.40