database

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessKeys

type AccessKeys struct {
	// gorm.Model
	Key       string    `gorm:"column:key; primarykey"` // key
	UID       int       `gorm:"column:uid"`             // 用户 ID
	CreatedAt time.Time `gorm:"column:created_at"`      // 创建时间
	UpdatedAt time.Time `gorm:"column:updated_at"`      // 更新时间
}

AccessKeys key 缓存

type Area

type Area int

Area 地区

const (
	AreaNone Area = iota
	AreaCN
	AreaHK
	AreaTW
	AreaTH
)

Area

type Config

type Config struct {
	Host     string
	User     string
	Password string
	DBName   string
	Port     int
}

Config database configurations

type Database

type Database struct {
	*gorm.DB
}

Database database helper

func NewDBConnection

func NewDBConnection(c *Config) (*Database, error)

NewDBConnection new database connection

func (*Database) CleanupAccessKeys

func (db *Database) CleanupAccessKeys(duration time.Duration) (int64, error)

CleanupAccessKeys cleanup access keys if exceeds duration

func (*Database) CleanupPlayURLCache

func (db *Database) CleanupPlayURLCache(duration time.Duration) (int64, error)

CleanupPlayURLCache cleanup playurl if exceeds duration

func (*Database) CleanupTHSeasonCache

func (db *Database) CleanupTHSeasonCache(duration time.Duration) (int64, error)

CleanupTHSeasonCache cleanup th season if exceeds duration

func (*Database) CleanupTHSubtitleCache

func (db *Database) CleanupTHSubtitleCache(duration time.Duration) (int64, error)

CleanupTHSubtitleCache cleanup th subtitle if exceeds duration

func (*Database) CleanupUsers

func (db *Database) CleanupUsers(duration time.Duration) (int64, error)

CleanupUsers cleanup users if exceeds duration

func (*Database) GetKey

func (db *Database) GetKey(key string) (*AccessKeys, error)

GetKey get access key data

func (*Database) GetPlayURLCache

func (db *Database) GetPlayURLCache(deviceType DeviceType, area Area, isVIP bool, cid int, episodeID int) (*PlayURLCache, error)

GetPlayURLCache get play url caching with device type, area, cid or episode ID

func (*Database) GetTHSeasonCache

func (db *Database) GetTHSeasonCache(seasonID int) (*THSeasonCache, error)

GetTHSeasonCache get season api cache from season id

func (*Database) GetTHSubtitleCache

func (db *Database) GetTHSubtitleCache(episodeID int) (*THSubtitleCache, error)

GetTHSubtitleCache get th subtitle api cache from season id

func (*Database) GetUser

func (db *Database) GetUser(uid int) (*Users, error)

GetUser get user from uid

func (*Database) InsertOrUpdateKey

func (db *Database) InsertOrUpdateKey(key string, uid int) (int64, error)

InsertOrUpdateKey insert or update access key data

func (*Database) InsertOrUpdatePlayURLCache

func (db *Database) InsertOrUpdatePlayURLCache(deviceType DeviceType, area Area, isVIP bool, cid int, episodeID int, jsonData string) (int64, error)

InsertOrUpdatePlayURLCache insert or update play url cache data

func (*Database) InsertOrUpdateTHSeasonCache

func (db *Database) InsertOrUpdateTHSeasonCache(seasonID int, jsonData string) (int64, error)

InsertOrUpdateTHSeasonCache insert or update season api cache

func (*Database) InsertOrUpdateTHSubtitleCache

func (db *Database) InsertOrUpdateTHSubtitleCache(episodeID int, jsonData string) (int64, error)

InsertOrUpdateTHSubtitleCache insert or update th subtitle api cache

func (*Database) InsertOrUpdateUser

func (db *Database) InsertOrUpdateUser(uid int, name string, vipDueDate time.Time) (int64, error)

InsertOrUpdateUser insert or update user data

type DeviceType

type DeviceType int

DeviceType 装置种类

const (
	DeviceTypeWeb DeviceType = iota
	DeviceTypeAndroid
)

DeviceType

type PlayURLCache

type PlayURLCache struct {
	ID         uint       `gorm:"column:id; primarykey"` // ...
	IsVip      bool       `gorm:"column:is_vip"`         // 大会员
	CID        int        `gorm:"column:cid"`            // cid
	Area       Area       `gorm:"column:area"`           // 地区
	DeviceType DeviceType `gorm:"column:device_type"`    // 装置种类
	EpisodeID  int        `gorm:"column:episode_id"`     // 剧集 ID
	JSONData   string     `gorm:"column:json_data"`      // 内容
	CreatedAt  time.Time  `gorm:"column:created_at"`     // 创建时间
	UpdatedAt  time.Time  `gorm:"column:updated_at"`     // 更新时间
}

PlayURLCache 播放链接缓存

type THSeasonCache

type THSeasonCache struct {
	SeasonID  int       `gorm:"column:season_id; primarykey"` // ...
	JSONData  string    `gorm:"column:json_data"`             // 内容
	CreatedAt time.Time `gorm:"column:created_at"`            // 创建时间
	UpdatedAt time.Time `gorm:"column:updated_at"`            // 更新时间
}

THSeasonCache season 缓存

type THSubtitleCache

type THSubtitleCache struct {
	EpisodeID int       `gorm:"column:episode_id; primarykey"` // ...
	JSONData  string    `gorm:"column:json_data"`              // 内容
	CreatedAt time.Time `gorm:"column:created_at"`             // 创建时间
	UpdatedAt time.Time `gorm:"column:updated_at"`             // 更新时间
}

THSubtitleCache 字幕缓存

type Users

type Users struct {
	UID        int       `gorm:"column:uid; primarykey"` // 用户 ID
	VIPDueDate time.Time `gorm:"column:vip_due_date"`    // VIP 到期时间
	Name       string    `gorm:"column:name"`            // 用户暱称
	CreatedAt  time.Time `gorm:"column:created_at"`      // 创建时间
	UpdatedAt  time.Time `gorm:"column:updated_at"`      // 更新时间
}

Users 用户资料

Jump to

Keyboard shortcuts

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