orm

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2019 License: MIT Imports: 23 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
)

Functions

func Batch

func Batch(chunkSize uint, cb func(offset, limit uint) (uint, error)) error

Batch is an iterator _like_ for batches of records

Types

type DialectName

type DialectName string

DialectName is a compiler enforced type used that maps to gorm's dialect names.

const (
	// DialectPostgres represents the postgres dialect.
	DialectPostgres DialectName = "postgres"
	// DialectSqlite represents the sqlite dialect.
	DialectSqlite = "sqlite3"
)

func DeduceDialect

func DeduceDialect(path string) (DialectName, error)

DeduceDialect returns the appropriate dialect for the passed connection string.

type FileLockingStrategy

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

FileLockingStrategy uses a file lock on disk to ensure exclusive access.

func (*FileLockingStrategy) Lock

func (s *FileLockingStrategy) Lock(timeout time.Duration) error

Lock returns immediately and assumes is always unlocked.

func (*FileLockingStrategy) Unlock

func (s *FileLockingStrategy) Unlock() error

Unlock is a noop.

type LockingStrategy

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

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

func NewFileLockingStrategy

func NewFileLockingStrategy(dbpath string) (LockingStrategy, error)

NewFileLockingStrategy creates a new instance of FileLockingStrategy at the passed path.

func NewLockingStrategy

func NewLockingStrategy(dialect DialectName, dbpath string) (LockingStrategy, error)

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

func NewPostgresLockingStrategy

func NewPostgresLockingStrategy(path string) (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 time.Duration) (*ORM, error)

NewORM initializes a new database file at the configured uri.

func (*ORM) AddTxAttempt

func (orm *ORM) AddTxAttempt(
	tx *models.Tx,
	etx *types.Transaction,
	blkNum uint64,
) (*models.TxAttempt, error)

AddTxAttempt creates a new transaction attempt and stores it in the database.

func (*ORM) AllSyncEvents

func (orm *ORM) AllSyncEvents(cb func(*models.SyncEvent) error) error

AllSyncEvents returns all sync events

func (*ORM) AnyJobWithType

func (orm *ORM) AnyJobWithType(taskTypeName string) (bool, error)

AnyJobWithType returns true if there is at least one job associated with the type name specified and false otherwise

func (*ORM) ArchiveJob

func (orm *ORM) ArchiveJob(ID string) error

ArchiveJob soft deletes the job and its associated job runs.

func (*ORM) Archived

func (orm *ORM) Archived(ID string) bool

Archived returns whether or not a job has been archived.

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) BulkDeleteRuns

func (orm *ORM) BulkDeleteRuns(bulkQuery *models.BulkDeleteRunRequest) error

BulkDeleteRuns removes JobRuns and their related records: TaskRuns and RunResults.

TaskRuns are removed by ON DELETE CASCADE when the JobRuns are deleted, but RunResults are not using foreign keys because multiple foreign keys on a record creates an ambiguity with gorm.

func (*ORM) ClearNonCurrentSessions

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

ClearNonCurrentSessions removes all sessions but the id passed in.

func (*ORM) ClearSessions

func (orm *ORM) ClearSessions() error

ClearSessions removes all sessions.

func (*ORM) ClobberDiskKeyStoreWithDBKeys

func (orm *ORM) ClobberDiskKeyStoreWithDBKeys(keysDir string) error

ClobberDiskKeyStoreWithDBKeys writes all keys stored in the orm to the keys folder on disk, deleting anything there prior.

func (*ORM) Close

func (orm *ORM) Close() error

Close closes the underlying database connection.

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) CreateHead added in v0.6.1

func (orm *ORM) CreateHead(n *models.Head) error

CreateHead creates a head record that tracks which block heads we've observed in the HeadTracker

func (*ORM) CreateInitiator

func (orm *ORM) CreateInitiator(initr *models.Initiator) error

CreateInitiator saves the initiator.

func (*ORM) CreateJob

func (orm *ORM) CreateJob(job *models.JobSpec) error

CreateJob saves a job to the database and adds IDs to associated tables.

func (*ORM) CreateJobRun

func (orm *ORM) CreateJobRun(run *models.JobRun) error

CreateJobRun inserts a new JobRun

func (*ORM) CreateServiceAgreement

func (orm *ORM) CreateServiceAgreement(sa *models.ServiceAgreement) error

CreateServiceAgreement saves a Service Agreement, its JobSpec and its associations to the database.

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) CreateTx

func (orm *ORM) CreateTx(
	surrogateID null.String,
	ethTx *types.Transaction,
	from *common.Address,
	sentAt uint64,
) (*models.Tx, error)

CreateTx returns a transaction by its surrogate key, if it exists, or creates it and its attempts

func (*ORM) DeleteBridgeType

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

DeleteBridgeType removes the bridge type

func (*ORM) DeleteExternalInitiator

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

DeleteExternalInitiator removes an external initiator

func (*ORM) DeleteJobRun

func (orm *ORM) DeleteJobRun(ID string) error

DeleteJobRun deletes the job run and corresponding task runs.

func (*ORM) DeleteStaleSessions

func (orm *ORM) DeleteStaleSessions(before time.Time) error

DeleteStaleSessions deletes all sessions before the passed time.

func (*ORM) DeleteTransaction

func (orm *ORM) DeleteTransaction(ethtx *models.Tx) error

DeleteTransaction deletes a transaction an all of its attempts.

func (*ORM) DeleteUser

func (orm *ORM) DeleteUser() (models.User, 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) DialectName

func (orm *ORM) DialectName() DialectName

func (*ORM) FindBridge

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

FindBridge looks up a Bridge by its Name.

func (*ORM) FindExternalInitiator

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

FindExternalInitiator finds an external initiator given an authentication request

func (*ORM) FindInitiator

func (orm *ORM) FindInitiator(ID uint) (models.Initiator, error)

FindInitiator returns the single initiator defined by the passed ID.

func (*ORM) FindJob

func (orm *ORM) FindJob(id string) (models.JobSpec, error)

FindJob looks up a Job by its ID.

func (*ORM) FindJobRun

func (orm *ORM) FindJobRun(id string) (models.JobRun, error)

FindJobRun looks up a JobRun by its ID.

func (*ORM) FindServiceAgreement

func (orm *ORM) FindServiceAgreement(id string) (models.ServiceAgreement, error)

FindServiceAgreement looks up a ServiceAgreement by its ID.

func (*ORM) FindTx

func (orm *ORM) FindTx(ID uint64) (*models.Tx, error)

FindTx returns the specific transaction for the passed ID.

func (*ORM) FindTxAttempt

func (orm *ORM) FindTxAttempt(hash common.Hash) (*models.TxAttempt, error)

FindTxAttempt returns an individual TxAttempt

func (*ORM) FindTxByAttempt

func (orm *ORM) FindTxByAttempt(hash common.Hash) (*models.Tx, *models.TxAttempt, error)

FindTxByAttempt returns the specific transaction attempt with the hash.

func (*ORM) FindUser

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

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

func (*ORM) FirstOrCreateKey

func (orm *ORM) FirstOrCreateKey(k *models.Key) error

FirstOrCreateKey returns the first key found or creates a new one in the orm.

func (*ORM) GetLastNonce

func (orm *ORM) GetLastNonce(address common.Address) (uint64, error)

GetLastNonce retrieves the last known nonce in the database for an account

func (*ORM) JobRunsCountFor

func (orm *ORM) JobRunsCountFor(jobSpecID string) (int, error)

JobRunsCountFor returns the current number of runs for the job

func (*ORM) JobRunsFor

func (orm *ORM) JobRunsFor(jobSpecID string, limit ...int) ([]models.JobRun, error)

JobRunsFor fetches all JobRuns with a given Job ID, sorted by their created at time.

func (*ORM) JobRunsSorted

func (orm *ORM) JobRunsSorted(sort SortType, offset int, limit int) ([]models.JobRun, int, error)

JobRunsSorted returns job runs ordered and filtered by the passed params.

func (*ORM) JobRunsSortedFor

func (orm *ORM) JobRunsSortedFor(id string, order SortType, offset int, limit int) ([]models.JobRun, int, error)

JobRunsSortedFor returns job runs for a specific job spec ordered and filtered by the passed params.

func (*ORM) Jobs

func (orm *ORM) Jobs(cb func(models.JobSpec) bool) error

Jobs fetches all jobs.

func (*ORM) JobsSorted

func (orm *ORM) JobsSorted(sort SortType, offset int, limit int) ([]models.JobSpec, int, error)

JobsSorted returns many JobSpecs sorted by CreatedAt from the store adhering to the passed parameters.

func (*ORM) Keys

func (orm *ORM) Keys() ([]*models.Key, error)

Keys returns all keys stored in the orm.

func (*ORM) LastHead

func (orm *ORM) LastHead() (*models.Head, error)

LastHead returns the most recently persisted head entry.

func (*ORM) MarkRan

func (orm *ORM) MarkRan(i *models.Initiator, ran bool) error

MarkRan will set Ran to true for a given initiator

func (*ORM) MarkTxSafe

func (orm *ORM) MarkTxSafe(tx *models.Tx, txAttempt *models.TxAttempt) error

MarkTxSafe updates the database for the given transaction and attempt to show that the transaction has not just been confirmed, but has met the minimum number of outgoing confirmations to be deemed safely written on the blockchain.

func (*ORM) PendingBridgeType

func (orm *ORM) PendingBridgeType(jr models.JobRun) (models.BridgeType, error)

PendingBridgeType returns the bridge type of the current pending task, or error if not pending bridge.

func (*ORM) SaveJobRun

func (orm *ORM) SaveJobRun(run *models.JobRun) error

SaveJobRun updates UpdatedAt for a JobRun and saves it

func (*ORM) SaveSession

func (orm *ORM) SaveSession(session *models.Session) error

SaveSession saves the session.

func (*ORM) SaveUser

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

SaveUser saves the user.

func (*ORM) Sessions

func (orm *ORM) Sessions(offset, limit int) ([]models.Session, error)

Sessions returns all sessions limited by the parameters.

func (*ORM) SetLogging added in v0.6.1

func (orm *ORM) SetLogging(enabled bool)

SetLogging turns on SQL statement logging

func (*ORM) Transactions

func (orm *ORM) Transactions(offset, limit int) ([]models.Tx, int, error)

Transactions returns all transactions limited by passed parameters.

func (*ORM) TxAttempts

func (orm *ORM) TxAttempts(offset, limit int) ([]models.TxAttempt, int, error)

TxAttempts returns the last tx attempts sorted by sent at descending.

func (*ORM) TxFrom

func (orm *ORM) TxFrom(from common.Address) ([]models.Tx, error)

TxFrom returns all transactions from a particular address.

func (*ORM) Unscoped

func (orm *ORM) Unscoped() *ORM

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

func (*ORM) UnscopedJobRunsWithStatus

func (orm *ORM) UnscopedJobRunsWithStatus(cb func(*models.JobRun), statuses ...models.RunStatus) error

UnscopedJobRunsWithStatus passes all JobRuns to a callback, one by one, including those that were soft deleted.

func (*ORM) UpdateBridgeType

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

UpdateBridgeType updates the bridge type.

func (*ORM) UpdateTx

func (orm *ORM) UpdateTx(
	tx *models.Tx,
	ethTx *types.Transaction,
	from *common.Address,
	sentAt uint64,
) error

UpdateTx assigns new EthTx details to a transaction, typically used after a failed Eth transaction attempt

func (*ORM) Where

func (orm *ORM) Where(field string, value interface{}, instance interface{}) error

Where fetches multiple objects with "Find".

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 time.Duration) error

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

func (*PostgresLockingStrategy) Unlock

func (s *PostgresLockingStrategy) Unlock() 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