database

package module
v0.0.0-...-6efba7d Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: Apache-2.0 Imports: 21 Imported by: 5

Documentation

Index

Constants

View Source
const (
	MAX_TRY_TIMES = 3
)
View Source
const TASK_RETRY_PERIOD = time.Minute

Variables

View Source
var DEFAULT_DSN = DSN{
	Host:     "localhost",
	Port:     5432,
	Database: "librarychecker",
	User:     "postgres",
	Password: "lcdummypassword",
}
View Source
var ErrNotExist = errors.New("not exist")

Functions

func AutoMigrate

func AutoMigrate(db *gorm.DB) error

func ClearTestcaseResult

func ClearTestcaseResult(db *gorm.DB, subID int32) error

func Connect

func Connect(dsn DSN, enableLogger bool) *gorm.DB

func CreateTestDB

func CreateTestDB(t *testing.T) *gorm.DB

func FetchMetadata

func FetchMetadata(db *gorm.DB, key string) (*string, error)

func FinishTask

func FinishTask(db *gorm.DB, taskId int32) error

func PushHackTask

func PushHackTask(db *gorm.DB, id, priority int32) error

func PushSubmissionTask

func PushSubmissionTask(db *gorm.DB, id, priority int32) error

func PushTask

func PushTask(db *gorm.DB, taskData TaskData, priority int32) error

func RegisterUser

func RegisterUser(db *gorm.DB, name string, uid string) error

func SaveHack

func SaveHack(db *gorm.DB, h Hack) (int32, error)

func SaveMetadata

func SaveMetadata(db *gorm.DB, key string, value string) error

func SaveProblem

func SaveProblem(db *gorm.DB, problem Problem) error

func SaveProblemCategories

func SaveProblemCategories(db *gorm.DB, categories []ProblemCategory) error

func SaveSubmission

func SaveSubmission(db *gorm.DB, submission Submission) (int32, error)

save submission and return id

func SaveTestcaseResult

func SaveTestcaseResult(db *gorm.DB, result SubmissionTestcaseResult) error

func TouchTask

func TouchTask(db *gorm.DB, id int32) error

func UpdateHack

func UpdateHack(db *gorm.DB, h Hack) error

func UpdateSubmission

func UpdateSubmission(db *gorm.DB, submission Submission) error

func UpdateSubmissionStatus

func UpdateSubmissionStatus(db *gorm.DB, id int32, status string) error

func UpdateUser

func UpdateUser(db *gorm.DB, user User) error

Types

type DSN

type DSN struct {
	Host     string
	Port     int
	Database string
	User     string
	Password string
}

func GetDSNFromEnv

func GetDSNFromEnv() DSN

type Hack

type Hack struct {
	ID           int32      `gorm:"primaryKey"`
	HackTime     time.Time  `gorm:"not null"`
	Submission   Submission `gorm:"foreignKey:SubmissionID"`
	SubmissionID int32
	User         User `gorm:"foreignKey:UserName"`
	UserName     sql.NullString

	// Test case, exactly one item is not nil
	TestCaseTxt []byte
	TestCaseCpp []byte

	// Result
	Status      string
	Time        sql.NullInt32
	Memory      sql.NullInt64
	Stderr      []byte
	JudgeOutput []byte
}

Hack is db table

func FetchHack

func FetchHack(db *gorm.DB, id int32) (Hack, error)

type Metadata

type Metadata struct {
	Key   string `gorm:"primaryKey"`
	Value string
}

type Problem

type Problem struct {
	Name             string `gorm:"primaryKey"`
	Title            string
	SourceUrl        string
	Timelimit        int32
	TestCasesVersion string
	Version          string
}

Problem is db table

func FetchProblem

func FetchProblem(db *gorm.DB, name string) (Problem, error)

type ProblemCategory

type ProblemCategory struct {
	Title    string   `json:"title"`
	Problems []string `json:"problems"`
}

func FetchProblemCategories

func FetchProblemCategories(db *gorm.DB) ([]ProblemCategory, error)

type Submission

type Submission struct {
	ID               int32 `gorm:"primaryKey"`
	SubmissionTime   time.Time
	ProblemName      string
	Problem          Problem `gorm:"foreignKey:ProblemName"`
	Lang             string
	Status           string
	PrevStatus       string
	Hacked           bool
	Source           string
	TestCasesVersion string
	MaxTime          int32
	MaxMemory        int64
	CompileError     []byte
	UserName         sql.NullString
	User             User `gorm:"foreignKey:UserName"`
	JudgedTime       time.Time
}

Submission is db table

func FetchSubmission

func FetchSubmission(db *gorm.DB, id int32) (Submission, error)

type SubmissionOrder

type SubmissionOrder int
const (
	ID_DESC SubmissionOrder = iota
	MAX_TIME_ASC
)

type SubmissionOverView

type SubmissionOverView struct {
	ID               int32
	SubmissionTime   time.Time
	ProblemName      string
	Problem          Problem
	Lang             string
	Status           string
	TestCasesVersion string
	MaxTime          int32
	MaxMemory        int64
	UserName         sql.NullString
	User             User
}

SubmissionOverview is smart select table

func FetchSubmissionList

func FetchSubmissionList(db *gorm.DB, problem, status, lang, user string, dedupUser bool, order []SubmissionOrder, offset, limit int) ([]SubmissionOverView, int64, error)

func ToSubmissionOverView

func ToSubmissionOverView(s Submission) SubmissionOverView

type SubmissionTestcaseResult

type SubmissionTestcaseResult struct {
	Submission int32  `gorm:"primaryKey"` // TODO: should be foreign key
	Testcase   string `gorm:"primaryKey"`
	Status     string
	Time       int32
	Memory     int64
	Stderr     []byte
	CheckerOut []byte
}

SubmissionTestcaseResult is db table

func FetchTestcaseResults

func FetchTestcaseResults(db *gorm.DB, id int32) ([]SubmissionTestcaseResult, error)

type Task

type Task struct {
	ID        int32 `gorm:"primaryKey;autoIncrement"`
	Priority  int32
	Available time.Time
	Enqueue   time.Time
	TaskData  []byte
}

Task is db table

type TaskData

type TaskData struct {
	TaskType   TaskType
	Submission int32
	Hack       int32
}

func PopTask

func PopTask(db *gorm.DB) (int32, TaskData, error)

type TaskType

type TaskType = int
const (
	JUDGE_SUBMISSION TaskType
	JUDGE_HACK
)

type User

type User struct {
	Name        string `gorm:"primaryKey" validate:"username"`
	UID         string `gorm:"not null;unique"`
	LibraryURL  string `validate:"libraryURL"`
	IsDeveloper bool
}

User is db table

func FetchUserFromName

func FetchUserFromName(db *gorm.DB, name string) (*User, error)

func FetchUserFromUID

func FetchUserFromUID(db *gorm.DB, uid string) (*User, error)

Jump to

Keyboard shortcuts

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