dao

package
v0.0.0-...-83adff0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeywordTagDefaultLimit .
	KeywordTagDefaultLimit int = iota
	// KeywordTagRestrictLimit .
	KeywordTagRestrictLimit
	// KeywordTagWhite .
	KeywordTagWhite
	// KeywordTagBlack .
	KeywordTagBlack
)
View Source
const (
	// AreaReply .
	AreaReply int = iota + 1
	// AreaIMessage .
	AreaIMessage
	// AreaLiveDM .
	AreaLiveDM
	// AreaMainSiteDM .
	AreaMainSiteDM
)
View Source
const (
	// StateDefault .
	StateDefault int = iota
	// StateDeleted .
	StateDeleted
)
View Source
const (
	// OperationLimit .
	OperationLimit int = iota
	// OperationPutToWhiteList .
	OperationPutToWhiteList
	// OperationRestrictLimit .
	OperationRestrictLimit
	// OperationIgnore .
	OperationIgnore
)
View Source
const (
	// LimitTypeDefaultLimit .
	LimitTypeDefaultLimit int = iota
	// LimitTypeRestrictLimit .
	LimitTypeRestrictLimit
	// LimitTypeWhite .
	LimitTypeWhite
	// LimitTypeBlack .
	LimitTypeBlack
)
View Source
const (
	// LimitScopeGlobal .
	LimitScopeGlobal int = iota
	// LimitScopeLocal .
	LimitScopeLocal
)

Variables

View Source
var (
	// ErrPingDao .
	ErrPingDao = errors.New("Ping dao error")
	// ErrResourceNotExist .
	ErrResourceNotExist = errors.New("Resource Not Exist")
	// ErrParams .
	ErrParams = errors.New("wrong params")
)

Functions

func Close

func Close()

Close .

func GetTotalCounts

func GetTotalCounts(ctx context.Context, q Querier, selectCountsSQL string) (int64, error)

GetTotalCounts .

func Init

func Init(conf *conf.Config) (ok bool)

Init .

func PingMySQL

func PingMySQL(ctx context.Context) error

PingMySQL .

Types

type Condition

type Condition struct {
	*util.Pagination

	Offset string
	Limit  string

	Tags     []string
	Contents []string

	Area      string
	Search    string
	State     string
	HitCounts string

	Order, OrderBy        string
	LimitType, LimitScope string
	StartTime, EndTime    string
	LastModifiedTime      string
}

Condition .

type Dao

type Dao struct {
	// contains filtered or unexported fields
}

Dao .

func New

func New(c *conf.Config) (d *Dao)

New a dao and return.

func (*Dao) AllSendersCache

func (d *Dao) AllSendersCache(c context.Context, keywordID int64) ([]string, error)

AllSendersCache .

func (*Dao) AreaSendersExpire

func (d *Dao) AreaSendersExpire(c context.Context, area string, senderID, dur int64) error

AreaSendersExpire .

func (*Dao) Close

func (d *Dao) Close()

Close close all connection.

func (*Dao) CntSendersCache

func (d *Dao) CntSendersCache(c context.Context, keywordID int64) (cnt int64, err error)

CntSendersCache .

func (*Dao) DelCountRelatedCache

func (d *Dao) DelCountRelatedCache(c context.Context, k *model.Keyword) error

DelCountRelatedCache .

func (*Dao) DelKeywordRelatedCache

func (d *Dao) DelKeywordRelatedCache(c context.Context, ks []*model.Keyword) error

DelKeywordRelatedCache .

func (*Dao) DelRegexpCache

func (d *Dao) DelRegexpCache(c context.Context) error

DelRegexpCache .

func (*Dao) DelRulesCache

func (d *Dao) DelRulesCache(c context.Context, area, limitType string) error

DelRulesCache .

func (*Dao) GlobalLimitExpire

func (d *Dao) GlobalLimitExpire(c context.Context, keywordID, dur int64) error

GlobalLimitExpire .

func (*Dao) GlobalLocalLimitCache

func (d *Dao) GlobalLocalLimitCache(c context.Context, keywordID, oid int64) ([]int64, error)

GlobalLocalLimitCache .

func (*Dao) IncrAreaSendersCache

func (d *Dao) IncrAreaSendersCache(c context.Context, area string, senderID int64) (int64, error)

IncrAreaSendersCache .

func (*Dao) IncrGlobalLimitCache

func (d *Dao) IncrGlobalLimitCache(c context.Context, keywordID int64) (int64, error)

IncrGlobalLimitCache .

func (*Dao) IncrLocalLimitCache

func (d *Dao) IncrLocalLimitCache(c context.Context, keywordID, oid int64) (int64, error)

IncrLocalLimitCache .

func (*Dao) IncrTotalLimitCache

func (d *Dao) IncrTotalLimitCache(c context.Context, keywordID int64) (int64, error)

IncrTotalLimitCache .

func (*Dao) LocalLimitExpire

func (d *Dao) LocalLimitExpire(c context.Context, keywordID, oid, dur int64) error

LocalLimitExpire .

func (*Dao) Ping

func (d *Dao) Ping(c context.Context) (err error)

Ping check connection used in dao

func (*Dao) SendersCache

func (d *Dao) SendersCache(c context.Context, keywordID, limit, offset int64) ([]string, error)

SendersCache .

func (*Dao) TotalLimitExpire

func (d *Dao) TotalLimitExpire(c context.Context, keywordID, dur int64) error

TotalLimitExpire .

func (*Dao) ZaddSendersCache

func (d *Dao) ZaddSendersCache(c context.Context, keywordID, score, senderID int64) (int64, error)

ZaddSendersCache insert into sortedset and return total counts of sorted set

func (*Dao) ZremSendersCache

func (d *Dao) ZremSendersCache(c context.Context, keywordID int64, senderIDStr string) (int64, error)

ZremSendersCache return the number of memebers removed from the sorted set

type Executer

type Executer interface {
	Exec(ctx context.Context, SQL string, args ...interface{}) (sql.Result, error)
}

Executer .

type Keyword

type Keyword struct {
	ID            int64  `db:"id"`
	Area          int    `db:"area"`
	Tag           int    `db:"tag"`
	State         int    `db:"state"`
	HitCounts     int64  `db:"hit_counts"`
	RegexpName    string `db:"regexp_name"`
	Content       string `db:"content"`
	OriginContent string `db:"origin_content"`

	CTime time.Time `db:"ctime"`
	MTime time.Time `db:"mtime"`
}

Keyword .

type KeywordDao

type KeywordDao interface {
	GetByID(context.Context, int64) (*Keyword, error)
	GetByIDs(context.Context, []int64) ([]*Keyword, error)
	GetByCond(context.Context, *Condition) ([]*Keyword, int64, error)
	GetByOffsetLimit(context.Context, *Condition) ([]*Keyword, error)
	GetByAreaAndContents(context.Context, *Condition) ([]*Keyword, error)
	GetByAreaAndContent(context.Context, *Condition) (*Keyword, error)
	GetRubbish(context.Context, *Condition) ([]*Keyword, error)

	Insert(context.Context, *Keyword) (*Keyword, error)
	Update(context.Context, *Keyword) (*Keyword, error)
	DeleteByIDs(context.Context, []int64) ([]*Keyword, error)
}

KeywordDao .

type KeywordDaoImpl

type KeywordDaoImpl struct{}

KeywordDaoImpl .

func NewKeywordDao

func NewKeywordDao() *KeywordDaoImpl

NewKeywordDao .

func (*KeywordDaoImpl) DeleteByIDs

func (kdi *KeywordDaoImpl) DeleteByIDs(ctx context.Context, ids []int64) ([]*Keyword, error)

DeleteByIDs .

func (*KeywordDaoImpl) GetByAreaAndContent

func (kdi *KeywordDaoImpl) GetByAreaAndContent(ctx context.Context,
	cond *Condition) (*Keyword, error)

GetByAreaAndContent .

func (*KeywordDaoImpl) GetByAreaAndContents

func (*KeywordDaoImpl) GetByAreaAndContents(ctx context.Context,
	cond *Condition) ([]*Keyword, error)

GetByAreaAndContents .

func (*KeywordDaoImpl) GetByCond

func (*KeywordDaoImpl) GetByCond(ctx context.Context, cond *Condition) (keywords []*Keyword, totalCounts int64, err error)

GetByCond .

func (*KeywordDaoImpl) GetByID

func (kdi *KeywordDaoImpl) GetByID(ctx context.Context, id int64) (*Keyword, error)

GetByID .

func (*KeywordDaoImpl) GetByIDs

func (*KeywordDaoImpl) GetByIDs(ctx context.Context, ids []int64) ([]*Keyword, error)

GetByIDs .

func (*KeywordDaoImpl) GetByOffsetLimit

func (*KeywordDaoImpl) GetByOffsetLimit(ctx context.Context, cond *Condition) (keywords []*Keyword, err error)

GetByOffsetLimit .

func (*KeywordDaoImpl) GetRubbish

func (*KeywordDaoImpl) GetRubbish(ctx context.Context, cond *Condition) (keywords []*Keyword, err error)

GetRubbish .

func (*KeywordDaoImpl) Insert

func (kdi *KeywordDaoImpl) Insert(ctx context.Context, k *Keyword) (*Keyword, error)

Insert .

func (*KeywordDaoImpl) Update

func (kdi *KeywordDaoImpl) Update(ctx context.Context,
	k *Keyword) (*Keyword, error)

Update .

type KeywordTx

type KeywordTx interface {
	InsertKeyword(*Keyword) error
	UpdateKeyword(*Keyword) error
}

KeywordTx .

type Querier

type Querier interface {
	QueryRow(ctx context.Context, SQL string, args ...interface{}) *xsql.Row
	Query(ctx context.Context, SQL string, args ...interface{}) (*xsql.Rows, error)
}

Querier .

type Regexp

type Regexp struct {
	ID        int64     `db:"id"`
	Area      int       `db:"area"`
	Name      string    `db:"name"`
	AdminID   int64     `db:"admin_id"`
	Operation int       `db:"operation"`
	Content   string    `db:"content"`
	State     int       `db:"state"`
	CTime     time.Time `db:"ctime"`
	MTime     time.Time `db:"mtime"`
}

Regexp .

type RegexpDao

type RegexpDao interface {
	GetByID(context.Context, int64) (*Regexp, error)
	GetByIDs(context.Context, []int64) ([]*Regexp, error)
	GetByCond(context.Context, *Condition) ([]*Regexp, int64, error)
	GetByAreaAndContent(context.Context, *Condition) (*Regexp, error)
	GetByContents(context.Context, []string) ([]*Regexp, error)

	Insert(context.Context, *Regexp) (*Regexp, error)
	Update(context.Context, *Regexp) (*Regexp, error)
}

RegexpDao .

type RegexpDaoImpl

type RegexpDaoImpl struct{}

RegexpDaoImpl .

func NewRegexpDao

func NewRegexpDao() *RegexpDaoImpl

NewRegexpDao .

func (*RegexpDaoImpl) GetByAreaAndContent

func (*RegexpDaoImpl) GetByAreaAndContent(ctx context.Context, cond *Condition) (*Regexp, error)

GetByAreaAndContent .

func (*RegexpDaoImpl) GetByCond

func (*RegexpDaoImpl) GetByCond(ctx context.Context,
	cond *Condition) (regexps []*Regexp, totalCounts int64, err error)

GetByCond .

func (*RegexpDaoImpl) GetByContents

func (*RegexpDaoImpl) GetByContents(ctx context.Context, contents []string) ([]*Regexp, error)

GetByContents .

func (*RegexpDaoImpl) GetByID

func (rdi *RegexpDaoImpl) GetByID(ctx context.Context, id int64) (*Regexp, error)

GetByID .

func (*RegexpDaoImpl) GetByIDs

func (*RegexpDaoImpl) GetByIDs(ctx context.Context, ids []int64) ([]*Regexp, error)

GetByIDs .

func (*RegexpDaoImpl) Insert

func (rdi *RegexpDaoImpl) Insert(ctx context.Context, r *Regexp) (*Regexp, error)

Insert .

func (*RegexpDaoImpl) Update

func (rdi *RegexpDaoImpl) Update(ctx context.Context, r *Regexp) (*Regexp, error)

Update .

type RegexpTx

type RegexpTx interface {
	InsertRegexp(*Regexp) error
	UpdateRegexp(*Regexp) error
}

RegexpTx .

type Rule

type Rule struct {
	ID            int64 `db:"id"`
	Area          int   `db:"area"`
	LimitType     int   `db:"limit_type"`
	LimitScope    int   `db:"limit_scope"`
	DurationSec   int64 `db:"dur_sec"`
	AllowedCounts int64 `db:"allowed_counts"`

	CTime time.Time `db:"ctime"`
	MTime time.Time `db:"mtime"`
}

Rule .

type RuleDao

type RuleDao interface {
	GetByID(context.Context, int64) (*Rule, error)
	GetByIDs(context.Context, []int64) ([]*Rule, error)
	GetByCond(context.Context, *Condition) ([]*Rule, int64, error)
	GetByArea(context.Context, *Condition) ([]*Rule, error)
	GetByAreaAndTypeAndScope(context.Context, *Condition) (*Rule, error)
	GetByAreaAndLimitType(context.Context, *Condition) ([]*Rule, error)

	Insert(context.Context, *Rule) (*Rule, error)
	Update(context.Context, *Rule) (*Rule, error)
}

RuleDao .

type RuleDaoImpl

type RuleDaoImpl struct{}

RuleDaoImpl .

func NewRuleDao

func NewRuleDao() *RuleDaoImpl

NewRuleDao .

func (*RuleDaoImpl) GetByArea

func (*RuleDaoImpl) GetByArea(ctx context.Context, cond *Condition) ([]*Rule, error)

GetByArea .

func (*RuleDaoImpl) GetByAreaAndLimitType

func (*RuleDaoImpl) GetByAreaAndLimitType(ctx context.Context, cond *Condition) ([]*Rule, error)

GetByAreaAndLimitType .

func (*RuleDaoImpl) GetByAreaAndTypeAndScope

func (*RuleDaoImpl) GetByAreaAndTypeAndScope(ctx context.Context, cond *Condition) (*Rule, error)

GetByAreaAndTypeAndScope .

func (*RuleDaoImpl) GetByCond

func (*RuleDaoImpl) GetByCond(ctx context.Context, cond *Condition) (rules []*Rule, totalCounts int64, err error)

GetByCond .

func (*RuleDaoImpl) GetByID

func (rdi *RuleDaoImpl) GetByID(ctx context.Context, id int64) (*Rule, error)

GetByID .

func (*RuleDaoImpl) GetByIDs

func (*RuleDaoImpl) GetByIDs(ctx context.Context, ids []int64) ([]*Rule, error)

GetByIDs .

func (*RuleDaoImpl) Insert

func (rdi *RuleDaoImpl) Insert(ctx context.Context, r *Rule) (*Rule, error)

Insert .

func (*RuleDaoImpl) Update

func (rdi *RuleDaoImpl) Update(ctx context.Context, r *Rule) (*Rule, error)

Update .

type RuleTx

type RuleTx interface {
	InsertRule(*Rule) error
	UpdateRule(*Rule) error
}

RuleTx .

type Tx

type Tx interface {
	Executer

	RegexpTx
	KeywordTx
	RuleTx

	Commit() error
	Rollback() error
}

Tx .

Jump to

Keyboard shortcuts

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