store

package
v0.0.0-...-0c09f60 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseConnection

func CloseConnection(tb testing.TB, sqlStore *SQLStore)

CloseConnection closes underlying database connection.

func GetMillis

func GetMillis() int64

GetMillis is a convenience method to get milliseconds since epoch.

func LatestVersion

func LatestVersion() semver.Version

LatestVersion returns the version to which the last migration migrates.

Types

type RawAccountMetadata

type RawAccountMetadata struct {
	ProviderMetadataRaw []byte
	AccountMetadataRaw  []byte
}

RawAccountMetadata is the raw byte metadata for a account.

type SQLStore

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

SQLStore abstracts access to the database.

func MakeTestSQLStore

func MakeTestSQLStore(tb testing.TB, logger log.FieldLogger) *SQLStore

MakeTestSQLStore creates a SQLStore for use with unit tests.

func New

func New(dsn string, logger logrus.FieldLogger) (*SQLStore, error)

New constructs a new instance of SQLStore.

func (*SQLStore) AddParentSubnet

func (sqlStore *SQLStore) AddParentSubnet(parentSubnet *model.ParentSubnet, subnets *[]model.Subnet) error

AddParentSubnet records the given parent subnet to the database.

func (*SQLStore) ClaimSubnet

func (sqlStore *SQLStore) ClaimSubnet(cidr string, accountID string) (*model.Subnet, error)

ClaimSubnet claims a subnet and associates it with an account. If an empty subnet is passed a random one will be allocated.

func (*SQLStore) CreateAccount

func (sqlStore *SQLStore) CreateAccount(account *model.Account) error

CreateAccount records the given account to the database, assigning it a unique ID.

func (*SQLStore) CreateWebhook

func (sqlStore *SQLStore) CreateWebhook(webhook *model.Webhook) error

CreateWebhook records the given webhook to the database, assigning it a unique ID.

func (*SQLStore) DeleteAccount

func (sqlStore *SQLStore) DeleteAccount(id string) error

DeleteAccount marks the given account as deleted, but does not remove the record from the database.

func (*SQLStore) DeleteWebhook

func (sqlStore *SQLStore) DeleteWebhook(id string) error

DeleteWebhook marks the given webhook as deleted, but does not remove the record from the database.

func (*SQLStore) GetAccount

func (sqlStore *SQLStore) GetAccount(id string) (*model.Account, error)

GetAccount fetches the given account by id.

func (*SQLStore) GetAccounts

func (sqlStore *SQLStore) GetAccounts(filter *model.AccountFilter) ([]*model.Account, error)

GetAccounts fetches the given page of created accounts. The first page is 0.

func (*SQLStore) GetCurrentVersion

func (sqlStore *SQLStore) GetCurrentVersion() (semver.Version, error)

GetCurrentVersion queries the System table for the current database version.

func (*SQLStore) GetParentSubnet

func (sqlStore *SQLStore) GetParentSubnet(id string) (model.ParentSubnet, error)

GetParentSubnet fetches the given parent subnet by subnet range.

func (*SQLStore) GetParentSubnets

func (sqlStore *SQLStore) GetParentSubnets(filter *model.ParentSubnetFilter) ([]model.ParentSubnet, error)

GetParentSubnets fetches the given page of added parent subnets. The first page is 0.

func (*SQLStore) GetSubnet

func (sqlStore *SQLStore) GetSubnet(id string) (*model.Subnet, error)

GetSubnet fetches the given subnet by subnet range.

func (*SQLStore) GetSubnets

func (sqlStore *SQLStore) GetSubnets(filter *model.SubnetFilter) ([]*model.Subnet, error)

GetSubnets fetches the given page of added subnets. The first page is 0.

func (*SQLStore) GetUnlockedAccountsPendingWork

func (sqlStore *SQLStore) GetUnlockedAccountsPendingWork() ([]*model.Account, error)

GetUnlockedAccountsPendingWork returns an unlocked account in a pending state.

func (*SQLStore) GetWebhook

func (sqlStore *SQLStore) GetWebhook(id string) (*model.Webhook, error)

GetWebhook fetches the given webhook by id.

func (*SQLStore) GetWebhooks

func (sqlStore *SQLStore) GetWebhooks(filter *model.WebhookFilter) ([]*model.Webhook, error)

GetWebhooks fetches the given page of created webhooks. The first page is 0.

func (*SQLStore) LockAccount

func (sqlStore *SQLStore) LockAccount(accountID, lockerID string) (bool, error)

LockAccount marks the account as locked for exclusive use by the caller.

func (*SQLStore) LockAccountAPI

func (sqlStore *SQLStore) LockAccountAPI(accountID string) error

LockAccountAPI locks updates to the account from the API.

func (*SQLStore) LockParentSubnet

func (sqlStore *SQLStore) LockParentSubnet(subnet, lockerID string) (bool, error)

LockParentSubnet marks the parent subnet as locked for exclusive use by the caller.

func (*SQLStore) LockSubnet

func (sqlStore *SQLStore) LockSubnet(subnet, lockerID string) (bool, error)

LockSubnet marks the subnet as locked for exclusive use by the caller.

func (*SQLStore) Migrate

func (sqlStore *SQLStore) Migrate() error

Migrate advances the schema of the configured database to the latest version.

func (*SQLStore) SubnetCleanup

func (sqlStore *SQLStore) SubnetCleanup(cidr string) error

SubnetCleanup is cleaning up a subnet making it available for claim.

func (*SQLStore) UnlockAccount

func (sqlStore *SQLStore) UnlockAccount(accountID, lockerID string, force bool) (bool, error)

UnlockAccount releases a lock previously acquired against a caller.

func (*SQLStore) UnlockAccountAPI

func (sqlStore *SQLStore) UnlockAccountAPI(accountID string) error

UnlockAccountAPI unlocks updates to the account from the API.

func (*SQLStore) UnlockParentSubnet

func (sqlStore *SQLStore) UnlockParentSubnet(subnet, lockerID string, force bool) (bool, error)

UnlockParentSubnet releases a lock previously acquired against a caller.

func (*SQLStore) UnlockSubnet

func (sqlStore *SQLStore) UnlockSubnet(subnet, lockerID string, force bool) (bool, error)

UnlockSubnet releases a lock previously acquired against a caller.

func (*SQLStore) UpdateAccount

func (sqlStore *SQLStore) UpdateAccount(account *model.Account) error

UpdateAccount updates the given account in the database.

func (*SQLStore) UpdateSubnet

func (sqlStore *SQLStore) UpdateSubnet(subnet *model.Subnet) error

UpdateSubnet updates the given subnet in the database.

type Transaction

type Transaction struct {
	*sqlx.Tx
	// contains filtered or unexported fields
}

Transaction is a wrapper around *sqlx.Tx providing convenience methods.

func (*Transaction) Commit

func (t *Transaction) Commit() error

Commit commits the pending transaction.

func (*Transaction) RollbackUnlessCommitted

func (t *Transaction) RollbackUnlessCommitted()

RollbackUnlessCommitted rollback the transaction if it is not committed.

Jump to

Keyboard shortcuts

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