db

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ACCESS_VIEW uint16 = 2 << iota
	ACCESS_DISABLE
	ACCESS_REMOVE
	ACCESS_EDIT
	ACCESS_CREATE
	ACCESS_GET
	ACCESS_POST
	ACCESS_GRANT
	ACCESS_ALL
	ACCESS_NONE uint16 = 0 // 无权限
)

操作列表

Variables

View Source
var (
	AccessNames = map[uint16]string{
		ACCESS_VIEW: "view", ACCESS_DISABLE: "disable", ACCESS_REMOVE: "remove",
		ACCESS_EDIT: "edit", ACCESS_CREATE: "create", ACCESS_GET: "get", ACCESS_POST: "post",
		ACCESS_GRANT: "grant", ACCESS_ALL: "all", ACCESS_NONE: "",
	}
	AccessTitles = map[uint16]string{
		ACCESS_VIEW: "查看", ACCESS_DISABLE: "禁用", ACCESS_REMOVE: "删除",
		ACCESS_EDIT: "编辑", ACCESS_CREATE: "新建", ACCESS_GET: "GET", ACCESS_POST: "POST",
		ACCESS_GRANT: "授权", ACCESS_ALL: "全部", ACCESS_NONE: "无",
	}
)

Functions

func Engine

func Engine() *xorm.Engine

查询某张数据表

func FillRequiredData

func FillRequiredData(drv string, query *xorm.Session) *xorm.Session

写入必须的初始化数据

func GetPermTitles

func GetPermTitles(codes []uint16) (titles []string)

找出权限的中文名称

func GetUserRoles

func GetUserRoles(uid string) (roles []string)

查询某个用户的所有角色名

func Initialize

func Initialize(cfg *config.Settings, verbose bool)

初始化、连接数据库和缓存

func ParsePermNames

func ParsePermNames(perm uint16) (codes []uint16, names []string)

分解出具体权限

func Registry

func Registry() *session.SessionRegistry

获得当前会话管理器

func Session

func Session(token string) *session.Session

获得用户会话

func Table

func Table(name interface{}) *xorm.Session

查询某张数据表

Types

type Access

type Access struct {
	Id           int       `json:"id" xorm:"not null pk autoincr INT(10)"`
	RoleName     string    `json:"role_name" xorm:"not null default '' comment('角色名') index VARCHAR(50)"`
	ResourceType string    `json:"resource_type" xorm:"not null default '' comment('资源类型') VARCHAR(50)"`
	ResourceArgs string    `json:"resource_args" xorm:"comment('资源参数') VARCHAR(255)"`
	PermCode     int       `json:"perm_code" xorm:"not null default 0 comment('权限码') SMALLINT(5)"`
	Actions      string    `json:"actions" xorm:"not null default '' comment('允许的操作') VARCHAR(50)"`
	GrantedAt    time.Time `json:"granted_at" xorm:"comment('授权时间') TIMESTAMP"`
	RevokedAt    time.Time `json:"revoked_at" xorm:"comment('撤销时间') index TIMESTAMP"`
}

func AddAccess

func AddAccess(role, res string, perm uint16, args ...string) (access *Access, err error)

添加权限

func (Access) TableName

func (Access) TableName() string

type CronDaily

type CronDaily struct {
	Id       int    `json:"id" xorm:"not null pk autoincr comment('主键') INT(10)"`
	TaskId   int    `json:"task_id" xorm:"not null default 0 comment('任务ID') index INT(10)"`
	IsActive int    `json:"is_active" xorm:"not null default b'0' comment('有效') BIT(1)"`
	Workday  int    `json:"workday" xorm:"not null default b'0' comment('工作日') BIT(1)"`
	Weekday  int    `json:"weekday" xorm:"not null default 0 comment('周X|周Y...') TINYINT(3)"`
	RunClock string `json:"run_clock" xorm:"not null default '' comment('具体时间') index CHAR(8)"`
}

func (CronDaily) TableName

func (CronDaily) TableName() string

type CronNotice

type CronNotice struct {
	Id             int       `json:"id" xorm:"not null pk autoincr comment('主键') INT(10)"`
	UserId         int       `json:"user_id" xorm:"default 0 comment('用户ID') index INT(10)"`
	TaskId         int       `json:"task_id" xorm:"not null default 0 comment('任务ID') index INT(10)"`
	IsActive       int       `json:"is_active" xorm:"not null default b'0' comment('有效') BIT(1)"`
	Important      int       `json:"important" xorm:"not null default 0 comment('重要程度') TINYINT(3)"`
	Message        string    `json:"message" xorm:"comment('消息内容') TEXT"`
	ReadTime       time.Time `json:"read_time" xorm:"comment('阅读时间') index DATETIME"`
	DelayStartTime time.Time `json:"delay_start_time" xorm:"comment('推迟开始时间') index DATETIME"`
	StartTime      time.Time `json:"start_time" xorm:"comment('开始时间') DATETIME"`
	StopTime       time.Time `json:"stop_time" xorm:"comment('结束时间') DATETIME"`
	StartClock     string    `json:"start_clock" xorm:"comment('开始时刻') CHAR(8)"`
	StopClock      string    `json:"stop_clock" xorm:"comment('结束时刻') CHAR(8)"`
}

func (CronNotice) TableName

func (CronNotice) TableName() string

type CronTask

type CronTask struct {
	Id         int       `json:"id" xorm:"not null pk autoincr comment('主键') INT(10)"`
	UserId     int       `json:"user_id" xorm:"default 0 comment('用户ID') index INT(10)"`
	ReferId    int       `json:"refer_id" xorm:"not null default 0 comment('关联任务ID') index INT(10)"`
	IsActive   int       `json:"is_active" xorm:"not null default b'0' comment('有效') BIT(1)"`
	Behind     int       `json:"behind" xorm:"not null default 0 comment('相对推迟/提前多少分钟') SMALLINT(6)"`
	ActionType string    `` /* 136-byte string literal not displayed */
	CmdUrl     string    `json:"cmd_url" xorm:"not null default '' comment('指令或网址') VARCHAR(500)"`
	ArgsData   string    `json:"args_data" xorm:"comment('参数或消息体') TEXT"`
	LastTime   time.Time `json:"last_time" xorm:"comment('最后执行时间') index DATETIME"`
	LastResult string    `json:"last_result" xorm:"comment('执行结果') TEXT"`
	LastError  string    `json:"last_error" xorm:"comment('出错信息') TEXT"`
}

func (CronTask) TableName

func (CronTask) TableName() string

type CronTimer

type CronTimer struct {
	Id       int       `json:"id" xorm:"not null pk autoincr comment('主键') INT(10)"`
	TaskId   int       `json:"task_id" xorm:"not null default 0 comment('任务ID') index INT(10)"`
	IsActive int       `json:"is_active" xorm:"not null default b'0' comment('有效') BIT(1)"`
	RunDate  time.Time `json:"run_date" xorm:"comment('指定日期') index DATE"`
	RunClock string    `json:"run_clock" xorm:"not null default '' comment('具体时间') CHAR(8)"`
}

func (CronTimer) TableName

func (CronTimer) TableName() string

type Group

type Group struct {
	Id        int       `json:"id" xorm:"not null pk autoincr INT(10)"`
	Gid       string    `json:"gid" xorm:"not null default '' comment('唯一ID') unique CHAR(16)"`
	Title     string    `json:"title" xorm:"not null default '' comment('名称') VARCHAR(50)"`
	Remark    string    `json:"remark" xorm:"comment('说明备注') TEXT"`
	CreatedAt time.Time `json:"created_at" xorm:"created comment('创建时间') TIMESTAMP"`
}

func (Group) TableName

func (Group) TableName() string
type Menu struct {
	Id                  int `json:"id" xorm:"not null pk autoincr INT(10)"`
	*models.NestedModel `xorm:"extends"`
	Path                string `json:"path" xorm:"not null default '' comment('路径') index VARCHAR(100)"`
	Title               string `json:"title" xorm:"not null default '' comment('名称') VARCHAR(50)"`
	Icon                string `json:"icon" xorm:"comment('图标') VARCHAR(30)"`
	Remark              string `json:"remark" xorm:"comment('说明备注') TEXT"`
	models.TimeModel    `xorm:"extends"`
}

func AddMenu

func AddMenu(path, title string, icon string, parent *Menu) (menu *Menu, err error)

添加菜单

func (m *Menu) AddTo(parent *Menu) (err error)

添加一个菜单

func (Menu) TableName() string

type Role

type Role struct {
	Id               int    `json:"id" xorm:"not null pk autoincr INT(10)"`
	Name             string `json:"name" xorm:"not null default '' comment('名称') unique VARCHAR(50)"`
	Remark           string `json:"remark" xorm:"comment('说明备注') TEXT"`
	models.TimeModel `xorm:"extends"`
}

func GetAllRoles

func GetAllRoles() (objs []*Role, err error)

查询符合条件的所有行

func (Role) TableName

func (Role) TableName() string

type User

type User struct {
	Id               int    `json:"id" xorm:"not null pk autoincr INT(10)"`
	Uid              string `json:"uid" xorm:"not null default '' comment('唯一ID') unique CHAR(16)"`
	Username         string `json:"username" xorm:"not null default '' comment('用户名') index VARCHAR(30)"`
	Password         string `json:"password" xorm:"not null default '' comment('密码') VARCHAR(60)"`
	Realname         string `json:"realname" xorm:"comment('昵称/称呼') VARCHAR(20)"`
	Mobile           string `json:"mobile" xorm:"comment('手机号码') index VARCHAR(20)"`
	Email            string `json:"email" xorm:"comment('电子邮箱') VARCHAR(50)"`
	PrinGid          string `json:"prin_gid" xorm:"not null default '' comment('主用户组') CHAR(16)"`
	ViceGid          string `json:"vice_gid" xorm:"comment('次用户组') CHAR(16)"`
	Avatar           string `json:"avatar" xorm:"comment('头像') VARCHAR(100)"`
	Introduction     string `json:"introduction" xorm:"comment('介绍说明') VARCHAR(500)"`
	models.TimeModel `xorm:"extends"`
}

func NewUser

func NewUser(username, realname string) *User

func UserSignin

func UserSignin(username, password string) (*User, string, error)

登录

func (*User) SetPassword

func (m *User) SetPassword(password string) *User

设置密码

func (User) TableName

func (User) TableName() string

func (User) VerifyPassword

func (m User) VerifyPassword(password string) bool

校验密码

type UserRole

type UserRole struct {
	Id       int    `json:"id" xorm:"not null pk autoincr INT(10)"`
	UserUid  string `json:"user_uid" xorm:"not null default '' comment('用户ID') index CHAR(16)"`
	RoleName string `json:"role_name" xorm:"not null default '' comment('角色名') index VARCHAR(50)"`
}

func (UserRole) GetRoleUsers

func (m UserRole) GetRoleUsers(roleName string) (users []*User)

查询属于某个角色的所有用户

func (UserRole) TableName

func (UserRole) TableName() string

Jump to

Keyboard shortcuts

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