db

package
v0.0.0-...-73882fe Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssociateParentID

func AssociateParentID(id uint) uint

func PopulateFromResource

func PopulateFromResource(artifact interface{}, resource string) error

Types

type Article

type Article struct {
	gorm.Model

	Title   string `json:"title"`
	Remote  string `json:"remote"`
	Content []byte

	ParentRefer uint
	Children    []Article `json:"children" gorm:"foreignKey:ParentRefer"`
}

func PopulateArticles

func PopulateArticles(resource string) (*Article, error)

func ReadArticles

func ReadArticles(db *gorm.DB) (*Article, error)

func (*Article) FetchContent

func (article *Article) FetchContent(recursive bool) error

func (*Article) FindByID

func (rootArticle *Article) FindByID(id uint) *Article

func (*Article) FindByTitle

func (rootArticle *Article) FindByTitle(title string) *Article

func (*Article) FindNext

func (rootArticle *Article) FindNext(article *Article) (*Article, error)

func (*Article) FindParent

func (rootArticle *Article) FindParent(child *Article) *Article

func (*Article) FindPrevious

func (rootArticle *Article) FindPrevious(article *Article) (*Article, error)

func (*Article) Write

func (rootArticle *Article) Write(db *gorm.DB) error

type Artifact

type Artifact interface {
	FetchContent(bool) error
	Exists(*gorm.DB) bool
	Write(*gorm.DB) error
	Read(*gorm.DB) error
}

type DB

type DB struct {
	Refer       *gorm.DB
	RootArticle *Article
	Exercises   []Exercise
	Sessions    []Session
}

func New

func New(filePath string) (*DB, error)

type Exercise

type Exercise struct {
	gorm.Model

	Content          string `json:"content"`
	ChecksWithScript bool   `json:"checks_with_script"`
	Expects          string `json:"expects"`

	ParentArticleRefer uint
	ParentArticle      Article `gorm:"foreignKey:ParentArticleRefer"`
}

func PopulateExercises

func PopulateExercises(resource string, rootArticle *Article) ([]Exercise, error)

func ReadExercises

func ReadExercises(db *gorm.DB) ([]Exercise, error)

func SortExercisesByParentArticle

func SortExercisesByParentArticle(exercises []Exercise, parentArticle *Article) []Exercise

func (*Exercise) Write

func (exercise *Exercise) Write(db *gorm.DB) error

type ExerciseRoot

type ExerciseRoot struct {
	ArticleTitle string     `json:"article_title"`
	Exercises    []Exercise `json:"exercises"`
}

should be used only when loading from exercise list resource.

type Session

type Session struct {
	gorm.Model

	Username string

	ArticleID uint
	Article   Article

	ExerciseID uint
	Exercise   Exercise
}

func ReadSessions

func ReadSessions(db *gorm.DB) ([]Session, error)

func (*Session) Update

func (session *Session) Update(db *gorm.DB) error

func (*Session) Write

func (session *Session) Write(db *gorm.DB) error

Jump to

Keyboard shortcuts

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