// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: event_consumer.sql package sqlc import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const insertConsumerDeadLetter = `-- name: InsertConsumerDeadLetter :exec INSERT INTO consumer_dead_letters ( consumer_name, topic, kafka_partition, kafka_offset, event_id, event_type, error_class, reason, attempts, value_size, value_sha256 ) VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11 ) ON CONFLICT ( consumer_name, topic, kafka_partition, kafka_offset, value_sha256 ) DO UPDATE SET event_id = excluded.event_id, event_type = excluded.event_type, error_class = excluded.error_class, reason = excluded.reason, attempts = excluded.attempts, dead_lettered_at = clock_timestamp() ` type InsertConsumerDeadLetterParams struct { ConsumerName string Topic string KafkaPartition int32 KafkaOffset int64 EventID pgtype.UUID EventType pgtype.Text ErrorClass string Reason string Attempts int32 ValueSize int32 ValueSha256 []byte } // Stores a record that a consumer could not apply. A second delivery of the // same record (same position and value) refreshes the outcome of its row: // after a rewind the handler may fail differently. A different value at a // reused position, after the topic was recreated, gets its own row. func (q *Queries) InsertConsumerDeadLetter(ctx context.Context, arg InsertConsumerDeadLetterParams) error { _, err := q.db.Exec(ctx, insertConsumerDeadLetter, arg.ConsumerName, arg.Topic, arg.KafkaPartition, arg.KafkaOffset, arg.EventID, arg.EventType, arg.ErrorClass, arg.Reason, arg.Attempts, arg.ValueSize, arg.ValueSha256, ) return err } const insertProcessedEventMarker = `-- name: InsertProcessedEventMarker :execrows INSERT INTO consumer_processed_events (consumer_name, event_id) VALUES ($1, $2) ON CONFLICT (consumer_name, event_id) DO NOTHING ` type InsertProcessedEventMarkerParams struct { ConsumerName string EventID pgtype.UUID } // Records that a consumer applies an event, in the transaction of the effect. // It returns 0 rows when the marker exists. While another transaction holds // an uncommitted marker for the same key, the insert waits for it: after a // commit it returns 0, after a rollback it inserts. So a concurrent duplicate // never runs the effect at the same time as the first delivery. func (q *Queries) InsertProcessedEventMarker(ctx context.Context, arg InsertProcessedEventMarkerParams) (int64, error) { result, err := q.db.Exec(ctx, insertProcessedEventMarker, arg.ConsumerName, arg.EventID) if err != nil { return 0, err } return result.RowsAffected(), nil } const setConsumerTransactionTimeouts = `-- name: SetConsumerTransactionTimeouts :exec SELECT set_config('statement_timeout', $1::text, true), set_config( 'idle_in_transaction_session_timeout', $2::text, true ) ` type SetConsumerTransactionTimeoutsParams struct { StatementTimeoutMs string IdleTimeoutMs string } // Bounds a consumer transaction on the server, local to the transaction. // statement_timeout stops a slow statement; idle_in_transaction_session_timeout // ends the session of a process that froze or lost the network inside the // handler, which releases the processed-event marker that a concurrent // duplicate waits for. func (q *Queries) SetConsumerTransactionTimeouts(ctx context.Context, arg SetConsumerTransactionTimeoutsParams) error { _, err := q.db.Exec(ctx, setConsumerTransactionTimeouts, arg.StatementTimeoutMs, arg.IdleTimeoutMs) return err }