dependabot[bot] 8787854b42
Bump github.com/unistack-org/micro/v3 from 3.2.22 to 3.7.8
Bumps [github.com/unistack-org/micro/v3](https://github.com/unistack-org/micro) from 3.2.22 to 3.7.8.
- [Release notes](https://github.com/unistack-org/micro/releases)
- [Commits](https://github.com/unistack-org/micro/compare/v3.2.22...v3.7.8)

---
updated-dependencies:
- dependency-name: github.com/unistack-org/micro/v3
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-01 18:19:39 +00:00
2021-01-29 22:21:37 +03:00
2021-01-29 22:21:37 +03:00
2021-03-15 15:49:54 +03:00
2021-03-15 15:49:54 +03:00

micro-wrapper-sqlpackage postgres

Example for For postgres

import (
	"fmt"
	"net/url"
	"time"

	"github.com/jackc/pgx/v4"
	"github.com/jackc/pgx/v4/stdlib"
	"github.com/jmoiron/sqlx"
)

func Connect(cfg *PostgresConfig) (*sqlx.DB, error) {
	// format connection string
	dbstr := fmt.Sprintf(
		"postgres://%s:%s@%s/%s?sslmode=disable&statement_cache_mode=describe",
		cfg.Login,
		url.QueryEscape(cfg.Passw),
		cfg.Addr,
		cfg.DBName,
	)

	// parse connection string
	dbConf, err := pgx.ParseConfig(dbstr)
	if err != nil {
		return nil, err
	}

	// needed for pgbouncer
	dbConf.RuntimeParams = map[string]string{
		"standard_conforming_strings": "on",
		"application_name":            cfg.AppName,
	}
	// may be needed for pbbouncer, needs to check
	//dbConf.PreferSimpleProtocol = true
	// register pgx conn
	connStr := stdlib.RegisterConnConfig(dbConf)

	db, err := sqlx.Connect("pgx", connStr)
	if err != nil {
		return nil, err
	}
	db.SetMaxOpenConns(int(cfg.ConnMax))
	db.SetMaxIdleConns(int(cfg.ConnMax / 2))
	db.SetConnMaxLifetime(time.Duration(cfg.ConnLifetime) * time.Second)
	db.SetConnMaxIdleTime(time.Duration(cfg.ConnMaxIdleTime) * time.Second)
	return db, nil
}
Description
No description provided
Readme
v3.10.15 Latest
2024-12-12 01:57:41 +03:00
Languages
Go 100%