0.3.6 • Published 1 month ago

@substreams/sink-database-changes v0.3.6

Weekly downloads
-
License
MIT
Repository
-
Last release
1 month ago

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);
  }
});
0.3.6

1 month ago

0.3.5

3 months ago

0.3.2

5 months ago

0.3.0

6 months ago