db

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	Current *gorm.DB
}

DB is the storage for current DB

func Connect

func Connect() DB

Connect connects to DATABASE_URL

type Extra

type Extra struct {
	ID        string    `gorm:"primarykey" json:"id"`
	CreatedAt time.Time `json:"-"`
	UpdatedAt time.Time `json:"-"`

	Chinese     string `gorm:"index:,unique;not null" json:"chinese"`
	Pinyin      string `json:"pinyin"`
	English     string `gorm:"-" json:"english"`
	Type        string `gorm:"-" json:"type"`
	Description string `json:"description"`
	Tag         string `gorm:"-" json:"tag"`
}

Extra is user database model for Extra

func (*Extra) Create added in v0.2.2

func (u *Extra) Create(tx *gorm.DB) error

Create ensures q update

func (*Extra) Delete added in v0.2.2

func (u *Extra) Delete(tx *gorm.DB) error

Delete ensures q delete and quiz delete

func (*Extra) Update added in v0.2.2

func (u *Extra) Update(tx *gorm.DB) error

Update makes sure description and tag are always updated

type Library

type Library struct {
	ID        string `gorm:"primarykey" json:"id"`
	CreatedAt time.Time
	UpdatedAt time.Time

	Title       string      `gorm:"index:idx_library_user_title,unique;not null" json:"title"`
	Entries     StringArray `json:"entries"`
	Description string      `json:"description"`
	Tag         string      `gorm:"-" json:"tag"`
}

Library is user database model for Library

func (*Library) Create added in v0.2.2

func (u *Library) Create(tx *gorm.DB) error

Create creates along with q

func (*Library) Delete added in v0.2.2

func (u *Library) Delete(tx *gorm.DB) error

Delete ensures q delete

func (*Library) Update added in v0.2.2

func (u *Library) Update(tx *gorm.DB) error

Update makes sure description and tag are always updated

type Quiz

type Quiz struct {
	ID        string `gorm:"primaryKey" json:"id"`
	CreatedAt time.Time
	UpdatedAt time.Time

	// Entry references
	Entry     string `gorm:"index:quiz_unique_idx,unique;not null" json:"entry"`
	Type      string `gorm:"index:quiz_unique_idx,unique;not null;check:[type] in ('hanzi','vocab','sentence')" json:"type"`
	Direction string `gorm:"index:quiz_unique_idx,unique;not null;check:direction in ('se','ec','te')" json:"direction"`
	Source    string `gorm:"index;not null" json:"source"`

	Description string `gorm:"-"`
	Tag         string `gorm:"-"`

	// Quiz statistics
	SRSLevel    *int8      `gorm:"index"`
	NextReview  *time.Time `gorm:"index"`
	LastRight   *time.Time `gorm:"index" json:"lastRight"`
	LastWrong   *time.Time `gorm:"index"`
	RightStreak *uint      `gorm:"index"`
	WrongStreak *uint      `gorm:"index" json:"wrongStreak"`
	MaxRight    *uint      `gorm:"index"`
	MaxWrong    *uint      `gorm:"index"`
}

Quiz is the database model for quiz

func (*Quiz) Create added in v0.2.2

func (q *Quiz) Create(tx *gorm.DB) (err error)

Create ensures q update

func (*Quiz) Delete added in v0.2.2

func (q *Quiz) Delete(tx *gorm.DB) error

Delete ensures q delete

func (*Quiz) UpdateSRSLevel

func (q *Quiz) UpdateSRSLevel(dSRSLevel int8)

UpdateSRSLevel updates SRSLevel and also updates stats

type Sentence

type Sentence struct {
	gorm.Model

	Chinese string `gorm:"uniqueIndex"`
	English string
}

Sentence caches sentences from http://www.jukuu.com/search.php?q=%s

type StringArray

type StringArray []string

StringArray type that is compat with both SQLite and PostGres

func (*StringArray) Scan

func (sa *StringArray) Scan(value interface{}) error

Scan (internal) to-external method for StringArray Type

func (StringArray) Value

func (sa StringArray) Value() (driver.Value, error)

Value (internal) to-database method for StringArray Type

type User

type User struct {
	ID        string `gorm:"primaryKey"`
	CreatedAt time.Time
	UpdatedAt time.Time

	Meta UserMeta
}

User holds user data

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate forces single user

type UserMeta

type UserMeta struct {
	Forvo    *string `json:"forvo"`
	Level    *uint   `json:"level"`
	LevelMin *uint   `json:"levelMin"`
	Settings struct {
		Level struct {
			WhatToShow string `json:"whatToShow"`
		} `json:"level"`
		Quiz struct {
			Type         []string `json:"type"`
			Stage        []string `json:"stage"`
			Direction    []string `json:"direction"`
			IncludeUndue bool     `json:"includeUndue"`
			IncludeExtra bool     `json:"includeExtra"`
			Q            string   `json:"q"`
		} `json:"quiz"`
		Sentence struct {
			Min *uint `json:"min"`
			Max *uint `json:"max"`
		} `json:"sentence"`
	} `json:"settings"`
}

UserMeta holds User's settings

func (UserMeta) GormDBDataType

func (UserMeta) GormDBDataType(db *gorm.DB, _ *schema.Field) string

GormDBDataType represents UserMeta's data type

func (*UserMeta) Scan

func (j *UserMeta) Scan(value interface{}) error

Scan scan value into Jsonb, implements sql.Scanner interface

func (UserMeta) Value

func (j UserMeta) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface

Jump to

Keyboard shortcuts

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