Skip to content

crypto-bundle/bc-wallet-common-lib-postgres

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bc-wallet-common-lib-postgres

Description

Library for manage postgresql config and connection.

Library contains:

  • common postgresql config struct
  • connection manager
  • small function-helpers for work with transaction statement

Usage example

Examples of create connection and write database communication code

Config and connection

package main

import (
	commonEnvConfig "github.com/crypto-bundle/bc-wallet-common-lib-configs/pkg/envconfig"
    commonPostgres "github.com/crypto-bundle/bc-wallet-common-lib-postgres/pkg/postgres"
	commonVault "github.com/crypto-bundle/bc-wallet-common-lib-vault/pkg/vault"
	commonVaultTokenClient "github.com/crypto-bundle/bc-wallet-common-lib-vault/pkg/vault/client/token"
)

type VaultWrappedConfig struct {
	*commonVault.BaseConfig
	*commonVaultTokenClient.AuthConfig
}

func main() {
	// vault prepare 
	vaultSrv, err := commonVault.NewService(ctx, vaultCfg, vaultClientSrv)
	if err != nil {
		panic(err)
	}

	_, err = vaultSrv.Login(ctx)
	if err != nil {
		panic(err)
	}

	pgConfig := commonPostgres.PostgresConfig{}
	pgCfgPreparerSrv := commonEnvConfig.NewConfigManager()
	err = pgCfgPreparerSrv.PrepareTo(pgConfig).With(vaultSrv).Do(ctx)
	if err != nil {
		panic(err)
	}

	pgConn := commonPostgres.NewConnection(context.Background(), pgConfig, loggerSvc)
	_, err = pgConn.Connect()
	if err != nil {
		panic(err)
	}
}

Contributors

Licence

bc-wallet-common-lib-postgres is licensed under the MIT License.