orm

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2021 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorNotFound is returned when finding a single value fails.
	ErrorNotFound = gorm.ErrRecordNotFound
	// ErrNoAdvisoryLock is returned when an advisory lock can't be acquired.
	ErrNoAdvisoryLock = errors.New("can't acquire advisory lock")
	// ErrReleaseLockFailed  is returned when releasing the advisory lock fails.
	ErrReleaseLockFailed = errors.New("advisory lock release failed")
	// ErrOptimisticUpdateConflict is returned when a record update failed
	// because another update occurred while the model was in memory and the
	// differences must be reconciled.
	ErrOptimisticUpdateConflict = errors.New("conflict while updating record")
)

Functions

func NewOrmLogWrapper added in v0.10.11

func NewOrmLogWrapper(logger *logger.Logger, logAllQueries bool, slowThreshold time.Duration) *ormLogWrapper

FIXME: This is a GORM log wrapper, not a ORM log wrapper so it probably belongs in a different package

Types

type Connection added in v0.8.5

type Connection struct {
	// contains filtered or unexported fields
}

Connection manages all of the possible database connection setup and config.

func NewConnection added in v0.8.5

func NewConnection(dialect dialects.DialectName, uri string, advisoryLockID int64, lockRetryInterval time.Duration, maxOpenConns, maxIdleConns int) (Connection, error)

NewConnection returns a Connection which holds all of the configuration necessary for managing the database connection.

type LockingStrategy

type LockingStrategy interface {
	Lock(timeout models.Duration) error
	Unlock(timeout models.Duration) error
}

LockingStrategy employs the locking and unlocking of an underlying resource for exclusive access, usually a file or database.

func NewLockingStrategy

func NewLockingStrategy(ct Connection) (LockingStrategy, error)

NewLockingStrategy returns the locking strategy for a particular dialect to ensure exlusive access to the orm.

func NewPostgresLockingStrategy

func NewPostgresLockingStrategy(ct Connection) (LockingStrategy, error)

NewPostgresLockingStrategy returns a new instance of the PostgresLockingStrategy.

type ORM

type ORM struct {
	DB *gorm.DB
	// contains filtered or unexported fields
}

ORM contains the database object used by Chainlink.

func NewORM

func NewORM(uri string, timeout models.Duration, shutdownSignal gracefulpanic.Signal, dialect dialects.DialectName, advisoryLockID int64, lockRetryInterval time.Duration, maxOpenConns, maxIdleConns int) (*ORM, error)

NewORM initializes the orm with the configured uri

func (*ORM) AuthorizedUserWithSession

func (orm *ORM) AuthorizedUserWithSession(sessionID string, sessionDuration time.Duration) (models.User, error)

AuthorizedUserWithSession will return the one API user if the Session ID exists and hasn't expired, and update session's LastUsed field.

func (*ORM) BridgeTypes

func (orm *ORM) BridgeTypes(offset int, limit int) ([]models.BridgeType, int, error)

BridgeTypes returns bridge types ordered by name filtered limited by the passed params.

func (*ORM) ClearNonCurrentSessions

func (orm *ORM) ClearNonCurrentSessions(sessionID string) error

ClearNonCurrentSessions removes all sessions but the id passed in.

func (*ORM) Close

func (orm *ORM) Close() error

Close closes the underlying database connection.

func (*ORM) CountOf added in v0.8.2

func (orm *ORM) CountOf(t interface{}) (int, error)

func (*ORM) CreateBridgeType

func (orm *ORM) CreateBridgeType(bt *models.BridgeType) error

CreateBridgeType saves the bridge type.

func (*ORM) CreateExternalInitiator

func (orm *ORM) CreateExternalInitiator(externalInitiator *models.ExternalInitiator) error

CreateExternalInitiator inserts a new external initiator

func (*ORM) CreateSession

func (orm *ORM) CreateSession(sr models.SessionRequest) (string, error)

CreateSession will check the password in the SessionRequest against the hashed API User password in the db.

func (*ORM) DeleteBridgeType

func (orm *ORM) DeleteBridgeType(bt *models.BridgeType) error

DeleteBridgeType removes the bridge type

func (*ORM) DeleteExternalInitiator

func (orm *ORM) DeleteExternalInitiator(name string) error

DeleteExternalInitiator removes an external initiator

func (*ORM) DeleteUser

func (orm *ORM) DeleteUser() error

DeleteUser will delete the API User in the db.

func (*ORM) DeleteUserSession

func (orm *ORM) DeleteUserSession(sessionID string) error

DeleteUserSession will erase the session ID for the sole API User.

func (*ORM) EthTransactionsWithAttempts added in v0.9.6

func (orm *ORM) EthTransactionsWithAttempts(offset, limit int) ([]bulletprooftxmanager.EthTx, int, error)

EthTransactionsWithAttempts returns all eth transactions with at least one attempt limited by passed parameters. Attempts are sorted by created_at.

func (*ORM) EthTxAttempts added in v0.9.6

func (orm *ORM) EthTxAttempts(offset, limit int) ([]bulletprooftxmanager.EthTxAttempt, int, error)

EthTxAttempts returns the last tx attempts sorted by created_at descending.

func (*ORM) ExternalInitiatorsSorted added in v0.10.11

func (orm *ORM) ExternalInitiatorsSorted(offset int, limit int) ([]models.ExternalInitiator, int, error)

ExternalInitiatorsSorted returns many ExternalInitiators sorted by Name from the store adhering to the passed parameters.

func (*ORM) FindBridge

func (orm *ORM) FindBridge(name models.TaskType) (bt models.BridgeType, err error)

FindBridge looks up a Bridge by its Name.

func (*ORM) FindEthTxAttempt added in v0.9.6

func (orm *ORM) FindEthTxAttempt(hash common.Hash) (*bulletprooftxmanager.EthTxAttempt, error)

FindEthTxAttempt returns an individual EthTxAttempt

func (*ORM) FindExternalInitiator

func (orm *ORM) FindExternalInitiator(
	eia *auth.Token,
) (*models.ExternalInitiator, error)

FindExternalInitiator finds an external initiator given an authentication request

func (*ORM) FindExternalInitiatorByName added in v0.6.6

func (orm *ORM) FindExternalInitiatorByName(iname string) (exi models.ExternalInitiator, err error)

FindExternalInitiatorByName finds an external initiator given an authentication request

func (*ORM) FindUser

func (orm *ORM) FindUser() (models.User, error)

FindUser will return the one API user, or an error.

func (*ORM) MustEnsureAdvisoryLock added in v0.8.2

func (orm *ORM) MustEnsureAdvisoryLock() error

MustEnsureAdvisoryLock sends a shutdown signal to the ORM if it an advisory lock cannot be acquired.

func (*ORM) MustSQLDB added in v0.10.0

func (orm *ORM) MustSQLDB() *sql.DB

func (*ORM) RawDBWithAdvisoryLock added in v0.10.3

func (orm *ORM) RawDBWithAdvisoryLock(fn func(*gorm.DB) error) error

func (*ORM) SaveUser

func (orm *ORM) SaveUser(user *models.User) error

SaveUser saves the user.

func (*ORM) SetLogging added in v0.6.1

func (orm *ORM) SetLogging(enabled bool)

SetLogging turns on SQL statement logging

func (*ORM) Unscoped

func (orm *ORM) Unscoped() *ORM

Unscoped returns a new instance of this ORM that includes soft deleted items.

func (*ORM) UpdateBridgeType

func (orm *ORM) UpdateBridgeType(bt *models.BridgeType, btr *models.BridgeTypeRequest) error

UpdateBridgeType updates the bridge type.

type PostgresLockingStrategy

type PostgresLockingStrategy struct {
	// contains filtered or unexported fields
}

PostgresLockingStrategy uses a postgres advisory lock to ensure exclusive access.

func (*PostgresLockingStrategy) Lock

func (s *PostgresLockingStrategy) Lock(timeout models.Duration) error

Lock uses a blocking postgres advisory lock that times out at the passed timeout.

func (*PostgresLockingStrategy) Unlock

func (s *PostgresLockingStrategy) Unlock(timeout models.Duration) error

Unlock unlocks the locked postgres advisory lock.

type SortType

type SortType int

SortType defines the different sort orders available.

const (
	// Ascending is the sort order going up, i.e. 1,2,3.
	Ascending SortType = iota
	// Descending is the sort order going down, i.e. 3,2,1.
	Descending
)

func (SortType) String

func (s SortType) String() string

Jump to

Keyboard shortcuts

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