store

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ImportTableName = "Import"

ImportTableName is the name of the database table used for storing import records.

View Source
const TranslationTableName = "Translation"

TranslationTableName is the name of the database table used for storing translation data.

Variables

View Source
var UploadTableName = "Upload"

UploadTableName is the name of the database table used for storing upload records.

Functions

func LatestVersion

func LatestVersion() semver.Version

LatestVersion returns the version to which the last migration migrates.

Types

type SQLStore

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

SQLStore abstracts access to the database.

func New

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

New creates and initializes a new SQLStore instance. It takes a database connection string (DSN) and a logger instance. It returns an initialized SQLStore or an error if the connection to the database fails.

func (*SQLStore) CompleteUpload

func (sqlStore *SQLStore) CompleteUpload(uploadID, errorMessage string) error

CompleteUpload marks an upload as complete in the database, with or without an error message (provide an empty string if no error)

func (*SQLStore) CreateImport added in v0.2.0

func (sqlStore *SQLStore) CreateImport(imp *model.Import) error

CreateImport stores a new import.

func (*SQLStore) CreateTranslation added in v0.2.0

func (sqlStore *SQLStore) CreateTranslation(translation *model.Translation) error

CreateTranslation stores a new translation.

func (*SQLStore) CreateUpload

func (sqlStore *SQLStore) CreateUpload(id string, archiveType model.BackupType) error

CreateUpload creates an upload object in the database to represent a started upload

func (*SQLStore) GetAllImports

func (sqlStore *SQLStore) GetAllImports() ([]*model.Import, error)

GetAllImports returns all of the Imports in the database TODO pagination

func (*SQLStore) GetAllTranslations

func (sqlStore *SQLStore) GetAllTranslations() ([]*model.Translation, error)

GetAllTranslations returns every Translation in the DB TODO pagination

func (*SQLStore) GetAndClaimNextReadyImport

func (sqlStore *SQLStore) GetAndClaimNextReadyImport(provisionerID string) (*model.Import, error)

GetAndClaimNextReadyImport finds the oldest unclaimed and non-started Import and locks it with the given provisionerID before returning that Import Returns nil with no error if no Import is available to lock Returns nil, error if the Import cannot be claimed for some other reason

func (*SQLStore) GetCurrentVersion

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

GetCurrentVersion queries the System table for the current database version.

func (*SQLStore) GetImport

func (sqlStore *SQLStore) GetImport(id string) (*model.Import, error)

GetImport returns a single Import with identifier id

func (*SQLStore) GetImportsByInstallation

func (sqlStore *SQLStore) GetImportsByInstallation(id string) ([]*model.Import, error)

GetImportsByInstallation provides a convenience function for looking up all Imports that belong to a given Installation

func (*SQLStore) GetImportsByTranslation

func (sqlStore *SQLStore) GetImportsByTranslation(id string) ([]*model.Import, error)

GetImportsByTranslation provides a convenience function for looking up all Imports that belong to a given Translation

func (*SQLStore) GetImportsInProgress

func (sqlStore *SQLStore) GetImportsInProgress() ([]*model.Import, error)

GetImportsInProgress retrieves all imports that are currently in progress.

func (*SQLStore) GetTranslation

func (sqlStore *SQLStore) GetTranslation(id string) (*model.Translation, error)

GetTranslation returns the Translation that corresponds to the identifier ID

func (*SQLStore) GetTranslationReadyToStart

func (sqlStore *SQLStore) GetTranslationReadyToStart() (*model.Translation, error)

GetTranslationReadyToStart returns a batch of Translations that are ready to go, with a maximum of ten, sorted from oldest to newest

func (*SQLStore) GetTranslationsByInstallation

func (sqlStore *SQLStore) GetTranslationsByInstallation(id string) ([]*model.Translation, error)

GetTranslationsByInstallation provides a convenience method for fetching every Translation related to a given Installation by its ID

func (*SQLStore) GetUnlockedImportPendingWork added in v0.3.0

func (sqlStore *SQLStore) GetUnlockedImportPendingWork() ([]*model.Import, error)

GetUnlockedImportPendingWork retrieves all imports that are pending work and not locked.

func (*SQLStore) GetUpload

func (sqlStore *SQLStore) GetUpload(id string) (*model.Upload, error)

GetUpload will fetch the metadata about an upload from the database by ID

func (*SQLStore) Migrate

func (sqlStore *SQLStore) Migrate() error

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

func (*SQLStore) TryLockImport

func (sqlStore *SQLStore) TryLockImport(imp *model.Import, owner string) error

TryLockImport attempts to lock the input Import with the given owner, but will not do so if the column already contains something, and will return an error instead in that case

func (*SQLStore) TryLockTranslation

func (sqlStore *SQLStore) TryLockTranslation(translation *model.Translation, owner string) error

TryLockTranslation attempts to claim the given translation for the owner ID provided and returns an error if it fails to do so

func (*SQLStore) UnlockImport

func (sqlStore *SQLStore) UnlockImport(imp *model.Import) error

UnlockImport clears the lock for the given Import

func (*SQLStore) UnlockTranslation

func (sqlStore *SQLStore) UnlockTranslation(translation *model.Translation) error

UnlockTranslation clears the lock on the given translation

func (*SQLStore) UpdateImport

func (sqlStore *SQLStore) UpdateImport(imp *model.Import) error

UpdateImport writes changes to the input Import to the database

func (*SQLStore) UpdateTranslation

func (sqlStore *SQLStore) UpdateTranslation(translation *model.Translation) error

UpdateTranslation stores changes to the provided translation 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