Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor
  • Loading branch information
psuresh309 committed Jan 21, 2020
commit dd4fc5d0e182ede2aefcef6d3bd5a56344a0c37e
16 changes: 6 additions & 10 deletions database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,8 @@ func (p *Postgres) Open(url string) (database.Driver, error) {

migrationsTable := purl.Query().Get("x-migrations-table")
statementTimeoutString := purl.Query().Get("x-statement-timeout")
var statementTimeout int
if statementTimeoutString == "" {
statementTimeout = 0
} else {
statementTimeout := 0
if statementTimeoutString != "" {
statementTimeout, err = strconv.Atoi(statementTimeoutString)
if err != nil {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhui wondering if we should throw a custom error here instead of the Atoi one, thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'd lose information w/ a custom error, so it'd be cleaner to wrap the error using multierror.

Expand Down Expand Up @@ -200,12 +198,10 @@ func (p *Postgres) Run(migration io.Reader) error {
if err != nil {
return err
}
var ctx context.Context
var cancel context.CancelFunc
if p.config.StatementTimeout == 0 {
ctx = context.Background()
} else {
ctx, cancel = context.WithTimeout(context.Background(), p.config.StatementTimeout)
ctx := context.Background()
if p.config.StatementTimeout != 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, p.config.StatementTimeout)
defer cancel()
}
// run migration
Expand Down