diff --git a/config/mssql.go b/config/mssql.go index 608eb703..e39e2539 100644 --- a/config/mssql.go +++ b/config/mssql.go @@ -1,6 +1,7 @@ package config import ( + "cmp" "fmt" "github.com/artie-labs/reader/constants" "github.com/artie-labs/reader/lib/rdbms/scan" @@ -20,12 +21,14 @@ type MSSQL struct { } type MSSQLTable struct { - Name string `yaml:"name"` - Schema string `yaml:"schema"` - BatchSize uint `yaml:"batchSize"` - OptionalPrimaryKeyValStart string `yaml:"optionalPrimaryKeyValStart"` - OptionalPrimaryKeyValEnd string `yaml:"optionalPrimaryKeyValEnd"` - ExcludeColumns []string `yaml:"excludeColumns"` + Name string `yaml:"name"` + Schema string `yaml:"schema"` + + // Optional settings + BatchSize uint `yaml:"batchSize,omitempty"` + OptionalPrimaryKeyValStart string `yaml:"optionalPrimaryKeyValStart,omitempty"` + OptionalPrimaryKeyValEnd string `yaml:"optionalPrimaryKeyValEnd,omitempty"` + ExcludeColumns []string `yaml:"excludeColumns,omitempty"` } func (m *MSSQL) ToDSN() string { @@ -43,11 +46,7 @@ func (m *MSSQL) ToDSN() string { } func (m *MSSQLTable) GetBatchSize() uint { - if m.BatchSize > 0 { - return m.BatchSize - } else { - return constants.DefaultBatchSize - } + return cmp.Or(m.BatchSize, constants.DefaultBatchSize) } func (m *MSSQLTable) GetOptionalPrimaryKeyValStart() []string { diff --git a/config/mysql.go b/config/mysql.go index eb4e450c..11f67b31 100644 --- a/config/mysql.go +++ b/config/mysql.go @@ -1,6 +1,7 @@ package config import ( + "cmp" "fmt" "math" "strings" @@ -32,19 +33,16 @@ func (m *MySQL) ToDSN() string { } type MySQLTable struct { - Name string `yaml:"name"` - BatchSize uint `yaml:"batchSize"` - OptionalPrimaryKeyValStart string `yaml:"optionalPrimaryKeyValStart"` - OptionalPrimaryKeyValEnd string `yaml:"optionalPrimaryKeyValEnd"` - ExcludeColumns []string `yaml:"excludeColumns"` + Name string `yaml:"name"` + // Optional settings + BatchSize uint `yaml:"batchSize,omitempty"` + OptionalPrimaryKeyValStart string `yaml:"optionalPrimaryKeyValStart,omitempty"` + OptionalPrimaryKeyValEnd string `yaml:"optionalPrimaryKeyValEnd,omitempty"` + ExcludeColumns []string `yaml:"excludeColumns,omitempty"` } func (m *MySQLTable) GetBatchSize() uint { - if m.BatchSize > 0 { - return m.BatchSize - } else { - return constants.DefaultBatchSize - } + return cmp.Or(m.BatchSize, constants.DefaultBatchSize) } func (m *MySQLTable) GetOptionalPrimaryKeyValStart() []string { diff --git a/config/postgres.go b/config/postgres.go index d5f9234c..6ec0f470 100644 --- a/config/postgres.go +++ b/config/postgres.go @@ -1,6 +1,7 @@ package config import ( + "cmp" "fmt" "math" "strings" @@ -33,20 +34,18 @@ func (p *PostgreSQL) ToDSN() string { } type PostgreSQLTable struct { - Name string `yaml:"name"` - Schema string `yaml:"schema"` - BatchSize uint `yaml:"batchSize"` - OptionalPrimaryKeyValStart string `yaml:"optionalPrimaryKeyValStart"` - OptionalPrimaryKeyValEnd string `yaml:"optionalPrimaryKeyValEnd"` - ExcludeColumns []string `yaml:"excludeColumns"` + Name string `yaml:"name"` + Schema string `yaml:"schema"` + + // Optional settings + BatchSize uint `yaml:"batchSize,omitempty"` + OptionalPrimaryKeyValStart string `yaml:"optionalPrimaryKeyValStart,omitempty"` + OptionalPrimaryKeyValEnd string `yaml:"optionalPrimaryKeyValEnd,omitempty"` + ExcludeColumns []string `yaml:"excludeColumns,omitempty"` } func (p *PostgreSQLTable) GetBatchSize() uint { - if p.BatchSize > 0 { - return p.BatchSize - } else { - return constants.DefaultBatchSize - } + return cmp.Or(p.BatchSize, constants.DefaultBatchSize) } func (p *PostgreSQLTable) GetOptionalPrimaryKeyValStart() []string { diff --git a/sources/dynamodb/snapshot.go b/sources/dynamodb/snapshot.go index bb2f9642..f4c34915 100644 --- a/sources/dynamodb/snapshot.go +++ b/sources/dynamodb/snapshot.go @@ -94,7 +94,7 @@ func (s *SnapshotStore) streamAndPublish(ctx context.Context, writer writers.Wri } // TODO: Create an actual iterator over the files that is passed to the writer. - if _, err := writer.Write(ctx, iterator.Once(messages)); err != nil { + if _, err = writer.Write(ctx, iterator.Once(messages)); err != nil { return fmt.Errorf("failed to publish messages: %w", err) }