db

package
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SUCCESS byte = iota
	WARM
	ERROR
)

Variables

View Source
var NoDatabase = &NoDatabaseError{}

Functions

func CreateMysqlConnection

func CreateMysqlConnection(username string, password string, host string, port int, dbname string, charset string) (db *gorm.DB, err error)

func GetMailsStr

func GetMailsStr(mails []*Mail) string

Types

type DB

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

func CreateDB

func CreateDB(storageRoot string) *DB

func (*DB) GetLogModel

func (d *DB) GetLogModel() *LogModel

func (*DB) GetMailModel

func (d *DB) GetMailModel() *MailModel

func (*DB) GetSMTPModel

func (d *DB) GetSMTPModel() *STMPModel

func (*DB) GetScheduleModel

func (d *DB) GetScheduleModel() *ScheduleModel

func (*DB) GetTokenModel

func (d *DB) GetTokenModel() *TokenModel

func (*DB) Init

func (d *DB) Init(config *config.Config) error

func (*DB) InitBySetInfo

func (d *DB) InitBySetInfo(setInfo *config.SetInfo) error

InitBySetInfo setInfo *config.SetInfo

type Data

type Data interface {
	*SMTP | any
}
type Header struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type IModel

type IModel interface {
	SetCreateTime(createTime time.Time)
	SetUpdateTime(updateTIme time.Time)
	GetId() uint
	SetId(id uint)
}

type Log

type Log struct {
	Id         uint      `gorm:"primaryKey;autoIncrement;column:id" json:"id"`
	Name       string    `gorm:"column:name" json:"name"`
	Mail       string    `gorm:"column:mail" json:"mail"`
	Token      string    `gorm:"column:token" json:"token"`
	SMTP       string    `gorm:"column:smtp" json:"smtp"`
	Subject    string    `gorm:"column:subject" json:"subject"`
	Content    string    `gorm:"column:content" json:"content"`
	Files      string    `gorm:"column:files" json:"files"`
	CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
	UpdateTime time.Time `gorm:"column:update_time" json:"updateTime"`
	Status     byte      `gorm:"column:status" json:"status"`
	StatusStr  string    `gorm:"-" json:"statusStr"`
	Result     string    `gorm:"column:result" json:"result"`
}

func (*Log) GetId

func (log *Log) GetId() uint

func (*Log) SetCreateTime

func (log *Log) SetCreateTime(createTime time.Time)

func (*Log) SetId

func (log *Log) SetId(id uint)

func (*Log) SetUpdateTime

func (log *Log) SetUpdateTime(updateTime time.Time)

type LogModel

type LogModel struct {
	*Model[*Log]
	// contains filtered or unexported fields
}

func NewLogModel

func NewLogModel(db *gorm.DB, tableName string) *LogModel

func (*LogModel) CreateTable

func (a *LogModel) CreateTable() error

func (*LogModel) DeleteTable

func (a *LogModel) DeleteTable() error

func (*LogModel) GetOne

func (a *LogModel) GetOne(id uint) (*Log, error)

func (*LogModel) Page

func (a *LogModel) Page(page *web.Page) (*Page[*Log], error)

func (*LogModel) PageBySearch added in v0.2.3

func (a *LogModel) PageBySearch(page *web.Page, key string) (*Page[*Log], error)

func (*LogModel) Save

func (a *LogModel) Save(log *Log) error

type Mail

type Mail struct {
	Id         uint      `gorm:"primaryKey;autoIncrement;column:id" json:"id"`
	Name       string    `gorm:"column:name" json:"name"`
	Mail       string    `gorm:"column:mail" json:"mail"`
	CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
	UpdateTime time.Time `gorm:"column:update_time" json:"updateTime"`
}

func GetMails

func GetMails(ids []uint, mailMap map[uint]*Mail) []*Mail

func (*Mail) GetId

func (mail *Mail) GetId() uint

func (*Mail) SetCreateTime

func (mail *Mail) SetCreateTime(createTime time.Time)

func (*Mail) SetId

func (mail *Mail) SetId(id uint)

func (*Mail) SetUpdateTime

func (mail *Mail) SetUpdateTime(updateTime time.Time)

type MailModel

type MailModel struct {
	*Model[*Mail]
	// contains filtered or unexported fields
}

func NewMailModel

func NewMailModel(db *gorm.DB, tableName string) *MailModel

func (*MailModel) CreateTable

func (a *MailModel) CreateTable() error

func (*MailModel) DeleteOne

func (a *MailModel) DeleteOne(id uint) error

func (*MailModel) DeleteTable

func (a *MailModel) DeleteTable() error

func (*MailModel) Edit

func (a *MailModel) Edit(mail *Mail) error

func (*MailModel) GetByIds

func (a *MailModel) GetByIds(id []uint) ([]*Mail, error)

func (*MailModel) GetMapByIds

func (a *MailModel) GetMapByIds(id []uint) (map[uint]*Mail, error)

func (*MailModel) GetOne

func (a *MailModel) GetOne(id uint) (*Mail, error)

func (*MailModel) NewModel

func (a *MailModel) NewModel(db *gorm.DB) *MailModel

func (*MailModel) Page

func (a *MailModel) Page(page *web.Page) (*Page[*Mail], error)

func (*MailModel) Save

func (a *MailModel) Save(mail *Mail) error

type Model

type Model[T IModel] struct {
	// contains filtered or unexported fields
}

func NewModel

func NewModel[T IModel](db *gorm.DB, tableName string) *Model[T]

func (*Model[T]) CreateTable

func (a *Model[T]) CreateTable(t T) error

func (*Model[T]) DeleteOne

func (a *Model[T]) DeleteOne(id uint, t T) error

func (*Model[T]) DeleteTable

func (a *Model[T]) DeleteTable(t T) error

func (*Model[T]) Edit

func (a *Model[T]) Edit(t T) error

func (*Model[T]) EditForMap

func (a *Model[T]) EditForMap(id uint, data map[string]interface{}) error

func (*Model[T]) GetByIds

func (a *Model[T]) GetByIds(id []uint, ts *[]T) error

func (*Model[T]) GetOne

func (a *Model[T]) GetOne(id uint, t T) error

func (*Model[T]) IsExist

func (a *Model[T]) IsExist() bool

func (*Model[T]) NewModel

func (a *Model[T]) NewModel(db *gorm.DB) *Model[T]

func (*Model[T]) Page

func (a *Model[T]) Page(page *web.Page, ts *[]T) (int, error)

func (*Model[T]) Save

func (a *Model[T]) Save(t T) error

type NoDatabaseError

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

func (*NoDatabaseError) Error

func (error *NoDatabaseError) Error() string

type Page

type Page[T Data] struct {
	Total int `json:"total"`
	List  []T `json:"list"`
}

func ToPage

func ToPage[T Data](total int, list []T) *Page[T]

type SMTP

type SMTP struct {
	Id         uint      `gorm:"primaryKey;autoIncrement;column:id" json:"id"`
	Host       string    `gorm:"column:host" json:"host"`
	Port       int       `gorm:"column:port" json:"port"`
	Mail       string    `gorm:"column:mail" json:"mail"`
	Username   string    `gorm:"column:username" json:"username"`
	Name       string    `gorm:"-"  json:"name"`
	Password   string    `gorm:"column:password"  json:"password"`
	CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
	UpdateTime time.Time `gorm:"column:update_time" json:"updateTime"`
}

func (*SMTP) GetId

func (smtp *SMTP) GetId() uint

func (*SMTP) SetCreateTime

func (smtp *SMTP) SetCreateTime(createTime time.Time)

func (*SMTP) SetId

func (smtp *SMTP) SetId(id uint)

func (*SMTP) SetUpdateTime

func (smtp *SMTP) SetUpdateTime(updateTime time.Time)

type STMPModel

type STMPModel struct {
	*Model[*SMTP]
	// contains filtered or unexported fields
}

func NewSMTPModel

func NewSMTPModel(db *gorm.DB, tableName string) *STMPModel

func (*STMPModel) CreateTable

func (a *STMPModel) CreateTable() error

func (*STMPModel) DeleteOne

func (a *STMPModel) DeleteOne(id uint) error

func (*STMPModel) DeleteTable

func (a *STMPModel) DeleteTable() error

func (*STMPModel) Edit

func (a *STMPModel) Edit(smtp *SMTP) error

func (*STMPModel) GetByIds

func (a *STMPModel) GetByIds(id []uint) ([]*SMTP, error)

func (*STMPModel) GetMapByIds

func (a *STMPModel) GetMapByIds(id []uint) (map[uint]*SMTP, error)

func (*STMPModel) GetOne

func (a *STMPModel) GetOne(id uint) (*SMTP, error)

func (*STMPModel) NewModel

func (a *STMPModel) NewModel(db *gorm.DB) *STMPModel

func (*STMPModel) Page

func (a *STMPModel) Page(page *web.Page) (*Page[*SMTP], error)

func (*STMPModel) Save

func (a *STMPModel) Save(stmp *SMTP) error

type Schedule

type Schedule struct {
	Id                uint      `gorm:"primaryKey;autoIncrement;column:id" json:"id"`
	Name              string    `gorm:"column:name" json:"name"`
	Token             string    `gorm:"column:token" json:"token"`
	TokenId           uint      `gorm:"-" json:"tokenId"`
	Cron              string    `gorm:"column:cron" json:"cron"`
	Url               string    `gorm:"column:url" json:"url"`
	Method            string    `gorm:"column:method" json:"method"`
	HeaderStr         string    `gorm:"column:header_str" json:"headerStr"`
	Headers           []*Header `gorm:"-" json:"headers"`
	Body              string    `gorm:"column:body" json:"body"`
	UseTemplate       bool      `gorm:"column:use_template" json:"useTemplate"`
	Template          string    `gorm:"column:template" json:"template"`
	IsUse             bool      `gorm:"column:is_use" json:"isUse"`
	IsOnlySendByError bool      `gorm:"column:is_only_send_by_error" json:"isSendOnlyByError"`
	CreateTime        time.Time `gorm:"column:create_time" json:"createTime"`
	UpdateTime        time.Time `gorm:"column:update_time" json:"updateTime"`
}

func (*Schedule) GetId

func (schedule *Schedule) GetId() uint

func (*Schedule) Key

func (schedule *Schedule) Key() string

func (*Schedule) SetCreateTime

func (schedule *Schedule) SetCreateTime(createTime time.Time)

func (*Schedule) SetId

func (schedule *Schedule) SetId(id uint)

func (*Schedule) SetUpdateTime

func (schedule *Schedule) SetUpdateTime(updateTIme time.Time)

type ScheduleModel

type ScheduleModel struct {
	*Model[*Schedule]
	// contains filtered or unexported fields
}

func NewScheduleModel

func NewScheduleModel(db *gorm.DB, tableName string) *ScheduleModel

func (*ScheduleModel) CreateTable

func (a *ScheduleModel) CreateTable() error

func (*ScheduleModel) DeleteOne

func (a *ScheduleModel) DeleteOne(id uint) error

func (*ScheduleModel) DeleteTable

func (a *ScheduleModel) DeleteTable() error

func (*ScheduleModel) Edit

func (a *ScheduleModel) Edit(schedule *Schedule) error

func (*ScheduleModel) FindAllByUse

func (a *ScheduleModel) FindAllByUse() ([]*Schedule, error)

func (*ScheduleModel) GetOne

func (a *ScheduleModel) GetOne(id uint) (*Schedule, error)

func (*ScheduleModel) NewModel

func (a *ScheduleModel) NewModel(db *gorm.DB) *ScheduleModel

func (*ScheduleModel) Page

func (a *ScheduleModel) Page(page *web.Page) (*Page[*Schedule], error)

func (*ScheduleModel) Save

func (a *ScheduleModel) Save(remoteRead *Schedule) error

type Token

type Token struct {
	Id               uint      `gorm:"primaryKey;autoIncrement;column:id" json:"id"`
	Token            string    `gorm:"unique;column:token" json:"token"`
	Name             string    `gorm:"-" json:"name"`
	Subject          string    `gorm:"column:subject" json:"subject"`
	ReceiveEmailIds  string    `gorm:"column:receive_emails" json:"receiveEmailIds"`
	ReceiveEmails    []*Mail   `gorm:"-" json:"receiveEmails"`
	ReceiveEmailsStr string    `gorm:"-" json:"receiveEmailsStr"`
	SMTPId           uint      `gorm:"column:SMTP_Id" json:"SMTPId"`
	SMTP             *SMTP     `gorm:"-" json:"SMTP"`
	SMTPStr          string    `gorm:"-" json:"SMTPStr"`
	IsUse            bool      `gorm:"column:is_use" json:"isUse"`
	CreateTime       time.Time `gorm:"column:create_time" json:"createTime"`
	UpdateTime       time.Time `gorm:"column:update_time" json:"updateTime"`
}

func (*Token) GetId

func (token *Token) GetId() uint

func (*Token) SetCreateTime

func (token *Token) SetCreateTime(createTime time.Time)

func (*Token) SetId

func (token *Token) SetId(id uint)

func (*Token) SetUpdateTime

func (token *Token) SetUpdateTime(updateTIme time.Time)

type TokenModel

type TokenModel struct {
	*Model[*Token]
	// contains filtered or unexported fields
}

func NewTokenModel

func NewTokenModel(db *gorm.DB, tableName string) *TokenModel

func (*TokenModel) CreateTable

func (a *TokenModel) CreateTable() error

func (*TokenModel) DeleteOne

func (a *TokenModel) DeleteOne(id uint) error

func (*TokenModel) DeleteTable

func (a *TokenModel) DeleteTable() error

func (*TokenModel) Edit

func (a *TokenModel) Edit(token *Token) error

func (*TokenModel) GetOne

func (a *TokenModel) GetOne(id uint) (*Token, error)

func (*TokenModel) GetOneByToken

func (a *TokenModel) GetOneByToken(tokenStr string) (*Token, error)

func (*TokenModel) NewModel

func (a *TokenModel) NewModel(db *gorm.DB) *TokenModel

func (*TokenModel) Page

func (a *TokenModel) Page(page *web.Page) (*Page[*Token], error)

func (*TokenModel) Save

func (a *TokenModel) Save(token *Token) error

Jump to

Keyboard shortcuts

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