oraconn

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2016 License: Apache-2.0 Imports: 8 Imported by: 4

README

Oraconn - Oracle Connection Utilities

CircleCI

This package provide a simple mechanism to extend the Oracle sql.DB implementation with some additional capabilities:

  • The ability to retry initial connection attempts using a simple backoff mechanism. This is useful in scenarios such as starting containerized applications without wanting to worry about start up order.
  • Detecting certain classes of connection related errors.
  • Reconnecting to the database using retrys and backoff.

Usage

  • Use the OpenAndConnect method to instantiate a *sql.DB instance.
  • Use IsConnectionError to determine if the error indicates the connection to the database is lost or hopeless, in which Reconnect should be used to reconnect to the database.

Dependencies

go get github.com/rjeczalik/pkgconfig/cmd/pkg-config
go get github.com/mattn/go-oci8
go get github.com/gucumber/gucumber/cmd/gucumber
go get github.com/stretchr/testify/assert
go get github.com/Sirupsen/logrus

Contributing

To contribute, you must certify you agree with the Developer Certificate of Origin by signing your commits via git -s. To create a signature, configure your user name and email address in git. Sign with your real name, do not use pseudonyms or submit anonymous commits.

In terms of workflow:

  1. For significant changes or improvement, create an issue before commencing work.
  2. Fork the respository, and create a branch for your edits.
  3. Add tests that cover your changes, unit tests for smaller changes, acceptance test for more significant functionality.
  4. Run gofmt on each file you change before committing your changes.
  5. Run golint on each file you change before committing your changes.
  6. Make sure all the tests pass before committing your changes.
  7. Commit your changes and issue a pull request.

License

(c) 2016 Fidelity Investments Licensed under the Apache License, Version 2.0

Documentation

Index

Constants

View Source
const (
	DBUser     = "DB_USER"
	DBPassword = "DB_PASSWORD"
	DBHost     = "DB_HOST"
	DBPort     = "DB_PORT"
	DBSvc      = "DB_SVC"
)

Variables

View Source
var ErrRetryCount = errors.New("Retry count must be greater than 1")

ErrRetryCount is used to indicate invalid retry count values passed to OpenAndConnect.

Functions

func BuildConnectString

func BuildConnectString(user, password, host, port, service string) string

BuildConnectString builds an Oracle connect string from its constituent parts.

func IsConnectionError

func IsConnectionError(err error) bool

IsConnectionError returns error if the argument is a connection error

Types

type EnvConfig

type EnvConfig struct {
	DBUser     string
	DBPassword string
	DBHost     string
	DBPort     string
	DBSvc      string
}

func NewEnvConfig

func NewEnvConfig() (*EnvConfig, error)

func (*EnvConfig) ConnectString

func (ec *EnvConfig) ConnectString() string

func (*EnvConfig) MaskedConnectString

func (ec *EnvConfig) MaskedConnectString() string

type OracleDB

type OracleDB struct {
	*sql.DB
	// contains filtered or unexported fields
}

OracleDB embeds sql.DB and extends it with the ability to retry connecting to the database when errors occur, detecting certain disconnections, and reconnecting to the database.

func OpenAndConnect

func OpenAndConnect(connectString string, retryCount int) (*OracleDB, error)

OpenAndConnect attempts to open a connection to Oracle as specified in the provided connection string. The connection is considered open when Ping returns with a nil error. The connection Ping is is tried the number of times indicated by the retry count, with a sleep delay of the current attempt in seconds, i.e. 1s, 2s, 3s ... retryCount

func (*OracleDB) Reconnect

func (odb *OracleDB) Reconnect(retryCount int) error

Reconnect to the database. Useful when a loss of connection has been detected

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL