@substreams/sink-database-changes
v0.3.6
Published
Substreams Sink Database Changes
Downloads
6
Readme
Substreams Sink Database Changes
Buf Protobuf codegen & TypeBox for
DatabaseChanges
.
Quickstart
$ npm install @substreams/sink-database-changes
import { typebox, zod } from "@substreams/sink-database-changes"
Protobuf
message DatabaseChanges {
repeated TableChange table_changes = 5;
}
message TableChange {
string table = 1;
oneof primary_key {
string pk = 2;
CompositePrimaryKey composite_pk = 6;
}
uint64 ordinal = 3;
Operation operation = 4;
repeated Field fields = 5;
}
message Field {
string name = 1;
string new_value = 2;
string old_value = 3;
}
Using TypeBox Static Type Resolution
import { DatabaseChanges } from "@substreams/sink-entity-changes/typebox"
...
const emitter = new BlockEmitter(transport, request, registry);
emitter.on("anyMessage", (message: DatabaseChanges) => {
for ( const tableChange of message.table_changes ?? []) {
console.log(tableChange);
}
});
Using Zod Static Type Resolution
import { DatabaseChanges } from "@substreams/sink-entity-changes/zod"
...
const emitter = new BlockEmitter(transport, request, registry);
emitter.on("anyMessage", (message: DatabaseChanges) => {
for ( const tableChange of message.table_changes ?? []) {
console.log(tableChange);
}
});
Using Buf Protobuf codegen
import { DatabaseChanges } from "@substreams/sink-entity-changes/entity_pb"
...
const emitter = new BlockEmitter(transport, request, registry);
// Stream DatabaseChanges
emitter.on("output", (output: DatabaseChanges) => {
for ( const tableChange of output?.table_changes ?? []) {
console.log(tableChange);
}
});