func New(ctx context.Context, params ...Parameter) (*Service, error) {
	parameters, err := parseAndCheckParameters(params...)
	if err != nil {
		return nil, errors.Wrap(err, "problem with parameters")
	}
	log = zerologger.With().Str("service", "chaindb").Str("impl", "postgresql").Logger().Level(parameters.logLevel)
	var pool *pgxpool.Pool
	if parameters.connectionURL != "" {
		pool, err = pgxpool.Connect(context.Background(), parameters.connectionURL)
		if err != nil {
			return nil, errors.Wrap(err, "failed to connect to database")
		}
	} else {
		dsnItems := make([]string, 0, 16)
		dsnItems = append(dsnItems, fmt.Sprintf("host=%s", parameters.server))
		dsnItems = append(dsnItems, fmt.Sprintf("user=%s", parameters.user))
		if parameters.password != "" {
			dsnItems = append(dsnItems, fmt.Sprintf("password=%s", parameters.password))
		}
		dsnItems = append(dsnItems, fmt.Sprintf("port=%d", parameters.port))
		var tlsConfig *tls.Config
		if parameters.caCert != nil || parameters.clientCert != nil {
			dsnItems = append(dsnItems, "sslmode=verify-full")
			tlsConfig = &tls.Config{
				ServerName: parameters.server,
				MinVersion: tls.VersionTLS13,
			}
			if parameters.clientCert != nil {
				clientPair, err := tls.X509KeyPair(parameters.clientCert, parameters.clientKey)
				if err != nil {
					return nil, errors.Wrap(err, "failed to create client certificate")
				}
				tlsConfig.Certificates = []tls.Certificate{clientPair}
			}
			if parameters.caCert != nil {
				rootCAs := x509.NewCertPool()
				if !rootCAs.AppendCertsFromPEM(parameters.caCert) {
					return nil, errors.New("failed to append root CA certificates")
				}
				tlsConfig.RootCAs = rootCAs
			}
		}
		config, err := pgxpool.ParseConfig(strings.Join(dsnItems, " "))
		if err != nil {
			return nil, errors.Wrap(err, "failed to generate pgx config")
		}
		config.AfterConnect = registerCustomTypes
		config.ConnConfig.TLSConfig = tlsConfig
		pool, err = pgxpool.ConnectConfig(context.Background(), config)
		if err != nil {
			return nil, errors.Wrap(err, "failed to connect to database")
		}
	}
	go func() {
		<-ctx.Done()
		log.Trace().Msg("Context done; closing pool")
		pool.Close()
	}()
	s := &Service{
		pool: pool,
	}
	return s, nil
}
New creates a new service.
package postgresql
import (
	"context"
	"crypto/tls"
	"crypto/x509"
	"fmt"
	"strings"
	"github.com/jackc/pgtype"
	shopspring "github.com/jackc/pgtype/ext/shopspring-numeric"
	"github.com/jackc/pgx/v4"
	"github.com/jackc/pgx/v4/pgxpool"
	"github.com/pkg/errors"
	"github.com/rs/zerolog"
	zerologger "github.com/rs/zerolog/log"
)
type Service struct {
	pool *pgxpool.Pool
}
var log zerolog.Logger