Skip to content

Commit

Permalink
PR review: add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vroldanbet committed Oct 3, 2023
1 parent b28abf1 commit 9d27265
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/datastore/postgres/common/pgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func ConfigurePGXLogger(connConfig *pgx.ConnConfig) {
addTracer(connConfig, &tracelog.TraceLog{Logger: levelMappingFn(l), LogLevel: tracelog.LogLevelInfo})
}

// truncateLargeSQL takes arguments of a SQL statement provided via pgx's tracelog.LoggerFunc and
// truncates SQL statements and SQL arguments to placeholders that exceed a certain length. This helps
// de-clutter logs when statements have hundreds to thousands of placeholders. The change is done in place.
func truncateLargeSQL(data map[string]any) {
const (
maxSQLLen = 350
Expand All @@ -127,6 +130,7 @@ func truncateLargeSQL(data map[string]any) {
}
}

// IsCancellationError determines if an error returned by pgx has been caused by context cancellation.
func IsCancellationError(err error) bool {
if errors.Is(err, context.Canceled) ||
errors.Is(err, context.DeadlineExceeded) ||
Expand Down

0 comments on commit 9d27265

Please sign in to comment.