Documentation ¶
Index ¶
- Constants
- func IsConstraintViolation(err error) bool
- func MapSQLError(ctx context.Context, err error, resourceType resource.Type, ...) error
- func SaveToContext(ctx context.Context, persistOp PersistenceOp) context.Context
- type DatabaseConfig
- type PersistenceOp
- type PersistenceTx
- type Transaction
- type Transactioner
Constants ¶
View Source
const ( // PersistenceCtxKey is a key used in context to store the persistence object PersistenceCtxKey persistenceCtxKey = "PersistenceCtx" // NotNullViolation is an error code that happens when the required data is not provided NotNullViolation pq.ErrorCode = "23502" // UniqueViolation is an error code that happens when the Unique Key is violated UniqueViolation pq.ErrorCode = "23505" // ForeignKeyViolation is an error code that happens when try to delete a row from the referenced/parent table when referencing/child table reference that row in the parent table // or when create/update a row in the child table with reference to the parent that does not exists ForeignKeyViolation pq.ErrorCode = "23503" // CheckViolation is an error code that happens when the values in a column do not meet a specific requirement defined by CHECK conditions CheckViolation pq.ErrorCode = "23514" // ConstraintViolation is the class of errors that happens when any constraint is violated ConstraintViolation pq.ErrorClass = "23" // NoData missing godoc NoData pq.ErrorClass = "02" )
View Source
const RetryCount int = 50
RetryCount is a number of retries when trying to open the database
Variables ¶
This section is empty.
Functions ¶
func IsConstraintViolation ¶
IsConstraintViolation missing godoc
func MapSQLError ¶
func MapSQLError(ctx context.Context, err error, resourceType resource.Type, sqlOperation resource.SQLOperation, format string, args ...interface{}) error
MapSQLError missing godoc
func SaveToContext ¶
func SaveToContext(ctx context.Context, persistOp PersistenceOp) context.Context
SaveToContext missing godoc
Types ¶
type DatabaseConfig ¶
type DatabaseConfig struct { User string `envconfig:"default=postgres,APP_DB_USER"` Password string `envconfig:"default=pgsql@12345,APP_DB_PASSWORD"` Host string `envconfig:"default=localhost,APP_DB_HOST"` Port string `envconfig:"default=5432,APP_DB_PORT"` Name string `envconfig:"default=compass,APP_DB_NAME"` SSLMode string `envconfig:"default=disable,APP_DB_SSL"` MaxOpenConnections int `envconfig:"default=5,APP_DB_MAX_OPEN_CONNECTIONS"` MaxIdleConnections int `envconfig:"default=5,APP_DB_MAX_IDLE_CONNECTIONS"` ConnMaxLifetime time.Duration `envconfig:"default=30m,APP_DB_CONNECTION_MAX_LIFETIME"` }
DatabaseConfig missing godoc
func (DatabaseConfig) GetConnString ¶
func (cfg DatabaseConfig) GetConnString() string
GetConnString missing godoc
type PersistenceOp ¶
type PersistenceOp interface { GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) }
PersistenceOp missing godoc
type PersistenceTx ¶
type PersistenceTx interface { Commit() error Rollback() error PersistenceOp }
PersistenceTx missing godoc
type Transaction ¶
Transaction missing godoc
type Transactioner ¶
type Transactioner interface { Begin() (PersistenceTx, error) RollbackUnlessCommitted(ctx context.Context, tx PersistenceTx) (didRollback bool) PingContext(ctx context.Context) error Stats() sql.DBStats }
Transactioner missing godoc
func Configure ¶
func Configure(context context.Context, conf DatabaseConfig) (Transactioner, func() error, error)
Configure returns the instance of the database
Source Files ¶
Click to show internal directories.
Click to hide internal directories.