db

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 9 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)

Types

type DB

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

func CreateDB

func CreateDB() *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) 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 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) 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 (*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 RemoteRead added in v0.1.14

type RemoteRead struct {
	Id          uint      `gorm:"primaryKey;autoIncrement;column:id" json:"id"`
	Url         string    `gorm:"column:url" json:"url"`
	Header      string    `gorm:"column:Header" json:"header"`
	Method      string    `gorm:"column:method" json:"method"`
	Body        string    `gorm:"column:body" json:"body"`
	BodyFormat  string    `gorm:"column:body_format" json:"bodyFormat"`
	ContentType string    `gorm:"column:content_type" json:"contentType"`
	CreateTime  time.Time `gorm:"column:create_time" json:"createTime"`
	UpdateTime  time.Time `gorm:"column:update_time" json:"updateTime"`
}

func (*RemoteRead) GetId added in v0.1.14

func (token *RemoteRead) GetId() uint

func (*RemoteRead) SetCreateTime added in v0.1.14

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

func (*RemoteRead) SetId added in v0.1.14

func (token *RemoteRead) SetId(id uint)

func (*RemoteRead) SetUpdateTime added in v0.1.14

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

type RemoteReadModel added in v0.1.14

type RemoteReadModel struct {
	*Model[*RemoteRead]
	// contains filtered or unexported fields
}

func NewRemoteReadModel added in v0.1.14

func NewRemoteReadModel(db *gorm.DB, tableName string) *RemoteReadModel

func (*RemoteReadModel) CreateTable added in v0.1.14

func (a *RemoteReadModel) CreateTable() error

func (*RemoteReadModel) DeleteOne added in v0.1.14

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

func (*RemoteReadModel) DeleteTable added in v0.1.14

func (a *RemoteReadModel) DeleteTable() error

func (*RemoteReadModel) GetOne added in v0.1.14

func (a *RemoteReadModel) GetOne(id uint) (*RemoteRead, error)

func (*RemoteReadModel) NewModel added in v0.1.14

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

func (*RemoteReadModel) Page added in v0.1.14

func (a *RemoteReadModel) Page(page *web.Page) (*Page[*RemoteRead], error)

func (*RemoteReadModel) Save added in v0.1.14

func (a *RemoteReadModel) Save(remoteRead *RemoteRead) error

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 Token

type Token struct {
	Id               uint      `gorm:"primaryKey;autoIncrement;column:id" json:"id"`
	Token            string    `gorm:"unique;column:token" json:"token"`
	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