Skip to content

Commit 14e6412

Browse files
committed
Add electric example to readme
1 parent a9213cf commit 14e6412

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,51 @@ graph.run()
135135
// 8 (from 3 + 5)
136136
```
137137

138+
### Using with ElectricSQL
139+
140+
D2TS can be used in conjunction with [ElectricSQL](https://electric-sql.com) to build data pipelines on top of [ShapeStreams](https://electric-sql.com/docs/api/clients/typescript#shapestream) that can be executed incrementally.
141+
142+
> [!NOTE]
143+
> Electric support has not yet been merged to main, you can follow the progress [in this PR](https://github.com/electric-sql/d2ts/pull/11).
144+
145+
Here's an example of how to use D2TS with ElectricSQL:
146+
147+
```typescript
148+
import { D2, map, filter, output } from '@electric-sql/d2ts'
149+
import { electricStreamToD2Input } from '@electric-sql/d2ts/electric'
150+
import { ShapeStream } from '@electric-sql/client'
151+
152+
// Create D2 graph
153+
const graph = new D2({ initialFrontier: 0 })
154+
155+
// Create D2 input
156+
const input = graph.newInput<any>()
157+
158+
// Configure the pipeline
159+
input
160+
.pipe(
161+
map(([key, data]) => data.value),
162+
filter(value => value > 10),
163+
// ... any other processing / joining
164+
output((msg) => doSomething(msg))
165+
)
166+
167+
// Finalize graph
168+
graph.finalize()
169+
170+
// Create Electric stream (example)
171+
const electricStream = new ShapeStream({
172+
url: 'http://localhost:3000/v1/shape',
173+
params: {
174+
table: 'items',
175+
replica: 'full', // <-- IMPORTANT!
176+
}
177+
})
178+
179+
// Connect Electric stream to D2 input
180+
electricStreamToD2Input(electricStream, input)
181+
```
182+
138183
## Examples
139184

140185
There are a number of examples in the [./examples](./examples) directory, covering:

0 commit comments

Comments
 (0)