database

package
v0.0.0-...-654e1bf Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 17 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 (
	ErrProblemNotFound      = errors.New("problem not found")
	ErrProblemAlreadyExists = errors.New("problem already exists")
)
View Source
var (
	ErrSubmissionNotFound = errors.New("submission not found")
)
View Source
var (
	ErrTestCaseNotFound = errors.New("test case not found")
)

Functions

func InitializeGORMDB

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

Types

type Account

type Account struct {
	ID   uint64 `gorm:"column:id;primaryKey"`
	Name string `gorm:"column:name"`
	Role int8   `gotm:"column:role"`
}

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 Migrator

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

func NewMigrator

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

type Problem

type Problem struct {
	ID          uint64 `gorm:"column:id;primaryKey"`
	DisplayName string `gorm:"column:display_name"`
	AuthorID    uint64 `gorm:"column:author_id"`
	Description string `gorm:"column:description"`
	TimeLimit   uint64 `gorm:"column:time_limit"`
	MemoryLimit uint64 `gorm:"column:memory_limit"`
}

type ProblemDataAccessor

type ProblemDataAccessor interface {
	CreateProblem(ctx context.Context, problem Problem) (Problem, error)
	GetProblemByID(ctx context.Context, id uint64) (Problem, error)
	GetProblemByName(ctx context.Context, name string) (Problem, error)
	GetProblemList(ctx context.Context, offset uint64, limit uint64) ([]Problem, error)
	GetProblemCount(ctx context.Context) (uint64, error)
	UpdateProblem(ctx context.Context, id uint64, problem Problem) (Problem, error)
	DeleteProblem(ctx context.Context, id uint64) error
	WithDatabaseTransaction(database Database) ProblemDataAccessor
}

func NewProblemDataAccessor

func NewProblemDataAccessor(database Database, logger *zap.Logger) ProblemDataAccessor

type Submission

type Submission struct {
	ID          uint64 `gorm:"column:id;primaryKey"`
	OfProblemID uint64 `gorm:"column:of_problem_id"`
	AuthorID    uint64 `gorm:"column:author_id"`
	Content     string `gorm:"column:content"`
	Language    string `gorm:"column:language"`
	Status      int8   `gorm:"column:status"`
	Result      int8   `gorm:"column:result"`
}

type SubmissionDataAccessor

type SubmissionDataAccessor interface {
	CreateSubmission(ctx context.Context, submission Submission) (Submission, error)
	GetSubmissionByID(ctx context.Context, id uint64) (Submission, error)
	GetSubmissionList(ctx context.Context, offset, limit uint64) ([]Submission, error)
	GetSubmissionCount(ctx context.Context) (uint64, error)
	GetProblemSubmissionList(ctx context.Context, problemID, offset, limit uint64) ([]Submission, error)
	GetProblemSubmissionCount(ctx context.Context, problemID uint64) (uint64, error)
	GetAccountProblemSubmissionList(ctx context.Context, accountID, problemID, offset, limit uint64) ([]Submission, error)
	GetAccountProblemSubmissionCount(ctx context.Context, accountID, problemID uint64) (uint64, error)
	UpdateSubmission(ctx context.Context, submission Submission) (Submission, error)
	DeleteSubmission(ctx context.Context, id uint64) error
	WithDatabaseTransaction(database Database) SubmissionDataAccessor
}

func NewSubmissionDataAccessor

func NewSubmissionDataAccessor(database Database, logger *zap.Logger) SubmissionDataAccessor

type TestCase

type TestCase struct {
	ID          uint64 `gorm:"column:id;primaryKey"`
	OfProblemID uint64 `gorm:"column:of_problem_id"`
	Input       string `gorm:"column:input"`
	Output      string `gorm:"column:output"`
	IsHidden    bool   `gorm:"column:is_hidden"`
}

type TestCaseDataAccessor

type TestCaseDataAccessor interface {
	CreateTestCase(ctx context.Context, testCase TestCase) (TestCase, error)
	GetTestCaseByID(ctx context.Context, id uint64) (TestCase, error)
	DeleteTestCase(ctx context.Context, id uint64) error
	GetProblemTestCaseList(ctx context.Context, problemID uint64, offset uint64, limit uint64) ([]TestCase, error)
	GetProblemTestCaseListAll(ctx context.Context, problemID uint64) ([]TestCase, error)
	GetProblemTestCaseCount(ctx context.Context, problemID uint64) (uint64, error)
	UpdateTestCase(ctx context.Context, testCase TestCase) (TestCase, error)
	WithDatabaseTransaction(database Database) TestCaseDataAccessor
}

func NewTestCaseDataAccessor

func NewTestCaseDataAccessor(database Database, logger *zap.Logger) TestCaseDataAccessor

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