mysql_db

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetByteLenByPartitionCount

func GetByteLenByPartitionCount(count int) int

func GetFnv128

func GetFnv128(data string) string

func GetMd5

func GetMd5(data string) string

func GetNewShortLinkDb

func GetNewShortLinkDb(config *MysqlDbConfig) db_base.ShortLinkDbInterface

func GetShortLinkPrefix

func GetShortLinkPrefix(partitionCount int, tableNum int) string

func GetTableNumFromRawLinkKey

func GetTableNumFromRawLinkKey(partitionCount int, key string) int

func GetTableNumFromShortLinkPath

func GetTableNumFromShortLinkPath(partitionCount int, shortLinkPath string) int

func GetUrlShortKey

func GetUrlShortKey(url string) string

func HexStrToInt64

func HexStrToInt64(hexStr string) uint64

func Int64ToHexStr

func Int64ToHexStr(n uint64) string

func MsTimeStampToTime

func MsTimeStampToTime(timeStamp int64) time.Time

Types

type MysqlDbConfig

type MysqlDbConfig struct {
	User           string
	Password       string
	Addr           string
	Port           int64
	DatabaseName   string
	PartitionCount int
}

type ShortLinkDao

type ShortLinkDao struct {
	Config MysqlDbConfig
	Engine *xorm.Engine
}
func (d *ShortLinkDao) DeleteShortLink(ctx context.Context, shortLinkPath string) error

TODO: add delete table, and reuse the deleted short path

func (d *ShortLinkDao) GenShortLink(ctx context.Context, rawLink string) (*db_base.ShortLink, error)

func (*ShortLinkDao) GenShortLinkWithExpire

func (d *ShortLinkDao) GenShortLinkWithExpire(ctx context.Context, rawLink string, expireAt time.Time) (*db_base.ShortLink, error)
func (d *ShortLinkDao) GetByRawLink(ctx context.Context, rawLink string) (*db_base.ShortLink, error)

func (*ShortLinkDao) GetByShortLinkPath

func (d *ShortLinkDao) GetByShortLinkPath(ctx context.Context, shortLinkPath string) (*db_base.ShortLink, error)

func (*ShortLinkDao) Init

func (d *ShortLinkDao) Init(config *MysqlDbConfig) error

func (*ShortLinkDao) SetShortLinkExpire

func (d *ShortLinkDao) SetShortLinkExpire(ctx context.Context, shortLinkPath string, expireAt time.Time) error

type ShortLinkTab

type ShortLinkTab struct {
	Id              int64  `xorm:"pk autoincr BIGINT(20)"`
	ShortLinkType   int    `xorm:"INT(11)"`
	ShortLinkPath   string `xorm:"not null VARCHAR(64)"`
	RawLinkKey      string `xorm:"not null unique VARCHAR(64)"` // md5 + fnv128
	RawLink         string `xorm:"not null VARCHAR(2048)"`
	ExpireTimestamp int64  `xorm:"index BIGINT(20)"`
	CreateTimestamp int64  `xorm:"BIGINT(20)"`
	UpdateTimestamp int64  `xorm:"BIGINT(20)"`
}

Jump to

Keyboard shortcuts

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