Skip to content

Commit

Permalink
Add log_queries key to config
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Jul 17, 2023
1 parent 100ee14 commit f1527f7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions configs/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ storage:
password: ${POSTGRES_PASSWORD}
sslmode: disable
timeout: 10
log_queries: ${POSTGRES_LOG_QUERIES:-false}

sentry:
environment: development
Expand Down
1 change: 1 addition & 0 deletions configs/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ storage:
password: ${POSTGRES_PASSWORD}
sslmode: disable
timeout: 10
log_queries: ${POSTGRES_LOG_QUERIES:-false}

sentry:
environment: production
Expand Down
5 changes: 3 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ type ServiceConfig struct {

// StorageConfig -
type StorageConfig struct {
Postgres PostgresConfig `yaml:"pg"`
Timeout int `yaml:"timeout"`
Postgres PostgresConfig `yaml:"pg"`
Timeout int `yaml:"timeout"`
LogQueries bool `yaml:"log_queries,omitempty"`
}

// PostgresConfig -
Expand Down
14 changes: 10 additions & 4 deletions internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,19 @@ func WithStorage(cfg StorageConfig, appName string, maxPageSize int64, maxConnCo
panic("Please set connection strings to storage in config")
}

conn := pgCore.WaitNew(
cfg.Postgres.ConnectionString(), ctx.Network.String(),
appName, cfg.Timeout,
opts := []pgCore.PostgresOption{
pgCore.WithPageSize(maxPageSize),
pgCore.WithIdleConnections(idleConnCount),
pgCore.WithMaxConnections(maxConnCount),
pgCore.WithQueryLogging(),
}

if cfg.LogQueries {
opts = append(opts, pgCore.WithQueryLogging())
}

conn := pgCore.WaitNew(
cfg.Postgres.ConnectionString(), ctx.Network.String(),
appName, cfg.Timeout, opts...,
)

contractStorage := contract.NewStorage(conn)
Expand Down

0 comments on commit f1527f7

Please sign in to comment.