db

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SubmissionStatusSubmitted SubmissionStatus = 1
	SubmissionStatusExecuting SubmissionStatus = 2
	SubmissionStatusFinished  SubmissionStatus = 3

	SubmissionResultOK                  SubmissionResult = 1
	SubmissionResultCompileError        SubmissionResult = 2
	SubmissionResultRuntimeError        SubmissionResult = 3
	SubmissionResultTimeLimitExceeded   SubmissionResult = 4
	SubmissionResultMemoryLimitExceeded SubmissionResult = 5
	SubmissionResultWrongAnswer         SubmissionResult = 6
	SubmissionResultUnsupportedLanguage SubmissionResult = 7
)

Variables

Functions

func InitializeDB

func InitializeDB(
	logger *zap.Logger,
	databaseConfig configs.Database,
) (*gorm.DB, error)

Types

type Account

type Account struct {
	gorm.Model
	AccountName string      `gorm:"type:varchar(32);uniqueIndex"`
	DisplayName string      `gorm:"type:varchar(32)"`
	Role        AccountRole `gorm:"type:varchar(32)"`
}

type AccountDataAccessor

type AccountDataAccessor interface {
	CreateAccount(ctx context.Context, account *Account) error
	UpdateAccount(ctx context.Context, account *Account) error
	GetAccount(ctx context.Context, id uint64) (*Account, error)
	GetAccountByAccountName(ctx context.Context, accountName string) (*Account, error)
	GetAccountList(ctx context.Context, offset, limit uint64) ([]*Account, error)
	GetAccountCount(ctx context.Context) (uint64, error)
	WithDB(db *gorm.DB) AccountDataAccessor
}

func NewAccountDataAccessor

func NewAccountDataAccessor(
	db *gorm.DB,
	logger *zap.Logger,
) AccountDataAccessor

type AccountPassword

type AccountPassword struct {
	gorm.Model
	OfAccountID uint64 `gorm:"index"`
	Hash        string `gorm:"type:varchar(128)"`
}

type AccountPasswordDataAccessor

type AccountPasswordDataAccessor interface {
	CreateAccountPassword(ctx context.Context, accountPassword *AccountPassword) error
	UpdateAccountPassword(ctx context.Context, accountPassword *AccountPassword) error
	GetAccountPasswordOfAccountID(ctx context.Context, accountID uint64) (*AccountPassword, error)
	WithDB(db *gorm.DB) AccountPasswordDataAccessor
}

func NewAccountPasswordDataAccessor

func NewAccountPasswordDataAccessor(
	db *gorm.DB,
	logger *zap.Logger,
) AccountPasswordDataAccessor

type AccountRole

type AccountRole string
const (
	AccountRoleAdmin         AccountRole = "admin"
	AccountRoleProblemSetter AccountRole = "problem_setter"
	AccountRoleContestant    AccountRole = "contestant"
	AccountRoleWorker        AccountRole = "worker"
)

type Migrator

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

func NewMigrator

func NewMigrator(
	db *gorm.DB,
	logger *zap.Logger,
) Migrator

type Problem

type Problem struct {
	gorm.Model
	UUID                   string `gorm:"type:char(36);uniqueIndex"`
	DisplayName            string `gorm:"type:varchar(256)"`
	AuthorAccountID        uint64 `gorm:"index"`
	Description            string `gorm:"type:text"`
	TimeLimitInMillisecond uint64
	MemoryLimitInByte      uint64
}

type ProblemDataAccessor

type ProblemDataAccessor interface {
	CreateProblem(ctx context.Context, problem *Problem) error
	UpdateProblem(ctx context.Context, problem *Problem) error
	DeleteProblem(ctx context.Context, id uint64) error
	GetProblem(ctx context.Context, id uint64) (*Problem, error)
	GetProblemByUUID(ctx context.Context, uuid string) (*Problem, error)
	GetProblemList(ctx context.Context, offset, limit uint64) ([]*Problem, error)
	GetAccountProblemList(ctx context.Context, accountID uint64, offset, limit uint64) ([]*Problem, error)
	GetProblemCount(ctx context.Context) (uint64, error)
	GetAccountProblemCount(ctx context.Context, accountID uint64) (uint64, error)
	WithDB(db *gorm.DB) ProblemDataAccessor
}

func NewProblemDataAccessor

func NewProblemDataAccessor(
	db *gorm.DB,
	logger *zap.Logger,
) ProblemDataAccessor

type ProblemExample

type ProblemExample struct {
	gorm.Model
	OfProblemID uint64
	Input       string `gorm:"type:text"`
	Output      string `gorm:"type:text"`
}

type ProblemExampleDataAccessor

type ProblemExampleDataAccessor interface {
	CreateProblemExampleList(ctx context.Context, problemExampleList []*ProblemExample) error
	GetProblemExampleListOfProblem(ctx context.Context, problemID uint64) ([]*ProblemExample, error)
	DeleteProblemExampleOfProblem(ctx context.Context, problemID uint64) error
	WithDB(db *gorm.DB) ProblemExampleDataAccessor
}

func NewProblemExampleDataAccessor

func NewProblemExampleDataAccessor(
	db *gorm.DB,
	logger *zap.Logger,
) ProblemExampleDataAccessor

type ProblemTestCaseHash

type ProblemTestCaseHash struct {
	gorm.Model
	OfProblemID uint64 `gorm:"index"`
	Hash        string `gorm:"type:text"`
}

type ProblemTestCaseHashDataAccessor

type ProblemTestCaseHashDataAccessor interface {
	CreateProblemTestCaseHash(ctx context.Context, problemTestCaseHash *ProblemTestCaseHash) error
	UpdateProblemTestCaseHash(ctx context.Context, problemTestCaseHash *ProblemTestCaseHash) error
	GetProblemTestCaseHashOfProblem(ctx context.Context, problemID uint64) (*ProblemTestCaseHash, error)
	DeleteProblemTestCaseHashOfProblem(ctx context.Context, problemID uint64) error
	WithDB(db *gorm.DB) ProblemTestCaseHashDataAccessor
}

func NewProblemTestCaseHashDataAccessor

func NewProblemTestCaseHashDataAccessor(
	db *gorm.DB,
	logger *zap.Logger,
) ProblemTestCaseHashDataAccessor

type Setting added in v1.2.0

type Setting struct {
	gorm.Model
	Data []byte
}

type SettingDataAccessor added in v1.2.0

type SettingDataAccessor interface {
	UpsertSetting(ctx context.Context, setting *Setting) error
	GetSetting(ctx context.Context) (*Setting, error)
	WithDB(db *gorm.DB) SettingDataAccessor
}

func NewSettingDataAccessor added in v1.2.0

func NewSettingDataAccessor(
	db *gorm.DB,
	logger *zap.Logger,
) SettingDataAccessor

type Submission

type Submission struct {
	gorm.Model
	OfProblemID     uint64           `gorm:"index"`
	AuthorAccountID uint64           `gorm:"index"`
	Content         string           `gorm:"type:text"`
	Language        string           `gorm:"type:varchar(16)"`
	Status          SubmissionStatus `gorm:"index"`
	Result          SubmissionResult
}

type SubmissionDataAccessor

type SubmissionDataAccessor interface {
	CreateSubmission(ctx context.Context, submission *Submission) error
	UpdateSubmission(ctx context.Context, submission *Submission) error
	UpdateExecutingSubmissionUpdatedBeforeThresholdToSubmitted(ctx context.Context, threshold time.Time) error
	DeleteSubmission(ctx context.Context, id uint64) error
	DeleteSubmissionOfProblem(ctx context.Context, problemID uint64) error
	GetSubmission(ctx context.Context, id uint64) (*Submission, error)
	GetSubmissionList(
		ctx context.Context,
		filterParams SubmissionListFilterParams,
		offset,
		limit uint64,
	) ([]*Submission, error)
	GetSubmissionIDList(ctx context.Context, filterParams SubmissionListFilterParams) ([]uint64, error)
	GetSubmissionCount(ctx context.Context, filterParams SubmissionListFilterParams) (uint64, error)
	WithDB(db *gorm.DB) SubmissionDataAccessor
}

func NewSubmissionDataAccessor

func NewSubmissionDataAccessor(
	db *gorm.DB,
	logger *zap.Logger,
) SubmissionDataAccessor

type SubmissionListFilterParams

type SubmissionListFilterParams struct {
	OfProblemID     *uint64
	AuthorAccountID *uint64
	Status          SubmissionStatus
}

type SubmissionResult

type SubmissionResult uint8

type SubmissionStatus

type SubmissionStatus uint8

type TestCase

type TestCase struct {
	gorm.Model
	UUID        string `gorm:"type:char(36);uniqueIndex"`
	OfProblemID uint64 `gorm:"index"`
	Input       string `gorm:"type:text"`
	Output      string `gorm:"type:text"`
	Hash        string `gorm:"type:text"`
	IsHidden    bool
}

type TestCaseDataAccessor

type TestCaseDataAccessor interface {
	CreateTestCase(ctx context.Context, testCase *TestCase) error
	CreateTestCaseList(ctx context.Context, testCaseList []*TestCase) error
	GetTestCase(ctx context.Context, id uint64) (*TestCase, error)
	GetTestCaseByUUID(ctx context.Context, uuid string) (*TestCase, error)
	GetTestCaseListOfProblem(ctx context.Context, problemID uint64, offset uint64, limit uint64) ([]*TestCase, error)
	GetTestCaseIDListOfProblem(ctx context.Context, problemID uint64) ([]uint64, error)
	GetTestCaseHashListOfProblem(ctx context.Context, problemID uint64, offset uint64, limit uint64) ([]string, error)
	GetTestCaseCountOfProblem(ctx context.Context, problemID uint64) (uint64, error)
	UpdateTestCase(ctx context.Context, testCase *TestCase) error
	DeleteTestCase(ctx context.Context, id uint64) error
	DeleteTestCaseOfProblem(ctx context.Context, problemID uint64) error
	WithDB(db *gorm.DB) TestCaseDataAccessor
}

func NewTestCaseDataAccessor

func NewTestCaseDataAccessor(
	db *gorm.DB,
	logger *zap.Logger,
) TestCaseDataAccessor

type TokenPublicKey added in v1.1.0

type TokenPublicKey struct {
	gorm.Model
	PublicKey []byte
}

type TokenPublicKeyDataAccessor added in v1.1.0

type TokenPublicKeyDataAccessor interface {
	CreatePublicKey(ctx context.Context, tokenPublicKey *TokenPublicKey) error
	GetPublicKey(ctx context.Context, id uint64) (*TokenPublicKey, error)
	WithDB(db *gorm.DB) TokenPublicKeyDataAccessor
}

func NewTokenPublicKeyDataAccessor added in v1.1.0

func NewTokenPublicKeyDataAccessor(
	db *gorm.DB,
	logger *zap.Logger,
) TokenPublicKeyDataAccessor

Jump to

Keyboard shortcuts

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