Documentation
¶
Index ¶
- Constants
- Variables
- func AutoMigrateModels(db *gorm.DB) error
- func CreateIndexes(db *gorm.DB) error
- type Card
- type CardService
- type Col
- type Deck
- type Field
- type Grave
- type Note
- type NoteContentFormatter
- type NoteOption
- type NoteOptions
- type NoteService
- type RevLog
- type Storage
- type Template
- type TplModel
Constants ¶
const ( CardTypeNew = iota CardTypeLearning CardTypeReview CardTypeRelearning CardTypeDue )
todo: 猜测
const ( CardQueueTypeNew = iota CardQueueTypeLearning CardQueueTypeReview CardQueueTypeRelearning CardQueueTypeDue )
todo: 猜测
const ( VirtualDeckID = 170214000000 VirtualDeckName = "BK.EasyExport" SimpleTplID = 1000 )
const ApkgDBName = "collection.anki2"
const SplitFieldOfNote = "\x1f"
Variables ¶
var ( ErrNoteNotFound = errors.New("note not found") GlobalTags = []string{} )
ErrNoteNotFound is returned when a note cannot be found.
Functions ¶
func AutoMigrateModels ¶
AutoMigrateModels migrates the provided models and creates necessary indexes.
func CreateIndexes ¶
CreateIndexes creates database indexes to improve query performance.
Types ¶
type Card ¶
type Card struct {
ID int `gorm:"primaryKey;column:id" json:"id"` // Unique identifier for the card
// NID - Note ID
NID int `gorm:"column:nid" json:"nid"`
// DID - Deck ID
DID int `gorm:"column:did" json:"did"`
// Ord - Ordinal, identifies card's template
Ord int `gorm:"column:ord" json:"ord"`
Mod int64 `gorm:"column:mod" json:"mod"` // Last modified in milliseconds
Usn int `gorm:"column:usn" json:"usn"` // Update sequence number
// Type of the card: 0: New, 1: Learning, 2: Review, 3: Relearning
// 表示卡片的类型(如新的、学习中、待复习等)
Type int `gorm:"column:type" json:"type"`
// Queue the card is in (new, learning, due, etc.)
// 表示卡片当前所处的队列(如新的、学习中、待复习等)
Queue int `gorm:"column:queue" json:"queue"`
// // Due date for review. For new cards and learning cards this is the order in which they will be shown.
// 表示卡片的到期日期
Due int `gorm:"column:due" json:"due"`
// Interval (used in SRS algorithm). Determines if the review card is young (Ivl < 21) or mature (Ivl >= 21).
// 用于SRS算法的间隔时间,用于决定卡片是"年轻"还是"成熟"
Ivl int `gorm:"column:ivl" json:"ivl"`
Factor int `gorm:"column:factor" json:"factor"` // Ease factor (used in SRS algorithm)
Reps int `gorm:"column:reps" json:"reps"` // Number of reviews
Lapses int `gorm:"column:lapses" json:"lapses"` // Number of lapses
Left int `gorm:"column:left" json:"left"` // Steps left to graduation (in learning)
Odue int `gorm:"column:odue" json:"odue"` // Original due date (for cards in relearning)
Odid int `gorm:"column:odid" json:"odid"` // Original deck ID (for cards in filtered decks)
Flags int `gorm:"column:flags" json:"flags"` // Flags
Data string `gorm:"column:data" json:"data"` // Unused, currently just an empty string.
}
Card represents the 'cards' table which stores the information about the review cards generated from notes. Anki 卡片是通过笔记(Notes)和卡片类型(Card Types)相结合来实现的。每个笔记可以生成一个或多个卡
type CardService ¶
CardService provides methods to work with notes and cards.
func (*CardService) CreateCard ¶
func (cs *CardService) CreateCard(cid int, note *Note) (*Card, error)
CreateCard creates a new card based on the given front and back information.
func (*CardService) FindCardByFront ¶
func (cs *CardService) FindCardByFront(front string) ([]Note, []Card, error)
FindCardByFront finds notes and cards with the given front.
func (*CardService) GetAllFronts ¶
func (cs *CardService) GetAllFronts() ([]string, error)
GetAllFronts returns a slice of all fronts from notes.
type Col ¶
type Col struct {
ID int `gorm:"primaryKey;column:id" json:"id"` // Unique identifier for the collection
Crt int `gorm:"column:crt" json:"crt"` // Collection created time (timestamp)
Mod int64 `gorm:"column:mod" json:"mod"` // Last modified in milliseconds
Scm int64 `gorm:"column:scm" json:"scm"` // Schema modified time (used for syncing)
Ver int `gorm:"column:ver" json:"ver"` // Version of the collection
Dty int `gorm:"column:dty" json:"dty"` // Dirty (need to be synced)
Usn int `gorm:"column:usn" json:"usn"` // Update sequence number (for finding diffs when syncing)
Ls int `gorm:"column:ls" json:"ls"` // Last sync time
Conf string `gorm:"column:conf" json:"conf"` // Configuration JSON object
Models string `gorm:"column:models" json:"models"` // JSON object containing note models
Decks string `gorm:"column:decks" json:"decks"` // JSON object containing deck information
Dconf string `gorm:"column:dconf" json:"dconf"` // JSON object containing deck options
Tags string `gorm:"column:tags" json:"tags"` // A cache of tags used in the collection
}
Col represents the 'col' table which contains information about the collection like settings and statistics.
type Deck ¶
Deck Anki 的 apkg 管理实体, 一一对应 deck Ref: - official: https://docs.ankiweb.net/intro.html - open source: -- https://gist.github.com/sartak/3921255 -- https://github.com/SergioFacchini/anki-cards-web-browser/blob/master/documentation/Processing%20Anki's%20.apkg%20files.md
func CreateDeck ¶
CreateDeck initializes and returns a new Deck with a connected database.
func (*Deck) CardService ¶
func (deck *Deck) CardService() *CardService
func (*Deck) ExportToAPKG ¶
ExportToAPKG exports the database and associated files as an .apkg file.
func (*Deck) NoteService ¶
func (deck *Deck) NoteService() *NoteService
type Grave ¶
type Grave struct {
ID int `gorm:"primaryKey;column:id" json:"id"` // Unused, currently just set to zero
Usn int `gorm:"column:usn" json:"usn"` // Update sequence number
Oid int `gorm:"column:oid" json:"oid"` // Original ID (card, note, or deck id)
Type int `gorm:"column:type" json:"type"` // Type of object (card, note, or deck)
}
Grave represents the 'graves' table which logs deleted cards, notes, and decks.
type Note ¶
type Note struct {
ID int `gorm:"primaryKey;column:id" json:"id"` // Unique identifier for the note
Guid string `gorm:"column:guid" json:"guid"` // Globally unique id, used for syncing
// Mid - Model ID,
// links to card templates which define how to use the fields to generate "front" and "back" sides of cards.
Mid int `gorm:"column:mid" json:"mid"`
// Mod - Last modified in milliseconds
Mod int64 `gorm:"column:mod" json:"mod"`
// Usn - Update sequence number
Usn int `gorm:"column:usn" json:"usn"`
Tags string `gorm:"column:tags" json:"tags"` // Space-separated string of tags.
// FLDs - Fields of the note joined by 0x1f character.
// They are used by card templates to generate "front" and "back" sides of cards.
//
// - "Basic" notes have "Front" and "Back" fields for basic question-answer cards.
// - "Basic (and reversed card)" notes add a reversed card from the answer to the question alongside the basic card.
// - "Basic (optional reversed card)" has "Front", "Back", and "Add Reverse" fields, creating reversed cards when "Add Reverse" is filled.
// - "Cloze" notes are used to create fill-in-the-blank cards where text is omitted.
// - "Image Occlusion" notes utilize images with sections blocked out to test recognition of image parts.
FLDs string `gorm:"column:flds" json:"flds"`
// SFLD - Sort field: the value of the field by which notes are sorted in the browser.
SFLD int `gorm:"column:sfld" json:"sfld"`
CSum int64 `gorm:"column:csum" json:"csum"` // Checksum used for duplicate check.
Flags int `gorm:"column:flags" json:"flags"` // Flags
Data string `gorm:"column:data" json:"data"` // Unused, currently just an empty string.
}
Note represents the 'notes' table which stores all the information of notes including metadata and the content itself.
type NoteContentFormatter ¶
type NoteContentFormatter string
const ( NoteCFmtPlainText NoteContentFormatter = "" NoteCFmtMarkdown = "markdown" )
type NoteOption ¶
type NoteOption func(*NoteOptions)
NoteOption configures NoteOptions.
func NoteWithContentFormatter ¶
func NoteWithContentFormatter(contentFmt NoteContentFormatter) NoteOption
func NoteWithGUID ¶
func NoteWithGUID(guid string) NoteOption
func NoteWithNID ¶
func NoteWithNID(nid int) NoteOption
func NoteWithTags ¶
func NoteWithTags(tags ...string) NoteOption
type NoteOptions ¶
type NoteOptions struct {
NID int `json:"nid,omitempty"`
GUID string `json:"guid,omitempty"`
Tags []string `json:"tags,omitempty"`
ContentFormatter NoteContentFormatter `json:"note_content_formatter,omitempty"`
}
NoteOptions includes options for creating a new note.
func (*NoteOptions) Use ¶
func (no *NoteOptions) Use(opts ...NoteOption) *NoteOptions
type NoteService ¶
NoteService provides methods to work with notes and cards.
func (*NoteService) CreateNote ¶
func (cs *NoteService) CreateNote(ctx context.Context, front, back string, opts ...NoteOption) (*Note, error)
type RevLog ¶
type RevLog struct {
ID int64 `gorm:"primaryKey;column:id" json:"id"` // Timestamp (based on 13 digits), used as ID
Cid int `gorm:"column:cid" json:"cid"` // Card ID
// Usn - Update sequence number
Usn int `gorm:"column:usn" json:"usn"`
Ease int `gorm:"column:ease" json:"ease"` // Ease button pressed (again, hard, good, easy)
Ivl int `gorm:"column:ivl" json:"ivl"` // New interval
LastIvl int `gorm:"column:lastIvl" json:"lastIvl"` // Last interval
Factor int `gorm:"column:factor" json:"factor"` // New ease factor
Time int `gorm:"column:time" json:"time"` // Review time in milliseconds
Type int `gorm:"column:type" json:"type"` // Review type
}
RevLog represents the 'revlog' table which stores the review logs of cards.
type Storage ¶
func CreateInMemStorage ¶
type TplModel ¶
type TplModel struct {
ID int `json:"id"`
Tmpls []Template `json:"tmpls"`
LatexPre string `json:"latexPre"`
Req []any `json:"req"`
Flds []Field `json:"flds"`
Tags []string `json:"tags"`
Type int `json:"type"`
Mod int64 `json:"mod"`
LatexSVG int `json:"latexsvg"`
Sortf int `json:"sortf"`
Usn int `json:"usn"`
Did int `json:"did"`
Vers []interface{} `json:"vers"`
LatexPost string `json:"latexPost"`
Name string `json:"name"`
Css string `json:"css"`
Gf bool `json:"gf"`
}