database

package
v0.0.0-...-426e299 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAccountNotFound      = errors.New("account not found")
	ErrAccountAlreadyExists = errors.New("account already exists")
)
View Source
var (
	ErrDownloadTaskNotFound = errors.New("download task not found")
)

Functions

func InitializeGORMDB

func InitializeGORMDB(dbConfig configs.Database) (*gorm.DB, func(), error)

Types

type Account

type Account struct {
	AccountID   uint64 `gorm:"column:account_id;primaryKey"`
	AccountName string `gorm:"column:account_name"`
}

type AccountDataAccessor

type AccountDataAccessor interface {
	CreateAccount(ctx context.Context, account Account) (Account, error)
	GetAccountByID(ctx context.Context, id uint64) (Account, error)
	GetAccountByName(ctx context.Context, name string) (Account, error)
	WithDatabaseTransaction(database Database) AccountDataAccessor
}

func NewAccountDataAccessor

func NewAccountDataAccessor(database Database, logger *zap.Logger) AccountDataAccessor

type AccountPassword

type AccountPassword struct {
	OfAccountID uint64 `gorm:"column:of_account_id;primaryKey"`
	Hashed      string `gorm:"column:hashed"`
}

type AccountPasswordDataAccessor

type AccountPasswordDataAccessor interface {
	CreatePassword(ctx context.Context, ofAccountID uint64, hashedPassword string) (AccountPassword, error)
	GetPassword(ctx context.Context, ofAccountID uint64) (AccountPassword, error)
	WithDatabaseTransaction(database Database) AccountPasswordDataAccessor
}

func NewAccountPasswordDataAccessor

func NewAccountPasswordDataAccessor(
	database Database,
	logger *zap.Logger,
) AccountPasswordDataAccessor

type Database

type Database interface {
	AddError(err error) error
	Assign(attrs ...interface{}) (tx *gorm.DB)
	Association(column string) *gorm.Association
	Attrs(attrs ...interface{}) (tx *gorm.DB)
	AutoMigrate(dst ...interface{}) error
	Begin(opts ...*sql.TxOptions) *gorm.DB
	Clauses(conds ...clause.Expression) (tx *gorm.DB)
	Commit() *gorm.DB
	Connection(fc func(tx *gorm.DB) error) (err error)
	Count(count *int64) (tx *gorm.DB)
	Create(value interface{}) (tx *gorm.DB)
	CreateInBatches(value interface{}, batchSize int) (tx *gorm.DB)
	DB() (*sql.DB, error)
	Debug() (tx *gorm.DB)
	Delete(value interface{}, conds ...interface{}) (tx *gorm.DB)
	Distinct(args ...interface{}) (tx *gorm.DB)
	Exec(sql string, values ...interface{}) (tx *gorm.DB)
	Find(dest interface{}, conds ...interface{}) (tx *gorm.DB)
	FindInBatches(dest interface{}, batchSize int, fc func(tx *gorm.DB, batch int) error) *gorm.DB
	First(dest interface{}, conds ...interface{}) (tx *gorm.DB)
	FirstOrCreate(dest interface{}, conds ...interface{}) (tx *gorm.DB)
	FirstOrInit(dest interface{}, conds ...interface{}) (tx *gorm.DB)
	Get(key string) (interface{}, bool)
	Group(name string) (tx *gorm.DB)
	Having(query interface{}, args ...interface{}) (tx *gorm.DB)
	InnerJoins(query string, args ...interface{}) (tx *gorm.DB)
	InstanceGet(key string) (interface{}, bool)
	InstanceSet(key string, value interface{}) *gorm.DB
	Joins(query string, args ...interface{}) (tx *gorm.DB)
	Last(dest interface{}, conds ...interface{}) (tx *gorm.DB)
	Limit(limit int) (tx *gorm.DB)
	Migrator() gorm.Migrator
	Model(value interface{}) (tx *gorm.DB)
	Not(query interface{}, args ...interface{}) (tx *gorm.DB)
	Offset(offset int) (tx *gorm.DB)
	Omit(columns ...string) (tx *gorm.DB)
	Or(query interface{}, args ...interface{}) (tx *gorm.DB)
	Order(value interface{}) (tx *gorm.DB)
	Pluck(column string, dest interface{}) (tx *gorm.DB)
	Preload(query string, args ...interface{}) (tx *gorm.DB)
	Raw(sql string, values ...interface{}) (tx *gorm.DB)
	Rollback() *gorm.DB
	RollbackTo(name string) *gorm.DB
	Row() *sql.Row
	Rows() (*sql.Rows, error)
	Save(value interface{}) (tx *gorm.DB)
	SavePoint(name string) *gorm.DB
	Scan(dest interface{}) (tx *gorm.DB)
	ScanRows(rows *sql.Rows, dest interface{}) error
	Scopes(funcs ...func(*gorm.DB) *gorm.DB) (tx *gorm.DB)
	Select(query interface{}, args ...interface{}) (tx *gorm.DB)
	Session(config *gorm.Session) *gorm.DB
	Set(key string, value interface{}) *gorm.DB
	SetupJoinTable(model interface{}, field string, joinTable interface{}) error
	Table(name string, args ...interface{}) (tx *gorm.DB)
	Take(dest interface{}, conds ...interface{}) (tx *gorm.DB)
	ToSQL(queryFn func(tx *gorm.DB) *gorm.DB) string
	Transaction(fc func(tx *gorm.DB) error, opts ...*sql.TxOptions) (err error)
	Unscoped() (tx *gorm.DB)
	Update(column string, value interface{}) (tx *gorm.DB)
	UpdateColumn(column string, value interface{}) (tx *gorm.DB)
	UpdateColumns(values interface{}) (tx *gorm.DB)
	Updates(values interface{}) (tx *gorm.DB)
	Use(plugin gorm.Plugin) error
	Where(query interface{}, args ...interface{}) (tx *gorm.DB)
	WithContext(ctx context.Context) *gorm.DB
}

func InitializeDB

func InitializeDB(dbConfig configs.Database) (Database, func(), error)

type DownloadTask

type DownloadTask struct {
	DownloadTaskID uint64 `gorm:"column:download_task_id;primaryKey"`
	OfAccountID    uint64 `gorm:"column:of_account_id"`
	DownloadType   uint16 `gorm:"column:download_type"`
	DownloadURL    string `gorm:"column:download_url"`
	DownloadStatus uint16 `gorm:"column:download_status"`
	Metadata       string `gorm:"column:metadata"`
}

type DownloadTaskDataAccessor

type DownloadTaskDataAccessor interface {
	CreateDownloadTask(ctx context.Context, downloadTask DownloadTask) (DownloadTask, error)
	GetDownloadTask(ctx context.Context, downloadTaskID uint64) (DownloadTask, error)
	GetDownloadTaskForUpdate(ctx context.Context, downloadTaskID uint64) (DownloadTask, error)
	GetPendingDownloadTaskIDList(ctx context.Context) ([]uint64, error)
	GetDownloadTaskListOfAccount(ctx context.Context, accountID, offset, limit uint64) ([]DownloadTask, error)
	GetDownloadTaskCountOfAccount(ctx context.Context, accountID uint64) (uint64, error)
	UpdateDownloadTask(ctx context.Context, downloadTaskID uint64, downloadStatus uint16, metadata string) error
	UpdateFailedDownloadTaskStatusToPending(ctx context.Context) error
	DeleteDownloadTask(ctx context.Context, downloadTaskID uint64) error
	WithDatabaseTransaction(database Database) DownloadTaskDataAccessor
}

func NewDownloadTaskDataAccessor

func NewDownloadTaskDataAccessor(database Database, logger *zap.Logger) DownloadTaskDataAccessor

type Migrator

type Migrator interface {
	Up(ctx context.Context) error
	Down(ctx context.Context) error
}

func NewMigrator

func NewMigrator(dbConfig configs.Database) (Migrator, error)

type TokenPublicKey

type TokenPublicKey struct {
	TokenPublicKeyID    uint64 `gorm:"column:token_public_key_id;primaryKey"`
	TokenPublicKeyValue []byte `gorm:"column:token_public_key_value"`
}

type TokenPublicKeyDataAccessor

type TokenPublicKeyDataAccessor interface {
	CreatePublicKey(ctx context.Context, tokenPublicKey TokenPublicKey) (uint64, error)
	GetPublicKey(ctx context.Context, tokenPublicKeyID uint64) (TokenPublicKey, error)
}

func NewTokenPublicKeyDataAccessor

func NewTokenPublicKeyDataAccessor(
	database Database,
	logger *zap.Logger,
) (TokenPublicKeyDataAccessor, error)

Jump to

Keyboard shortcuts

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