MCPcopy Create free account
hub / github.com/electric-sql/electric / clearItems

Function clearItems

examples/tanstack/src/Example.tsx:39–57  ·  view source on GitHub ↗
(numItems: number)

Source from the content-addressed store, hash-verified

37}
38
39async function clearItems(numItems: number) {
40 const itemsStream = getShapeStream(itemShape())
41
42 // Match the delete
43 const findUpdatePromise =
44 numItems > 0
45 ? matchStream({
46 stream: itemsStream,
47 operations: [`delete`],
48 // First delete will match
49 matchFn: () => true,
50 })
51 : Promise.resolve()
52
53 // Delete all items
54 const fetchPromise = fetch(itemsUrl, { method: `DELETE` })
55
56 return await Promise.all([findUpdatePromise, fetchPromise])
57}
58
59export const Example = () => {
60 const queryClient = useQueryClient()

Callers 1

ExampleFunction · 0.85

Calls 4

getShapeStreamFunction · 0.90
matchStreamFunction · 0.90
itemShapeFunction · 0.85
fetchFunction · 0.85

Tested by

no test coverage detected