Skip to content

db: small improvements

Compare
Choose a tag to compare
@j4k4 j4k4 released this 25 Jun 06:20
· 37 commits to main since this release

This release adds several small improvements to the db package:

Sqler and ExecMultiInTx

We added a convenient function to execute multiple sql statements in one transaction:

sqls := []db.Sqler{
	squirrel.Update("`schemas`").Set("is_default", false),
	squirrel.Insert("`schemas`").Options("IGNORE").Columns("name", "is_default").Values(name, true),
	squirrel.Update("`schemas`").Set("is_default", true).Where(squirrel.Eq{"name": name}),
}

if _, err = client.ExecMultiInTx(ctx, sqls...); err != nil {
	return fmt.Errorf("can not execute queries: %w", err)
}

MySQL logging

We've added the gosoline logger to the MySQL driver so that critical errors get not printed to os.Stderr but instead getting logged as an error.

Settings

We've added a couple of settings for the db connection. The following yaml shows how to set them. The example shows the default values:

db:
  default:
    charset: utf8mb4
    collation: utf8mb4_general_ci
    connection_max_idletime: 120s
    timeouts:
      readTimeout: 0
      writeTimeout: 0
      timeout: 0 # 0 means that the os default will get used