Documentation
¶
Index ¶
- Variables
- func EscapeIdentifier(valueToEscape string) string
- func GenerateCreateTableSQL(tables map[string]*TableInfo) string
- func OnModuleHashMismatchNames() []string
- func RegisterMetrics()
- func TestSinglePrimaryKeyTables(schema string) map[string]*TableInfo
- func TestTables(schema string, customTable map[string]*TableInfo) map[string]*TableInfo
- type ClickhouseDialect
- func (d ClickhouseDialect) AllowPkDuplicates() bool
- func (d ClickhouseDialect) CreateUser(tx Tx, ctx context.Context, l *Loader, username string, password string, ...) error
- func (d ClickhouseDialect) DriverSupportRowsAffected() bool
- func (d ClickhouseDialect) ExecuteSetupScript(ctx context.Context, l *Loader, schemaSql string) error
- func (d ClickhouseDialect) Flush(tx Tx, ctx context.Context, l *Loader, outputModuleHash string, ...) (int, error)
- func (d ClickhouseDialect) GetAllCursorsQuery(table string) string
- func (d ClickhouseDialect) GetCreateCursorQuery(schema string, withPostgraphile bool) string
- func (d ClickhouseDialect) GetCreateHistoryQuery(schema string, withPostgraphile bool) string
- func (d ClickhouseDialect) GetPrimaryKey(db *sql.DB, schemaName, tableName string) ([]string, error)
- func (d ClickhouseDialect) GetTableColumns(db *sql.DB, schemaName, tableName string) ([]*sql.ColumnType, error)
- func (d ClickhouseDialect) GetTablesInSchema(db *sql.DB, schemaName string) ([][2]string, error)
- func (d ClickhouseDialect) GetUpdateCursorQuery(table, moduleHash string, cursor *sink.Cursor, block_num uint64, ...) string
- func (d ClickhouseDialect) OnlyInserts() bool
- func (d ClickhouseDialect) ParseDatetimeNormalization(value string) string
- func (d ClickhouseDialect) Revert(tx Tx, ctx context.Context, l *Loader, lastValidFinalBlock uint64) error
- type ColumnInfo
- type DSN
- type DSNOptions
- func (v DSNOptions) Encode() string
- func (v DSNOptions) EncodeWithSeparator(sep string) string
- func (v DSNOptions) Get(key string) string
- func (v DSNOptions) GetOr(key, defaultValue string) string
- func (v DSNOptions) Iter() iter.Seq2[string, string]
- func (v DSNOptions) RemoveOr(key, defaultValue string) string
- type Dialect
- type FieldData
- type Loader
- func (l *Loader) BatchBlockFlushInterval() int
- func (l *Loader) Begin() (Tx, error)
- func (l *Loader) BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error)
- func (l *Loader) CreateUser(ctx context.Context, username string, password string, database string, ...) (err error)
- func (l *Loader) Delete(tableName string, primaryKey map[string]string, reversibleBlockNum *uint64) error
- func (l *Loader) DeleteAllCursors(ctx context.Context) (deletedCount int64, err error)
- func (l *Loader) DeleteCursor(ctx context.Context, moduleHash string) error
- func (l *Loader) Flush(ctx context.Context, outputModuleHash string, cursor *sink.Cursor, ...) (rowFlushedCount int, err error)
- func (l *Loader) FlushNeeded() bool
- func (l *Loader) GetAllCursors(ctx context.Context) (out map[string]*sink.Cursor, err error)
- func (l *Loader) GetAvailableTablesInSchema() []string
- func (l *Loader) GetColumnsForTable(name string) []string
- func (l *Loader) GetCursor(ctx context.Context, outputModuleHash string) (cursor *sink.Cursor, mismatchDetected bool, err error)
- func (l *Loader) GetDSN() *DSN
- func (l *Loader) GetIdentifier() string
- func (l *Loader) GetPrimaryKey(tableName string, pk string) (map[string]string, error)
- func (l *Loader) HasTable(tableName string) bool
- func (l *Loader) Insert(tableName string, primaryKey map[string]string, data map[string]FieldData, ...) error
- func (l *Loader) InsertCursor(ctx context.Context, moduleHash string, c *sink.Cursor) error
- func (l *Loader) LiveBlockFlushInterval() int
- func (l *Loader) LoadTables(schemaName string, cursorTableName string, historyTableName string) error
- func (l *Loader) MarshalLogObject(encoder zapcore.ObjectEncoder) error
- func (l *Loader) NextBatchOrdinal() uint64
- func (l *Loader) Revert(ctx context.Context, outputModuleHash string, cursor *sink.Cursor, ...) error
- func (l *Loader) Setup(ctx context.Context, schemaName string, userSql string, withPostgraphile bool) error
- func (l *Loader) Update(tableName string, primaryKey map[string]string, data map[string]FieldData, ...) error
- func (l *Loader) UpdateCursor(ctx context.Context, tx Tx, moduleHash string, c *sink.Cursor) error
- func (l *Loader) Upsert(tableName string, primaryKey map[string]string, data map[string]FieldData, ...) error
- type OnModuleHashMismatch
- type Operation
- type OperationType
- type OrderedMap
- type PostgresDialect
- func (d PostgresDialect) AllowPkDuplicates() bool
- func (d PostgresDialect) CreateUser(tx Tx, ctx context.Context, l *Loader, username string, password string, ...) error
- func (d PostgresDialect) DriverSupportRowsAffected() bool
- func (d PostgresDialect) ExecuteSetupScript(ctx context.Context, l *Loader, schemaSql string) error
- func (d PostgresDialect) Flush(tx Tx, ctx context.Context, l *Loader, outputModuleHash string, ...) (int, error)
- func (d PostgresDialect) GetAllCursorsQuery(table string) string
- func (d PostgresDialect) GetCreateCursorQuery(schema string, withPostgraphile bool) string
- func (d PostgresDialect) GetCreateHistoryQuery(schema string, withPostgraphile bool) string
- func (d PostgresDialect) GetPrimaryKey(db *sql.DB, schemaName, tableName string) ([]string, error)
- func (d PostgresDialect) GetTableColumns(db *sql.DB, schemaName, tableName string) ([]*sql.ColumnType, error)
- func (d PostgresDialect) GetTablesInSchema(db *sql.DB, schemaName string) ([][2]string, error)
- func (d PostgresDialect) GetUpdateCursorQuery(table, moduleHash string, cursor *sink.Cursor, block_num uint64, ...) string
- func (d PostgresDialect) OnlyInserts() bool
- func (d PostgresDialect) ParseDatetimeNormalization(value string) string
- func (d PostgresDialect) Revert(tx Tx, ctx context.Context, l *Loader, lastValidFinalBlock uint64) error
- type Queryable
- type SystemTableError
- type TableInfo
- type TestTx
- func (t *TestTx) Commit() error
- func (t *TestTx) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (t *TestTx) QueryContext(ctx context.Context, query string, args ...any) (out *sql.Rows, err error)
- func (t *TestTx) Results() []string
- func (t *TestTx) Rollback() error
- type Tx
- type TypeGetter
- type UnknownDriverError
- type UpdateOp
Constants ¶
This section is empty.
Variables ¶
var ErrCursorNotFound = errors.New("cursor not found")
var ErrInvalidOnModuleHashMismatch = fmt.Errorf("not a valid OnModuleHashMismatch, try [%s]", strings.Join(_OnModuleHashMismatchNames, ", "))
var PruneReversibleSegmentDuration = metrics.NewCounter("prune_reversible_segment_duration", "The amount of time spent pruning reversible segment in nanoseconds")
var QueryExecutionDuration = metrics.NewCounterVec("tx_query_execution_duration", []string{"query_type"}, "The amount of time spent executing queries by type (normal/undo) in nanoseconds")
Functions ¶
func EscapeIdentifier ¶
func GenerateCreateTableSQL ¶
func OnModuleHashMismatchNames ¶
func OnModuleHashMismatchNames() []string
OnModuleHashMismatchNames returns a list of possible string values of OnModuleHashMismatch.
func RegisterMetrics ¶
func RegisterMetrics()
Types ¶
type ClickhouseDialect ¶
type ClickhouseDialect struct {
// contains filtered or unexported fields
}
func NewClickhouseDialect ¶
func NewClickhouseDialect(schemaName string, cursorTableName string, cluster string) *ClickhouseDialect
func (ClickhouseDialect) AllowPkDuplicates ¶
func (d ClickhouseDialect) AllowPkDuplicates() bool
func (ClickhouseDialect) CreateUser ¶
func (ClickhouseDialect) DriverSupportRowsAffected ¶
func (d ClickhouseDialect) DriverSupportRowsAffected() bool
func (ClickhouseDialect) ExecuteSetupScript ¶
func (ClickhouseDialect) Flush ¶
func (d ClickhouseDialect) Flush(tx Tx, ctx context.Context, l *Loader, outputModuleHash string, lastFinalBlock uint64) (int, error)
Clickhouse should be used to insert a lot of data in batches. The current official clickhouse driver doesn't support Transactions for multiple tables. The only way to add in batches is creating a transaction for a table, adding all rows and commiting it.
func (ClickhouseDialect) GetAllCursorsQuery ¶
func (d ClickhouseDialect) GetAllCursorsQuery(table string) string
func (ClickhouseDialect) GetCreateCursorQuery ¶
func (d ClickhouseDialect) GetCreateCursorQuery(schema string, withPostgraphile bool) string
func (ClickhouseDialect) GetCreateHistoryQuery ¶
func (d ClickhouseDialect) GetCreateHistoryQuery(schema string, withPostgraphile bool) string
func (ClickhouseDialect) GetPrimaryKey ¶
func (ClickhouseDialect) GetTableColumns ¶
func (d ClickhouseDialect) GetTableColumns(db *sql.DB, schemaName, tableName string) ([]*sql.ColumnType, error)
func (ClickhouseDialect) GetTablesInSchema ¶
func (ClickhouseDialect) GetUpdateCursorQuery ¶
func (ClickhouseDialect) OnlyInserts ¶
func (d ClickhouseDialect) OnlyInserts() bool
func (ClickhouseDialect) ParseDatetimeNormalization ¶
func (d ClickhouseDialect) ParseDatetimeNormalization(value string) string
type ColumnInfo ¶
type ColumnInfo struct {
// contains filtered or unexported fields
}
func NewColumnInfo ¶
func NewColumnInfo(name string, databaseTypeName string, scanType any) *ColumnInfo
type DSN ¶
type DSN struct {
Host string
Port int64
Username string
Password string
Database string
Options DSNOptions
// contains filtered or unexported fields
}
func (*DSN) ConnString ¶
type DSNOptions ¶
DSNOptions is a thin wrapper around url.Values to provide helper methods and better names.
func (DSNOptions) Encode ¶
func (v DSNOptions) Encode() string
Encode encodes the values into “URL encoded” form ("bar=baz&foo=quux") sorted by key.
func (DSNOptions) EncodeWithSeparator ¶
func (v DSNOptions) EncodeWithSeparator(sep string) string
EncodeWithSeparator encodes the values into “URL encoded” like form ("bar=baz foo=quux") sorted by key where essentially the separator is used instead of '&'.
func (DSNOptions) Get ¶
func (v DSNOptions) Get(key string) string
Get returns the value associated with the key.
func (DSNOptions) GetOr ¶
func (v DSNOptions) GetOr(key, defaultValue string) string
GetOr returns the value associated with the key or defaultValue if not found.
func (DSNOptions) Iter ¶
func (v DSNOptions) Iter() iter.Seq2[string, string]
Iterate over the first value of each key, to be used in for range loops.
func (DSNOptions) RemoveOr ¶
func (v DSNOptions) RemoveOr(key, defaultValue string) string
RemoveOr removes the key from the options and returns its value or defaultValue if not found.
type Dialect ¶
type Dialect interface {
GetCreateCursorQuery(schema string, withPostgraphile bool) string
GetCreateHistoryQuery(schema string, withPostgraphile bool) string
ExecuteSetupScript(ctx context.Context, l *Loader, schemaSql string) error
DriverSupportRowsAffected() bool
GetUpdateCursorQuery(table, moduleHash string, cursor *sink.Cursor, block_num uint64, block_id string) string
GetAllCursorsQuery(table string) string
ParseDatetimeNormalization(value string) string
Flush(tx Tx, ctx context.Context, l *Loader, outputModuleHash string, lastFinalBlock uint64) (int, error)
Revert(tx Tx, ctx context.Context, l *Loader, lastValidFinalBlock uint64) error
OnlyInserts() bool
AllowPkDuplicates() bool
CreateUser(tx Tx, ctx context.Context, l *Loader, username string, password string, database string, readOnly bool) error
GetTableColumns(db *sql.DB, schemaName, tableName string) ([]*sql.ColumnType, error)
GetPrimaryKey(db *sql.DB, schemaName, tableName string) ([]string, error)
GetTablesInSchema(db *sql.DB, schemaName string) ([][2]string, error)
}
type Loader ¶
func NewTestLoader ¶
func (*Loader) BatchBlockFlushInterval ¶
func (*Loader) CreateUser ¶
func (*Loader) Delete ¶
func (l *Loader) Delete(tableName string, primaryKey map[string]string, reversibleBlockNum *uint64) error
Delete a row in the DB, it is assumed the table exists, you can do a check before with HasTable()
func (*Loader) DeleteAllCursors ¶
DeleteAllCursors deletes the active cursor for the given 'moduleHash'. If no cursor is active and no delete occurrred, returns ErrCursorNotFound. If the delete was not successful on the database, returns an error.
func (*Loader) DeleteCursor ¶
DeleteCursor deletes the active cursor for the given 'moduleHash'. If no cursor is active and no delete occurrred, returns ErrCursorNotFound. If the delete was not successful on the database, returns an error.
func (*Loader) FlushNeeded ¶
func (*Loader) GetAllCursors ¶
GetAllCursors returns an unordered map given for each module's hash recorded the active cursor for it.
func (*Loader) GetAvailableTablesInSchema ¶
func (*Loader) GetColumnsForTable ¶
func (*Loader) GetIdentifier ¶
GetIdentifier returns <database>/<schema> suitable for user presentation
func (*Loader) GetPrimaryKey ¶
func (*Loader) Insert ¶
func (l *Loader) Insert(tableName string, primaryKey map[string]string, data map[string]FieldData, reversibleBlockNum *uint64) error
Insert a row in the DB, it is assumed the table exists, you can do a check before with HasTable()
func (*Loader) InsertCursor ¶
func (*Loader) LiveBlockFlushInterval ¶
func (*Loader) LoadTables ¶
func (*Loader) MarshalLogObject ¶
func (l *Loader) MarshalLogObject(encoder zapcore.ObjectEncoder) error
func (*Loader) NextBatchOrdinal ¶
NextBatchOrdinal returns the next ordinal for the current batch and increments the counter
func (*Loader) Setup ¶
func (l *Loader) Setup(ctx context.Context, schemaName string, userSql string, withPostgraphile bool) error
Setup creates the schemaName, cursors and history table where the <schemaBytes> is a byte array taken from somewhere.
func (*Loader) Update ¶
func (l *Loader) Update(tableName string, primaryKey map[string]string, data map[string]FieldData, reversibleBlockNum *uint64) error
Update a row in the DB, it is assumed the table exists, you can do a check before with HasTable()
func (*Loader) UpdateCursor ¶
UpdateCursor updates the active cursor. If no cursor is active and no update occurred, returns ErrCursorNotFound. If the update was not successful on the database, returns an error. You can use tx=nil to run the query outside of a transaction.
type OnModuleHashMismatch ¶
type OnModuleHashMismatch uint
ENUM(
Ignore Warn Error
)
const ( // OnModuleHashMismatchIgnore is a OnModuleHashMismatch of type Ignore. OnModuleHashMismatchIgnore OnModuleHashMismatch = iota // OnModuleHashMismatchWarn is a OnModuleHashMismatch of type Warn. OnModuleHashMismatchWarn // OnModuleHashMismatchError is a OnModuleHashMismatch of type Error. OnModuleHashMismatchError )
func ParseOnModuleHashMismatch ¶
func ParseOnModuleHashMismatch(name string) (OnModuleHashMismatch, error)
ParseOnModuleHashMismatch attempts to convert a string to a OnModuleHashMismatch.
func (OnModuleHashMismatch) IsValid ¶
func (x OnModuleHashMismatch) IsValid() bool
IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values
func (OnModuleHashMismatch) MarshalText ¶
func (x OnModuleHashMismatch) MarshalText() ([]byte, error)
MarshalText implements the text marshaller method.
func (OnModuleHashMismatch) String ¶
func (x OnModuleHashMismatch) String() string
String implements the Stringer interface.
func (*OnModuleHashMismatch) UnmarshalText ¶
func (x *OnModuleHashMismatch) UnmarshalText(text []byte) error
UnmarshalText implements the text unmarshaller method.
type OperationType ¶
type OperationType string
const ( OperationTypeInsert OperationType = "INSERT" OperationTypeUpsert OperationType = "UPSERT" OperationTypeUpdate OperationType = "UPDATE" OperationTypeDelete OperationType = "DELETE" )
type OrderedMap ¶
type OrderedMap[K comparable, V any] struct { *orderedmap.OrderedMap[K, V] }
Make the typing a bit easier
func NewOrderedMap ¶
func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V]
type PostgresDialect ¶
type PostgresDialect struct {
// contains filtered or unexported fields
}
func NewPostgresDialect ¶
func NewPostgresDialect(schemaName string, cursorTableName string, historyTableName string) *PostgresDialect
func (PostgresDialect) AllowPkDuplicates ¶
func (d PostgresDialect) AllowPkDuplicates() bool
func (PostgresDialect) CreateUser ¶
func (PostgresDialect) DriverSupportRowsAffected ¶
func (d PostgresDialect) DriverSupportRowsAffected() bool
func (PostgresDialect) ExecuteSetupScript ¶
func (PostgresDialect) GetAllCursorsQuery ¶
func (d PostgresDialect) GetAllCursorsQuery(table string) string
func (PostgresDialect) GetCreateCursorQuery ¶
func (d PostgresDialect) GetCreateCursorQuery(schema string, withPostgraphile bool) string
func (PostgresDialect) GetCreateHistoryQuery ¶
func (d PostgresDialect) GetCreateHistoryQuery(schema string, withPostgraphile bool) string
func (PostgresDialect) GetPrimaryKey ¶
func (PostgresDialect) GetTableColumns ¶
func (d PostgresDialect) GetTableColumns(db *sql.DB, schemaName, tableName string) ([]*sql.ColumnType, error)
func (PostgresDialect) GetTablesInSchema ¶
func (PostgresDialect) GetUpdateCursorQuery ¶
func (PostgresDialect) OnlyInserts ¶
func (d PostgresDialect) OnlyInserts() bool
func (PostgresDialect) ParseDatetimeNormalization ¶
func (d PostgresDialect) ParseDatetimeNormalization(value string) string
type SystemTableError ¶
type SystemTableError struct {
// contains filtered or unexported fields
}
type TableInfo ¶
type TableInfo struct {
// contains filtered or unexported fields
}
func NewTableInfo ¶
type TestTx ¶
type TestTx struct {
// contains filtered or unexported fields
}
func (*TestTx) ExecContext ¶
func (*TestTx) QueryContext ¶
type UnknownDriverError ¶
type UnknownDriverError struct {
Driver string
}
func (UnknownDriverError) Error ¶
func (e UnknownDriverError) Error() string
Error returns a formatted string description.
type UpdateOp ¶
type UpdateOp int32
UpdateOp defines the operation to apply when updating a field on conflict
const ( UpdateOpSet UpdateOp = 0 // Direct assignment: col = value UpdateOpAdd UpdateOp = 1 // Accumulate: col = COALESCE(col, 0) + value UpdateOpMax UpdateOp = 2 // Maximum: col = GREATEST(COALESCE(col, 0), value) UpdateOpMin UpdateOp = 3 // Minimum: col = LEAST(COALESCE(col, 0), value) UpdateOpSetIfNull UpdateOp = 4 // Set only if NULL: col = COALESCE(col, value) )