1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
// @generated by buffa-codegen. DO NOT EDIT.
// source: sf/substreams/sink/database/v1/database.proto
/// DatabaseChanges represents a collection of table changes that should be applied to a database.
/// This is the top-level message that Substreams modules output when using the database sink.
/// All changes within a DatabaseChanges message are typically applied within a single transaction.
#[derive(Clone, PartialEq, Default)]
pub struct DatabaseChanges {
/// table_changes is an ordered list of changes to apply to database tables.
/// The changes are applied in the order they appear in this list.
///
/// Field 1: `table_changes`
pub table_changes: ::buffa::alloc::vec::Vec<TableChange>,
}
impl ::core::fmt::Debug for DatabaseChanges {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct("DatabaseChanges")
.field("table_changes", &self.table_changes)
.finish()
}
}
impl DatabaseChanges {
/// Protobuf type URL for this message, for use with `Any::pack` and
/// `Any::unpack_if`.
///
/// Format: `type.googleapis.com/<fully.qualified.TypeName>`
pub const TYPE_URL: &'static str = "type.googleapis.com/sf.substreams.sink.database.v1.DatabaseChanges";
}
::buffa::impl_default_instance!(DatabaseChanges);
impl ::buffa::MessageName for DatabaseChanges {
const PACKAGE: &'static str = "sf.substreams.sink.database.v1";
const NAME: &'static str = "DatabaseChanges";
const FULL_NAME: &'static str = "sf.substreams.sink.database.v1.DatabaseChanges";
const TYPE_URL: &'static str = "type.googleapis.com/sf.substreams.sink.database.v1.DatabaseChanges";
}
impl ::buffa::Message for DatabaseChanges {
/// Returns the total encoded size in bytes.
///
/// Accumulates in `u64` (which cannot overflow for in-memory
/// data) and saturates to `u32` at return, so a message whose
/// encoded size exceeds the 2 GiB protobuf limit yields a value
/// above [`::buffa::MAX_MESSAGE_BYTES`] that the encode entry
/// points reject, never a silently wrapped size.
#[allow(clippy::let_and_return)]
fn compute_size(&self, __cache: &mut ::buffa::SizeCache) -> u32 {
#[allow(unused_imports)]
use ::buffa::Enumeration as _;
let mut size = 0u64;
for v in &self.table_changes {
let __slot = __cache.reserve();
let inner_size = v.compute_size(__cache);
__cache.set(__slot, inner_size);
size
+= 1u64 + ::buffa::encoding::varint_len(inner_size as u64) as u64
+ inner_size as u64;
}
::buffa::saturate_size(size)
}
fn write_to(
&self,
__cache: &mut ::buffa::SizeCache,
buf: &mut impl ::buffa::EncodeSink,
) {
#[allow(unused_imports)]
use ::buffa::Enumeration as _;
for v in &self.table_changes {
::buffa::types::put_len_delimited_header(
1u32,
u64::from(__cache.consume_next()),
buf,
);
v.write_to(__cache, buf);
}
}
fn merge_field(
&mut self,
tag: ::buffa::encoding::Tag,
buf: &mut impl ::buffa::bytes::Buf,
ctx: ::buffa::DecodeContext<'_>,
) -> ::core::result::Result<(), ::buffa::DecodeError> {
#[allow(unused_imports)]
use ::buffa::bytes::Buf as _;
#[allow(unused_imports)]
use ::buffa::Enumeration as _;
match tag.field_number() {
1u32 => {
::buffa::encoding::check_wire_type(
tag,
::buffa::encoding::WireType::LengthDelimited,
)?;
let mut elem = ::core::default::Default::default();
ctx.register_element_memory(
::buffa::__private::element_footprint(&elem),
)?;
::buffa::Message::merge_length_delimited(&mut elem, buf, ctx)?;
self.table_changes.push(elem);
}
_ => {
::buffa::encoding::skip_field_depth(tag, buf, ctx.depth())?;
}
}
::core::result::Result::Ok(())
}
fn clear(&mut self) {
self.table_changes.clear();
}
}
/// TableChange represents a single change operation (CREATE, UPDATE, DELETE, or UPSERT) on a database table row.
/// Each TableChange must specify the table name, primary key, operation type, and the fields to modify.
#[derive(Clone, PartialEq, Default)]
pub struct TableChange {
/// table is the name of the database table to modify.
/// This should match the actual table name in your database schema.
///
/// Field 1: `table`
pub table: ::buffa::alloc::string::String,
/// ordinal provides ordering information for this change within the block.
/// Changes with lower ordinal values are applied before changes with higher values.
/// This ensures deterministic ordering when multiple changes affect the same or related data.
///
/// Field 3: `ordinal`
pub ordinal: u64,
/// operation specifies what type of change to apply to the table row.
///
/// Field 4: `operation`
pub operation: ::buffa::EnumValue<table_change::Operation>,
/// fields contains the column values to set or update.
/// For CREATE and UPSERT operations, these are the values for the new/updated row.
/// For UPDATE operations, these are the columns to modify.
/// For DELETE operations, fields may be empty or contain old values for logging/auditing.
///
/// Field 5: `fields`
pub fields: ::buffa::alloc::vec::Vec<Field>,
pub primary_key: ::core::option::Option<__buffa::oneof::table_change::PrimaryKey>,
}
impl ::core::fmt::Debug for TableChange {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct("TableChange")
.field("table", &self.table)
.field("ordinal", &self.ordinal)
.field("operation", &self.operation)
.field("fields", &self.fields)
.field("primary_key", &self.primary_key)
.finish()
}
}
impl TableChange {
/// Protobuf type URL for this message, for use with `Any::pack` and
/// `Any::unpack_if`.
///
/// Format: `type.googleapis.com/<fully.qualified.TypeName>`
pub const TYPE_URL: &'static str = "type.googleapis.com/sf.substreams.sink.database.v1.TableChange";
}
::buffa::impl_default_instance!(TableChange);
impl ::buffa::MessageName for TableChange {
const PACKAGE: &'static str = "sf.substreams.sink.database.v1";
const NAME: &'static str = "TableChange";
const FULL_NAME: &'static str = "sf.substreams.sink.database.v1.TableChange";
const TYPE_URL: &'static str = "type.googleapis.com/sf.substreams.sink.database.v1.TableChange";
}
impl ::buffa::Message for TableChange {
/// Returns the total encoded size in bytes.
///
/// Accumulates in `u64` (which cannot overflow for in-memory
/// data) and saturates to `u32` at return, so a message whose
/// encoded size exceeds the 2 GiB protobuf limit yields a value
/// above [`::buffa::MAX_MESSAGE_BYTES`] that the encode entry
/// points reject, never a silently wrapped size.
#[allow(clippy::let_and_return)]
fn compute_size(&self, __cache: &mut ::buffa::SizeCache) -> u32 {
#[allow(unused_imports)]
use ::buffa::Enumeration as _;
let mut size = 0u64;
if !self.table.is_empty() {
size += 1u64 + ::buffa::types::string_encoded_len(&self.table) as u64;
}
if let ::core::option::Option::Some(ref v) = self.primary_key {
match v {
__buffa::oneof::table_change::PrimaryKey::Pk(x) => {
size += 1u64 + ::buffa::types::string_encoded_len(x) as u64;
}
__buffa::oneof::table_change::PrimaryKey::CompositePk(x) => {
let __slot = __cache.reserve();
let inner = x.compute_size(__cache);
__cache.set(__slot, inner);
size
+= 1u64 + ::buffa::encoding::varint_len(inner as u64) as u64
+ inner as u64;
}
}
}
if self.ordinal != 0u64 {
size += 1u64 + ::buffa::types::uint64_encoded_len(self.ordinal) as u64;
}
{
let val = self.operation.to_i32();
if val != 0 {
size += 1u64 + ::buffa::types::int32_encoded_len(val) as u64;
}
}
for v in &self.fields {
let __slot = __cache.reserve();
let inner_size = v.compute_size(__cache);
__cache.set(__slot, inner_size);
size
+= 1u64 + ::buffa::encoding::varint_len(inner_size as u64) as u64
+ inner_size as u64;
}
::buffa::saturate_size(size)
}
fn write_to(
&self,
__cache: &mut ::buffa::SizeCache,
buf: &mut impl ::buffa::EncodeSink,
) {
#[allow(unused_imports)]
use ::buffa::Enumeration as _;
if !self.table.is_empty() {
::buffa::types::put_string_field(1u32, &self.table, buf);
}
if let ::core::option::Option::Some(ref v) = self.primary_key {
match v {
__buffa::oneof::table_change::PrimaryKey::Pk(x) => {
::buffa::types::put_string_field(2u32, x, buf);
}
__buffa::oneof::table_change::PrimaryKey::CompositePk(x) => {
::buffa::types::put_len_delimited_header(
6u32,
u64::from(__cache.consume_next()),
buf,
);
x.write_to(__cache, buf);
}
}
}
if self.ordinal != 0u64 {
::buffa::types::put_uint64_field(3u32, self.ordinal, buf);
}
{
let val = self.operation.to_i32();
if val != 0 {
::buffa::types::put_int32_field(4u32, val, buf);
}
}
for v in &self.fields {
::buffa::types::put_len_delimited_header(
5u32,
u64::from(__cache.consume_next()),
buf,
);
v.write_to(__cache, buf);
}
}
fn merge_field(
&mut self,
tag: ::buffa::encoding::Tag,
buf: &mut impl ::buffa::bytes::Buf,
ctx: ::buffa::DecodeContext<'_>,
) -> ::core::result::Result<(), ::buffa::DecodeError> {
#[allow(unused_imports)]
use ::buffa::bytes::Buf as _;
#[allow(unused_imports)]
use ::buffa::Enumeration as _;
match tag.field_number() {
1u32 => {
::buffa::encoding::check_wire_type(
tag,
::buffa::encoding::WireType::LengthDelimited,
)?;
::buffa::types::merge_string(&mut self.table, buf)?;
}
2u32 => {
::buffa::encoding::check_wire_type(
tag,
::buffa::encoding::WireType::LengthDelimited,
)?;
self.primary_key = ::core::option::Option::Some(
__buffa::oneof::table_change::PrimaryKey::Pk(
::buffa::types::decode_string(buf)?,
),
);
}
6u32 => {
::buffa::encoding::check_wire_type(
tag,
::buffa::encoding::WireType::LengthDelimited,
)?;
if let ::core::option::Option::Some(
__buffa::oneof::table_change::PrimaryKey::CompositePk(
ref mut existing,
),
) = self.primary_key
{
::buffa::Message::merge_length_delimited(&mut **existing, buf, ctx)?;
} else {
let mut val = ::core::default::Default::default();
::buffa::Message::merge_length_delimited(&mut val, buf, ctx)?;
self.primary_key = ::core::option::Option::Some(
__buffa::oneof::table_change::PrimaryKey::CompositePk(
::buffa::alloc::boxed::Box::new(val),
),
);
}
}
3u32 => {
::buffa::encoding::check_wire_type(
tag,
::buffa::encoding::WireType::Varint,
)?;
self.ordinal = ::buffa::types::decode_uint64(buf)?;
}
4u32 => {
::buffa::encoding::check_wire_type(
tag,
::buffa::encoding::WireType::Varint,
)?;
self.operation = ::buffa::EnumValue::from(
::buffa::types::decode_int32(buf)?,
);
}
5u32 => {
::buffa::encoding::check_wire_type(
tag,
::buffa::encoding::WireType::LengthDelimited,
)?;
let mut elem = ::core::default::Default::default();
ctx.register_element_memory(
::buffa::__private::element_footprint(&elem),
)?;
::buffa::Message::merge_length_delimited(&mut elem, buf, ctx)?;
self.fields.push(elem);
}
_ => {
::buffa::encoding::skip_field_depth(tag, buf, ctx.depth())?;
}
}
::core::result::Result::Ok(())
}
fn clear(&mut self) {
self.table.clear();
self.primary_key = ::core::option::Option::None;
self.ordinal = 0u64;
self.operation = ::buffa::EnumValue::from(0);
self.fields.clear();
}
}
pub mod table_change {
#[allow(unused_imports)]
use super::*;
/// Operation defines the type of database operation to perform on the row.
#[allow(non_camel_case_types)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
#[repr(i32)]
pub enum Operation {
/// OPERATION_UNSPECIFIED should not be used in practice.
/// This exists as the protobuf default to ensure consumers explicitly set the operation type.
OPERATION_UNSPECIFIED = 0i32,
/// OPERATION_CREATE inserts a new row into the table.
/// Will fail if a row with the same primary key already exists.
OPERATION_CREATE = 1i32,
/// OPERATION_UPDATE modifies an existing row in the table.
/// Will fail if no row with the specified primary key exists.
OPERATION_UPDATE = 2i32,
/// OPERATION_DELETE removes a row from the table.
/// Will fail if no row with the specified primary key exists.
OPERATION_DELETE = 3i32,
/// OPERATION_UPSERT inserts a new row or updates an existing row.
/// If a row with the primary key exists, it updates; otherwise, it creates.
///
/// The upsert might not be supported by all drivers the sink supports,
/// refer to <https://github.com/streamingfast/substreams-sink-sql> for
/// which drivers support it.
///
/// At time of writing, the Postgres driver supports was the only one supporting
/// it.
OPERATION_UPSERT = 4i32,
}
impl Operation {
///Idiomatic alias for [`Self::OPERATION_UNSPECIFIED`]; `Debug` prints the variant name.
#[allow(non_upper_case_globals)]
pub const Unspecified: Self = Self::OPERATION_UNSPECIFIED;
///Idiomatic alias for [`Self::OPERATION_CREATE`]; `Debug` prints the variant name.
#[allow(non_upper_case_globals)]
pub const Create: Self = Self::OPERATION_CREATE;
///Idiomatic alias for [`Self::OPERATION_UPDATE`]; `Debug` prints the variant name.
#[allow(non_upper_case_globals)]
pub const Update: Self = Self::OPERATION_UPDATE;
///Idiomatic alias for [`Self::OPERATION_DELETE`]; `Debug` prints the variant name.
#[allow(non_upper_case_globals)]
pub const Delete: Self = Self::OPERATION_DELETE;
///Idiomatic alias for [`Self::OPERATION_UPSERT`]; `Debug` prints the variant name.
#[allow(non_upper_case_globals)]
pub const Upsert: Self = Self::OPERATION_UPSERT;
}
impl ::core::default::Default for Operation {
fn default() -> Self {
Self::OPERATION_UNSPECIFIED
}
}
impl ::buffa::Enumeration for Operation {
fn from_i32(value: i32) -> ::core::option::Option<Self> {
match value {
0i32 => ::core::option::Option::Some(Self::OPERATION_UNSPECIFIED),
1i32 => ::core::option::Option::Some(Self::OPERATION_CREATE),
2i32 => ::core::option::Option::Some(Self::OPERATION_UPDATE),
3i32 => ::core::option::Option::Some(Self::OPERATION_DELETE),
4i32 => ::core::option::Option::Some(Self::OPERATION_UPSERT),
_ => ::core::option::Option::None,
}
}
fn to_i32(&self) -> i32 {
*self as i32
}
fn proto_name(&self) -> &'static str {
match self {
Self::OPERATION_UNSPECIFIED => "OPERATION_UNSPECIFIED",
Self::OPERATION_CREATE => "OPERATION_CREATE",
Self::OPERATION_UPDATE => "OPERATION_UPDATE",
Self::OPERATION_DELETE => "OPERATION_DELETE",
Self::OPERATION_UPSERT => "OPERATION_UPSERT",
}
}
fn from_proto_name(name: &str) -> ::core::option::Option<Self> {
match name {
"OPERATION_UNSPECIFIED" => {
::core::option::Option::Some(Self::OPERATION_UNSPECIFIED)
}
"OPERATION_CREATE" => {
::core::option::Option::Some(Self::OPERATION_CREATE)
}
"OPERATION_UPDATE" => {
::core::option::Option::Some(Self::OPERATION_UPDATE)
}
"OPERATION_DELETE" => {
::core::option::Option::Some(Self::OPERATION_DELETE)
}
"OPERATION_UPSERT" => {
::core::option::Option::Some(Self::OPERATION_UPSERT)
}
_ => ::core::option::Option::None,
}
}
fn values() -> &'static [Self] {
&[
Self::OPERATION_UNSPECIFIED,
Self::OPERATION_CREATE,
Self::OPERATION_UPDATE,
Self::OPERATION_DELETE,
Self::OPERATION_UPSERT,
]
}
}
#[doc(inline)]
pub use super::__buffa::oneof::table_change::PrimaryKey;
#[doc(inline)]
pub use super::__buffa::view::oneof::table_change::PrimaryKey as PrimaryKeyView;
}
/// CompositePrimaryKey represents a primary key composed of multiple columns.
/// Use this when your table has a multi-column primary key instead of a single primary key column.
#[derive(Clone, PartialEq, Default)]
pub struct CompositePrimaryKey {
/// keys is a map from column name to column value for each part of the composite primary key.
/// All values are represented as strings and will be converted to the appropriate type by the sink.
/// Example: {"user_id": "123", "post_id": "456"} for a table with composite primary key (user_id, post_id)
///
/// Field 1: `keys`
pub keys: ::buffa::__private::HashMap<
::buffa::alloc::string::String,
::buffa::alloc::string::String,
>,
}
impl ::core::fmt::Debug for CompositePrimaryKey {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct("CompositePrimaryKey").field("keys", &self.keys).finish()
}
}
impl CompositePrimaryKey {
/// Protobuf type URL for this message, for use with `Any::pack` and
/// `Any::unpack_if`.
///
/// Format: `type.googleapis.com/<fully.qualified.TypeName>`
pub const TYPE_URL: &'static str = "type.googleapis.com/sf.substreams.sink.database.v1.CompositePrimaryKey";
}
::buffa::impl_default_instance!(CompositePrimaryKey);
impl ::buffa::MessageName for CompositePrimaryKey {
const PACKAGE: &'static str = "sf.substreams.sink.database.v1";
const NAME: &'static str = "CompositePrimaryKey";
const FULL_NAME: &'static str = "sf.substreams.sink.database.v1.CompositePrimaryKey";
const TYPE_URL: &'static str = "type.googleapis.com/sf.substreams.sink.database.v1.CompositePrimaryKey";
}
impl ::buffa::Message for CompositePrimaryKey {
/// Returns the total encoded size in bytes.
///
/// Accumulates in `u64` (which cannot overflow for in-memory
/// data) and saturates to `u32` at return, so a message whose
/// encoded size exceeds the 2 GiB protobuf limit yields a value
/// above [`::buffa::MAX_MESSAGE_BYTES`] that the encode entry
/// points reject, never a silently wrapped size.
#[allow(clippy::let_and_return)]
fn compute_size(&self, _cache: &mut ::buffa::SizeCache) -> u32 {
#[allow(unused_imports)]
use ::buffa::Enumeration as _;
let mut size = 0u64;
size
+= ::buffa::map_codec::field_len::<
::buffa::map_codec::Str,
::buffa::map_codec::Str,
_,
>(&self.keys, 1u64);
::buffa::saturate_size(size)
}
fn write_to(
&self,
_cache: &mut ::buffa::SizeCache,
buf: &mut impl ::buffa::EncodeSink,
) {
#[allow(unused_imports)]
use ::buffa::Enumeration as _;
::buffa::map_codec::write_field::<
::buffa::map_codec::Str,
::buffa::map_codec::Str,
_,
>(&self.keys, 1u32, buf);
}
fn merge_field(
&mut self,
tag: ::buffa::encoding::Tag,
buf: &mut impl ::buffa::bytes::Buf,
ctx: ::buffa::DecodeContext<'_>,
) -> ::core::result::Result<(), ::buffa::DecodeError> {
#[allow(unused_imports)]
use ::buffa::bytes::Buf as _;
#[allow(unused_imports)]
use ::buffa::Enumeration as _;
match tag.field_number() {
1u32 => {
::buffa::encoding::check_wire_type(
tag,
::buffa::encoding::WireType::LengthDelimited,
)?;
::buffa::map_codec::merge_entry::<
::buffa::map_codec::Str,
::buffa::map_codec::Str,
_,
>(&mut self.keys, buf, ctx)?;
}
_ => {
::buffa::encoding::skip_field_depth(tag, buf, ctx.depth())?;
}
}
::core::result::Result::Ok(())
}
fn clear(&mut self) {
self.keys.clear();
}
}
/// Field represents a single column value in a table row.
/// Contains the column name, value, and an update operation mode for UPSERT operations.
#[derive(Clone, PartialEq, Default)]
pub struct Field {
/// name is the column name in the database table.
/// Must match the actual column name in your database schema.
///
/// Field 1: `name`
pub name: ::buffa::alloc::string::String,
/// value is the value to set for this column.
/// All values are represented as strings and will be converted to the appropriate database type.
/// For numeric types, use string representation (e.g., "123", "45.67").
/// For NULL values, leave this field empty or unset.
///
/// Field 2: `value`
pub value: ::buffa::alloc::string::String,
/// update_op specifies how to merge this field's value during UPSERT operations.
/// Defaults to UPDATE_OP_SET if not specified.
/// Ignored for CREATE, UPDATE, and DELETE operations.
///
/// Field 4: `update_op`
pub update_op: ::buffa::EnumValue<field::UpdateOp>,
}
impl ::core::fmt::Debug for Field {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct("Field")
.field("name", &self.name)
.field("value", &self.value)
.field("update_op", &self.update_op)
.finish()
}
}
impl Field {
/// Protobuf type URL for this message, for use with `Any::pack` and
/// `Any::unpack_if`.
///
/// Format: `type.googleapis.com/<fully.qualified.TypeName>`
pub const TYPE_URL: &'static str = "type.googleapis.com/sf.substreams.sink.database.v1.Field";
}
::buffa::impl_default_instance!(Field);
impl ::buffa::MessageName for Field {
const PACKAGE: &'static str = "sf.substreams.sink.database.v1";
const NAME: &'static str = "Field";
const FULL_NAME: &'static str = "sf.substreams.sink.database.v1.Field";
const TYPE_URL: &'static str = "type.googleapis.com/sf.substreams.sink.database.v1.Field";
}
impl ::buffa::Message for Field {
/// Returns the total encoded size in bytes.
///
/// Accumulates in `u64` (which cannot overflow for in-memory
/// data) and saturates to `u32` at return, so a message whose
/// encoded size exceeds the 2 GiB protobuf limit yields a value
/// above [`::buffa::MAX_MESSAGE_BYTES`] that the encode entry
/// points reject, never a silently wrapped size.
#[allow(clippy::let_and_return)]
fn compute_size(&self, _cache: &mut ::buffa::SizeCache) -> u32 {
#[allow(unused_imports)]
use ::buffa::Enumeration as _;
let mut size = 0u64;
if !self.name.is_empty() {
size += 1u64 + ::buffa::types::string_encoded_len(&self.name) as u64;
}
if !self.value.is_empty() {
size += 1u64 + ::buffa::types::string_encoded_len(&self.value) as u64;
}
{
let val = self.update_op.to_i32();
if val != 0 {
size += 1u64 + ::buffa::types::int32_encoded_len(val) as u64;
}
}
::buffa::saturate_size(size)
}
fn write_to(
&self,
_cache: &mut ::buffa::SizeCache,
buf: &mut impl ::buffa::EncodeSink,
) {
#[allow(unused_imports)]
use ::buffa::Enumeration as _;
if !self.name.is_empty() {
::buffa::types::put_string_field(1u32, &self.name, buf);
}
if !self.value.is_empty() {
::buffa::types::put_string_field(2u32, &self.value, buf);
}
{
let val = self.update_op.to_i32();
if val != 0 {
::buffa::types::put_int32_field(4u32, val, buf);
}
}
}
fn merge_field(
&mut self,
tag: ::buffa::encoding::Tag,
buf: &mut impl ::buffa::bytes::Buf,
ctx: ::buffa::DecodeContext<'_>,
) -> ::core::result::Result<(), ::buffa::DecodeError> {
#[allow(unused_imports)]
use ::buffa::bytes::Buf as _;
#[allow(unused_imports)]
use ::buffa::Enumeration as _;
match tag.field_number() {
1u32 => {
::buffa::encoding::check_wire_type(
tag,
::buffa::encoding::WireType::LengthDelimited,
)?;
::buffa::types::merge_string(&mut self.name, buf)?;
}
2u32 => {
::buffa::encoding::check_wire_type(
tag,
::buffa::encoding::WireType::LengthDelimited,
)?;
::buffa::types::merge_string(&mut self.value, buf)?;
}
4u32 => {
::buffa::encoding::check_wire_type(
tag,
::buffa::encoding::WireType::Varint,
)?;
self.update_op = ::buffa::EnumValue::from(
::buffa::types::decode_int32(buf)?,
);
}
_ => {
::buffa::encoding::skip_field_depth(tag, buf, ctx.depth())?;
}
}
::core::result::Result::Ok(())
}
fn clear(&mut self) {
self.name.clear();
self.value.clear();
self.update_op = ::buffa::EnumValue::from(0);
}
}
pub mod field {
#[allow(unused_imports)]
use super::*;
/// UpdateOp defines how the field value should be combined with existing data during UPSERT operations.
/// Only applies when TableChange.operation is OPERATION_UPSERT.
/// Allows for advanced merge behaviors beyond simple replacement.
#[allow(non_camel_case_types)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
#[repr(i32)]
pub enum UpdateOp {
/// UPDATE_OP_UNSPECIFIED should not be used in practice.
/// This exists as the protobuf default to ensure consumers explicitly set the update operation type.
UPDATE_OP_UNSPECIFIED = 0i32,
/// UPDATE_OP_SET replaces the column value with the provided value (default behavior).
/// SQL equivalent: column = value
UPDATE_OP_SET = 1i32,
/// UPDATE_OP_ADD adds the provided value to the existing column value.
/// Useful for counters and numeric accumulation.
/// SQL equivalent: column = COALESCE(column, 0) + value
UPDATE_OP_ADD = 2i32,
/// UPDATE_OP_MAX sets the column to the maximum of existing value and provided value.
/// Useful for tracking high-water marks or maximum observed values.
/// SQL equivalent: column = GREATEST(COALESCE(column, value), value)
UPDATE_OP_MAX = 3i32,
/// UPDATE_OP_MIN sets the column to the minimum of existing value and provided value.
/// Useful for tracking low-water marks or minimum observed values.
/// SQL equivalent: column = LEAST(COALESCE(column, value), value)
UPDATE_OP_MIN = 4i32,
/// UPDATE_OP_SET_IF_NULL sets the column to the provided value only if it's currently NULL.
/// Preserves the first non-NULL value and prevents subsequent overwrites.
/// SQL equivalent: column = COALESCE(column, value)
UPDATE_OP_SET_IF_NULL = 5i32,
}
impl UpdateOp {
///Idiomatic alias for [`Self::UPDATE_OP_UNSPECIFIED`]; `Debug` prints the variant name.
#[allow(non_upper_case_globals)]
pub const Unspecified: Self = Self::UPDATE_OP_UNSPECIFIED;
///Idiomatic alias for [`Self::UPDATE_OP_SET`]; `Debug` prints the variant name.
#[allow(non_upper_case_globals)]
pub const Set: Self = Self::UPDATE_OP_SET;
///Idiomatic alias for [`Self::UPDATE_OP_ADD`]; `Debug` prints the variant name.
#[allow(non_upper_case_globals)]
pub const Add: Self = Self::UPDATE_OP_ADD;
///Idiomatic alias for [`Self::UPDATE_OP_MAX`]; `Debug` prints the variant name.
#[allow(non_upper_case_globals)]
pub const Max: Self = Self::UPDATE_OP_MAX;
///Idiomatic alias for [`Self::UPDATE_OP_MIN`]; `Debug` prints the variant name.
#[allow(non_upper_case_globals)]
pub const Min: Self = Self::UPDATE_OP_MIN;
///Idiomatic alias for [`Self::UPDATE_OP_SET_IF_NULL`]; `Debug` prints the variant name.
#[allow(non_upper_case_globals)]
pub const SetIfNull: Self = Self::UPDATE_OP_SET_IF_NULL;
}
impl ::core::default::Default for UpdateOp {
fn default() -> Self {
Self::UPDATE_OP_UNSPECIFIED
}
}
impl ::buffa::Enumeration for UpdateOp {
fn from_i32(value: i32) -> ::core::option::Option<Self> {
match value {
0i32 => ::core::option::Option::Some(Self::UPDATE_OP_UNSPECIFIED),
1i32 => ::core::option::Option::Some(Self::UPDATE_OP_SET),
2i32 => ::core::option::Option::Some(Self::UPDATE_OP_ADD),
3i32 => ::core::option::Option::Some(Self::UPDATE_OP_MAX),
4i32 => ::core::option::Option::Some(Self::UPDATE_OP_MIN),
5i32 => ::core::option::Option::Some(Self::UPDATE_OP_SET_IF_NULL),
_ => ::core::option::Option::None,
}
}
fn to_i32(&self) -> i32 {
*self as i32
}
fn proto_name(&self) -> &'static str {
match self {
Self::UPDATE_OP_UNSPECIFIED => "UPDATE_OP_UNSPECIFIED",
Self::UPDATE_OP_SET => "UPDATE_OP_SET",
Self::UPDATE_OP_ADD => "UPDATE_OP_ADD",
Self::UPDATE_OP_MAX => "UPDATE_OP_MAX",
Self::UPDATE_OP_MIN => "UPDATE_OP_MIN",
Self::UPDATE_OP_SET_IF_NULL => "UPDATE_OP_SET_IF_NULL",
}
}
fn from_proto_name(name: &str) -> ::core::option::Option<Self> {
match name {
"UPDATE_OP_UNSPECIFIED" => {
::core::option::Option::Some(Self::UPDATE_OP_UNSPECIFIED)
}
"UPDATE_OP_SET" => ::core::option::Option::Some(Self::UPDATE_OP_SET),
"UPDATE_OP_ADD" => ::core::option::Option::Some(Self::UPDATE_OP_ADD),
"UPDATE_OP_MAX" => ::core::option::Option::Some(Self::UPDATE_OP_MAX),
"UPDATE_OP_MIN" => ::core::option::Option::Some(Self::UPDATE_OP_MIN),
"UPDATE_OP_SET_IF_NULL" => {
::core::option::Option::Some(Self::UPDATE_OP_SET_IF_NULL)
}
_ => ::core::option::Option::None,
}
}
fn values() -> &'static [Self] {
&[
Self::UPDATE_OP_UNSPECIFIED,
Self::UPDATE_OP_SET,
Self::UPDATE_OP_ADD,
Self::UPDATE_OP_MAX,
Self::UPDATE_OP_MIN,
Self::UPDATE_OP_SET_IF_NULL,
]
}
}
}