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

Function createItem

examples/tanstack/src/Example.tsx:20–37  ·  view source on GitHub ↗
(newId: string)

Source from the content-addressed store, hash-verified

18})
19
20async function createItem(newId: string) {
21 const itemsStream = getShapeStream<Item>(itemShape())
22
23 // Match the insert
24 const findUpdatePromise = matchStream({
25 stream: itemsStream,
26 operations: [`insert`],
27 matchFn: ({ message }) => message.value.id === newId,
28 })
29
30 // Insert item
31 const fetchPromise = fetch(itemsUrl, {
32 method: `POST`,
33 body: JSON.stringify({ id: newId }),
34 })
35
36 return await Promise.all([findUpdatePromise, fetchPromise])
37}
38
39async function clearItems(numItems: number) {
40 const itemsStream = getShapeStream(itemShape())

Callers 1

ExampleFunction · 0.70

Calls 4

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

Tested by

no test coverage detected