model

package
v0.0.0-...-0f3d56e Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortByUniqueKey

func SortByUniqueKey(slice interface{}) map[int]int

SortByUniqueKey sorts the given pointer to a slice of Model by UniqueKey, removes unnecessary nil-entries (except at position 0), and also updates the IDs accordingly. It tracks these changes by a map, for which the key represents the old ID, and value represents the new ID.

func UpdateIDs

func UpdateIDs(mdl interface{}, IDName string, changes map[int]int)

UpdateIDs updates a given ID (named by IDName) on the slice of *model.Model according to the given map, for which the key represents the old ID, and value represents the new ID.

Types

type BlockRange

type BlockRange struct {
	BlockRangeID int
	BlockType    int
	Identifier   int
	StartToken   sql.NullInt32
	EndToken     sql.NullInt32
	UserMarkID   int
}

BlockRange represents the BlockRange table inside the JW Library database

func (*BlockRange) Equals

func (m *BlockRange) Equals(m2 Model) bool

Equals checks if the BlockRange is equal to the given one.

func (*BlockRange) ID

func (m *BlockRange) ID() int

ID returns the ID of the entry

func (BlockRange) MakeSlice

func (BlockRange) MakeSlice(mdl []Model) []*BlockRange

MakeSlice converts a slice of the generice interface model

func (BlockRange) MarshalJSON

func (m BlockRange) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the entry

func (*BlockRange) PrettyPrint

func (m *BlockRange) PrettyPrint(db *Database) string

PrettyPrint prints BlockRange in a human readable format and adds information about related entries if helpful.

func (*BlockRange) RelatedEntries

func (m *BlockRange) RelatedEntries(db *Database) Related

RelatedEntries returns entries that are related to this one

func (*BlockRange) SetID

func (m *BlockRange) SetID(id int)

SetID sets the ID of the entry

func (*BlockRange) UniqueKey

func (m *BlockRange) UniqueKey() string

UniqueKey returns the key that makes this BlockRange unique, so it can be used as a key in a map.

type Bookmark

type Bookmark struct {
	BookmarkID            int
	LocationID            int
	PublicationLocationID int
	Slot                  int
	Title                 string
	Snippet               sql.NullString
	BlockType             int
	BlockIdentifier       sql.NullInt32
}

Bookmark represents the Bookmark table inside the JW Library database

func (*Bookmark) Equals

func (m *Bookmark) Equals(m2 Model) bool

Equals checks if the Bookmark is equal to the given one. The check won't include the BookmarkID

func (*Bookmark) ID

func (m *Bookmark) ID() int

ID returns the ID of the entry

func (Bookmark) MakeSlice

func (Bookmark) MakeSlice(mdl []Model) []*Bookmark

MakeSlice converts a slice of the generice interface model

func (Bookmark) MarshalJSON

func (m Bookmark) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the entry

func (*Bookmark) PrettyPrint

func (m *Bookmark) PrettyPrint(db *Database) string

PrettyPrint prints Bookmark in a human readable format and adds information about related entries if helpful.

func (*Bookmark) RelatedEntries

func (m *Bookmark) RelatedEntries(db *Database) Related

RelatedEntries returns entries that are related to this one

func (*Bookmark) SetID

func (m *Bookmark) SetID(id int)

SetID sets the ID of the entry

func (*Bookmark) UniqueKey

func (m *Bookmark) UniqueKey() string

UniqueKey returns the key that makes this Bookmark unique, so it can be used as a key in a map.

type Database

type Database struct {
	BlockRange []*BlockRange
	Bookmark   []*Bookmark
	InputField []*InputField
	Location   []*Location
	Note       []*Note
	Tag        []*Tag
	TagMap     []*TagMap
	UserMark   []*UserMark

	// ContainsPlaylists indicates if the imported backup contains playlists.
	ContainsPlaylists bool
	// SkipPlaylists allows to skip prevention of merging if playlists exist in the database.
	// It is meant as a temporary workaround until merging of playlists is implemented.
	SkipPlaylists bool
}

Database represents the JW Library database as a struct

func MakeDatabaseCopy

func MakeDatabaseCopy(db *Database) *Database

MakeDatabaseCopy creates a deep copy of the given Database, so elements of the copy can be safely updated without affecting the original one.

func (*Database) Equals

func (db *Database) Equals(other *Database) bool

Equals checks if all entries of a Database are equal.

func (*Database) ExportJWLBackup

func (db *Database) ExportJWLBackup(filename string) error

ExportJWLBackup creates a .jwlibrary backup file out of a Database{} struct

func (*Database) FetchFromTable

func (db *Database) FetchFromTable(tableName string, id int) Model

FetchFromTable tries to fetch a entry with the given ID. If it can't find it or the entry is empty it returns nil.

func (*Database) ImportJWLBackup

func (db *Database) ImportJWLBackup(filename string) error

ImportJWLBackup unzips a given JW Library Backup file and imports the included SQLite DB to the Database struct

func (*Database) PurgeTables

func (db *Database) PurgeTables(tables []string) error

PurgeTables removes all entries from the tables mentioned in the tables slice, which are named by the fields of the Database slice. If a table doesn't exist, an error will be returned.

type InputField

type InputField struct {
	LocationID int
	TextTag    string
	Value      string
	// contains filtered or unexported fields
}

InputField represents the InputField table inside the JW Library database

func (*InputField) Equals

func (m *InputField) Equals(m2 Model) bool

Equals checks if the InputField is equal to the given one.

func (*InputField) ID

func (m *InputField) ID() int

ID returns the ID of the entry. As the InputField table does not have an ID, we are using a pseudoID, so the rest of the merge logic is still able to run as usual.

func (InputField) MakeSlice

func (InputField) MakeSlice(mdl []Model) []*InputField

MakeSlice converts a slice of the generice interface model.

func (InputField) MarshalJSON

func (m InputField) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the entry.

func (*InputField) PrettyPrint

func (m *InputField) PrettyPrint(db *Database) string

PrettyPrint prints InputField in a human readable format and adds information about related entries if helpful.

func (*InputField) RelatedEntries

func (m *InputField) RelatedEntries(db *Database) Related

RelatedEntries returns entries that are related to this one.

func (*InputField) SetID

func (m *InputField) SetID(id int)

SetID sets the ID of the entry. As the InputField table does not have an ID, this function does nothing.

func (*InputField) UniqueKey

func (m *InputField) UniqueKey() string

UniqueKey returns the key that makes this InputField unique, so it can be used as a key in a map.

type Location

type Location struct {
	LocationID     int
	BookNumber     sql.NullInt32
	ChapterNumber  sql.NullInt32
	DocumentID     sql.NullInt32
	Track          sql.NullInt32
	IssueTagNumber int
	KeySymbol      sql.NullString
	MepsLanguage   sql.NullInt32
	LocationType   int
	Title          sql.NullString
}

Location represents the Location table inside the JW Library database

func (*Location) Equals

func (m *Location) Equals(m2 Model) bool

Equals checks if the Location is equal to the given one.

func (*Location) ID

func (m *Location) ID() int

ID returns the ID of the entry

func (Location) MakeSlice

func (Location) MakeSlice(mdl []Model) []*Location

MakeSlice converts a slice of the generice interface model

func (Location) MarshalJSON

func (m Location) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the entry

func (*Location) PrettyPrint

func (m *Location) PrettyPrint(db *Database) string

PrettyPrint prints Location in a human readable format and adds information about related entries if helpful.

func (*Location) RelatedEntries

func (m *Location) RelatedEntries(db *Database) Related

RelatedEntries returns entries that are related to this one

func (*Location) SetID

func (m *Location) SetID(id int)

SetID sets the ID of the entry

func (*Location) UniqueKey

func (m *Location) UniqueKey() string

UniqueKey returns the key that makes this Location unique, so it can be used as a key in a map.

type Model

type Model interface {
	ID() int
	SetID(int)
	UniqueKey() string
	Equals(m2 Model) bool
	RelatedEntries(db *Database) Related
	PrettyPrint(db *Database) string
	// contains filtered or unexported methods
}

Model represents a general table of the JW Library database and defines methods that are needed so entries are mergeable.

func MakeModelCopy

func MakeModelCopy(mdl Model) Model

MakeModelCopy copies the content of the given Model (pointer to a model-implementing struct) to a new Model

func MakeModelSlice

func MakeModelSlice(arg interface{}) ([]Model, error)

MakeModelSlice converts a slice of pointers of model-implementing structs to []model

type Note

type Note struct {
	NoteID          int
	GUID            string
	UserMarkID      sql.NullInt32
	LocationID      sql.NullInt32
	Title           sql.NullString
	Content         sql.NullString
	LastModified    string
	Created         string
	BlockType       int
	BlockIdentifier sql.NullInt32
}

Note represents the Note table inside the JW Library database

func (*Note) Equals

func (m *Note) Equals(m2 Model) bool

Equals checks if the Note is equal to the given one.

func (*Note) ID

func (m *Note) ID() int

ID returns the ID of the entry

func (Note) MakeSlice

func (Note) MakeSlice(mdl []Model) []*Note

MakeSlice converts a slice of the generice interface model

func (Note) MarshalJSON

func (m Note) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the entry

func (*Note) PrettyPrint

func (m *Note) PrettyPrint(db *Database) string

PrettyPrint prints Note in a human readable format and adds information about related entries if helpful.

func (*Note) RelatedEntries

func (m *Note) RelatedEntries(db *Database) Related

RelatedEntries returns entries that are related to this one

func (*Note) SetID

func (m *Note) SetID(id int)

SetID sets the ID of the entry

func (*Note) UniqueKey

func (m *Note) UniqueKey() string

UniqueKey returns the key that makes this Note unique, so it can be used as a key in a map.

type Related struct {
	BlockRange          []*BlockRange       `json:"blockRange"`
	Bookmark            *Bookmark           `json:"bookmark"`
	Location            *Location           `json:"location"`
	PublicationLocation *Location           `json:"publicationLocation"`
	Note                *Note               `json:"note"`
	Tag                 *Tag                `json:"tag"`
	TagMap              *TagMap             `json:"tagMap"`
	UserMark            *UserMark           `json:"userMark"`
	UserMarkBlockRange  *UserMarkBlockRange `json:"userMarkBlockRange"`
}

Related combines entries that are related to a given model

type Tag

type Tag struct {
	TagID   int
	TagType int
	Name    string
}

Tag represents the Tag table inside the JW Library database

func (*Tag) Equals

func (m *Tag) Equals(m2 Model) bool

Equals checks if the Tag is equal to the given one. The check won't include the TagID.

func (*Tag) ID

func (m *Tag) ID() int

ID returns the ID of the entry

func (Tag) MakeSlice

func (Tag) MakeSlice(mdl []Model) []*Tag

MakeSlice converts a slice of the generice interface model

func (Tag) MarshalJSON

func (m Tag) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the entry

func (*Tag) PrettyPrint

func (m *Tag) PrettyPrint(db *Database) string

PrettyPrint prints Tag in a human readable format and adds information about related entries if helpful.

func (*Tag) RelatedEntries

func (m *Tag) RelatedEntries(db *Database) Related

RelatedEntries returns entries that are related to this one

func (*Tag) SetID

func (m *Tag) SetID(id int)

SetID sets the ID of the entry

func (*Tag) UniqueKey

func (m *Tag) UniqueKey() string

UniqueKey returns the key that makes this Tag unique, so it can be used as a key in a map.

type TagMap

type TagMap struct {
	TagMapID       int
	PlaylistItemID sql.NullInt32
	LocationID     sql.NullInt32
	NoteID         sql.NullInt32
	TagID          int
	Position       int
}

TagMap represents the TagMap table inside the JW Library database

func (*TagMap) Equals

func (m *TagMap) Equals(m2 Model) bool

Equals checks if the TagMap is equal to the given one.

func (*TagMap) ID

func (m *TagMap) ID() int

ID returns the ID of the entry

func (TagMap) MakeSlice

func (TagMap) MakeSlice(mdl []Model) []*TagMap

MakeSlice converts a slice of the generice interface model

func (TagMap) MarshalJSON

func (m TagMap) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the entry

func (*TagMap) PrettyPrint

func (m *TagMap) PrettyPrint(db *Database) string

PrettyPrint prints TagMap in a human readable format and adds information about related entries if helpful.

func (*TagMap) RelatedEntries

func (m *TagMap) RelatedEntries(db *Database) Related

RelatedEntries returns entries that are related to this one

func (*TagMap) SetID

func (m *TagMap) SetID(id int)

SetID sets the ID of the entry

func (*TagMap) UniqueKey

func (m *TagMap) UniqueKey() string

UniqueKey returns the key that makes this TagMap unique, so it can be used as a key in a map.

type UserMark

type UserMark struct {
	UserMarkID   int
	ColorIndex   int
	LocationID   int
	StyleIndex   int
	UserMarkGUID string
	Version      int
}

UserMark represents the UserMark table inside the JW Library database

func (*UserMark) Equals

func (m *UserMark) Equals(m2 Model) bool

Equals checks if the UserMark is equal to the given one.

func (*UserMark) ID

func (m *UserMark) ID() int

ID returns the ID of the entry

func (UserMark) MakeSlice

func (UserMark) MakeSlice(mdl []Model) []*UserMark

MakeSlice converts a slice of the generice interface model

func (UserMark) MarshalJSON

func (m UserMark) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the entry

func (*UserMark) PrettyPrint

func (m *UserMark) PrettyPrint(db *Database) string

PrettyPrint prints UserMark in a human readable format and adds information about related entries if helpful.

func (*UserMark) RelatedEntries

func (m *UserMark) RelatedEntries(db *Database) Related

RelatedEntries returns entries that are related to this one

func (*UserMark) SetID

func (m *UserMark) SetID(id int)

SetID sets the ID of the entry

func (*UserMark) UniqueKey

func (m *UserMark) UniqueKey() string

UniqueKey returns the key that makes this UserMark unique, so it can be used as a key in a map.

type UserMarkBlockRange

type UserMarkBlockRange struct {
	UserMark    *UserMark
	BlockRanges []*BlockRange
}

UserMarkBlockRange represents a UserMark joined with its BlockRange entries. It does NOT represent an actual table in the JWLibrary backup file!

func (*UserMarkBlockRange) Equals

func (m *UserMarkBlockRange) Equals(m2 Model) bool

Equals checks if the UserMarkBlockRange is equal to the given one. It will both check its UserMark and all BlockRanges.

func (*UserMarkBlockRange) ID

func (m *UserMarkBlockRange) ID() int

ID returns the ID of the UserMark representing the whole UserMarkBlockRange{}

func (UserMarkBlockRange) MakeSlice

func (UserMarkBlockRange) MakeSlice(mdl []Model) []*UserMarkBlockRange

MakeSlice converts a slice of the generice interface model

func (UserMarkBlockRange) MarshalJSON

func (m UserMarkBlockRange) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the entry

func (*UserMarkBlockRange) PrettyPrint

func (m *UserMarkBlockRange) PrettyPrint(db *Database) string

PrettyPrint prints UserMarkBlockRange in a human readable format and adds information about related entries if helpful.

func (*UserMarkBlockRange) RelatedEntries

func (m *UserMarkBlockRange) RelatedEntries(db *Database) Related

RelatedEntries returns entries that are related to this one

func (*UserMarkBlockRange) SetID

func (m *UserMarkBlockRange) SetID(id int)

SetID sets the ID of the entry, which is the UserMarkID representing the whole UserMarkBlockRange{}

func (*UserMarkBlockRange) UniqueKey

func (m *UserMarkBlockRange) UniqueKey() string

UniqueKey returns the key that makes this UserMarkBlockRange unique, so it can be used as a key in a map.

Jump to

Keyboard shortcuts

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