orm

package
v0.0.0-...-a1b16c7 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: MIT Imports: 13 Imported by: 0

README

ORM

处理cc后端的数据库对象映射事务,屏蔽数据库细节。

错误处理

  • orm的函数,在非特殊情况下必须返回error对象,error对象将在http模块中进行统一的处理。(2020.9.17)

测试

  • orm的测试覆盖率必须达到95%以上(2020.9.17)
DM_1
  • MD5不能为全局唯一值,因为存在文件副本是完全有可能的

Documentation

Overview

处理将磁盘文件记录入数据库的操作

用于查询数据库中的资源

通过文件监控使数据库自适应

orm/mainServer.go 负责数据库读取

TODO: 文章是否可以删除? TODO: 文章的访问权限问题?

Index

Constants

View Source
const (
	ACCOUNT_LEVEL_ADMIN        = "admin"   // 网站管理员
	ACCOUNT_LEVEL_VIP          = "vip"     // 网站vip
	ACCOUNT_LEVEL_NORMAL       = "n"       // 一般会员
	ACCOUNT_LEVEL_UNREGISTERED = "unrgstr" // 还未验证账户

	ACCOUNT_LEVEL_TEST = "t" // 测试账户,鸟用没有

	TIME_EXPIRE_ONE_MONTH = 2626560
	TIME_EXPIRE_ONE_DAY   = 87552
)
View Source
const (
	DM_PERMISSION_ALL   = 0
	DM_PERMISSION_GUEST = 1
)

Variables

This section is empty.

Functions

func DMAddResources

func DMAddResources(rs []dm_1.DMResource, status *dm_1.DMTaskStatus) (e error)

当添加一笔数据时,系统将会根据dm1.DMExts自动匹配文件的种类 只要有一笔数据为重复添加的,就会立刻返回错误

func DMAddResourcesGo

func DMAddResourcesGo(rs []dm_1.DMResource, status *dm_1.DMTaskStatus, goCount int) (e error)

弃用 MD5 运算无法使用并发提高速度,因为有读取文件的磁盘速度短板

func DMCheckPermission

func DMCheckPermission(accountId int64) (hasPermission bool, er error)

用于在API时第一时间进行权限检查 如果是上帝id则会直接通过

func DMGetTagIdByName

func DMGetTagIdByName(name string) int64

func DMIndicateResourceBackupOf

func DMIndicateResourceBackupOf(resourceId int64, backupId int64) (e error)

指定某文件为某资源的备份

func DMIndicateResourceBinary

func DMIndicateResourceBinary(id int64) (e error)

指定资源为二进制,或二进制目录

func DMInsertTag

func DMInsertTag(tag DMTag) error

func DMIsTagExist

func DMIsTagExist(name string) bool

func DMIsTargetResourceExist

func DMIsTargetResourceExist(path string) (exist bool, e error)

func DMNewNotifyFileDb

func DMNewNotifyFileDb() *dm_1.DMNotifyFile

func DMTags2Strings

func DMTags2Strings(tags []DMTag) (ts []string)

func GetPostCustomStyleById

func GetPostCustomStyleById(id int64) (css string)

func GetTagIds

func GetTagIds(tags []string) ([]int64, error)

根据一系列tag的名字获取所有的tag的id 如果tag不存在则会被创建

func GetTagNames

func GetTagNames(tagIds []int64) ([]string, error)

func InitEngine

func InitEngine(dbPath string)

func IsPostFav

func IsPostFav(id, pid int64) (isFav bool, e error)

func ModifyPost

func ModifyPost(id int64, title, text string, owner int64, isPrivate bool, tags []string, path string) error

修改文章

func ModifyPostNoText

func ModifyPostNoText(id int64, title string, owner int64, tags []string) error

修改文章,不修改内容 减轻流量负担

func ModifyPostPath

func ModifyPostPath(id int64, path string) error

func NewAccount

func NewAccount(name, email, phone, passwd string) error

func NewChat

func NewChat(accountId int64, text string, date time.Time) error

func NewPost

func NewPost(title, text string, owner int64, tags []string, private bool, path string) (int64, error)

向数据库添加一笔新文章

func SetAccountExAvatar

func SetAccountExAvatar(avatar string, id int64) error

func SetAccountExInfo

func SetAccountExInfo(info string, id int64) error

func SetAccountPhone

func SetAccountPhone(phone string, id int64) error

func Sync2Account

func Sync2Account()

func Sync2Chat

func Sync2Chat()

func Sync2DM1

func Sync2DM1()

func Sync2Post

func Sync2Post()

func Sync2VP

func Sync2VP()

func VagueSearchPostAndTagName

func VagueSearchPostAndTagName(text string) (ps []PostInfo, tags []Tag, e error)

Types

type Account

type Account struct {
	Id     int64
	Name   string `xorm:"unique"`
	Email  string `xorm:"unique"`
	Phone  string `xorm:"unique"`
	Passwd string
}

账户的基本信息

func GetAccount

func GetAccount(id int64) (*Account, error)

func GetAccountByLoginType

func GetAccountByLoginType(login, cryPswd, loginType string) (*Account, error)

func GetAccountByName

func GetAccountByName(name string) (*Account, error)

type AccountEx

type AccountEx struct {
	Id        int64
	AccountId int64  `xorm:"unique"`
	Avatar    string // base64 数据
	Info      string // 个人简介,markdown数据
	Level     string // \see ACCOUNT_LEVEL_xxx

	BgUrl string // 装扮信息

	Exp             int64  // 等级?
	PrivateInfoMask string // 用于遮罩哪些信息不可被外部访问

	FavPosts []int64 // 收藏文章

	SteamId  string
	SteamApi string
}

账户的额外信息

func AddFav

func AddFav(id, pid int64) (*AccountEx, error)

func GetAccountEx

func GetAccountEx(id int64) (*AccountEx, error)

func RemoveFav

func RemoveFav(id, pid int64) (*AccountEx, error)

func UpdateFav

func UpdateFav(id int64, mdFavList []int64) (*AccountEx, error)

type Chat

type Chat struct {
	Id        int64
	AccountId int64 `xorm:"unique"`
	Text      string
	Date      time.Time
}

type CountOf

type CountOf struct {
	Text  string
	Count int
}

上传的文章

func GetOnesAllPostInfoDate

func GetOnesAllPostInfoDate(id int64) (c []CountOf, e error)

获取某个人的文章日期列表,按月来算。 返回的列表应该形如: key: 2000-1 value: 2 表示在2000的1月有两篇文章

于2020/12/2通过测试

func GetOnesAllPostInfoTags

func GetOnesAllPostInfoTags(id int64) (t []CountOf, e error)

返回某人拥有的所有tag

func Map2CountOf

func Map2CountOf(m map[string]int) (c []CountOf)

type DMBackupResource

type DMBackupResource struct {
	Id          int64
	ParentId    int64
	Description string
	MD5         string
	Path        string `xorm:"unique"`
	// 例如:备份一个文件夹,则其中的所有文件都会被该备份资源所备份
	BackupTargetIds []int64
}

backup

func DMGetBackupResourceById

func DMGetBackupResourceById(id int64) (bk *DMBackupResource, er error)

func (DMBackupResource) Update

func (R DMBackupResource) Update() (e error)

type DMTag

type DMTag struct {
	Id   int64
	Name string `xorm:"unique"`
}

tag

func DMGetAllTags

func DMGetAllTags() (tags []DMTag, e error)

func (DMTag) Insert

func (R DMTag) Insert() (e error)

type DMTargetResource

type DMTargetResource struct {
	Id           int64
	Description  string
	MD5          string
	Path         string `xorm:"unique"`
	TagIds       []int64
	BackupIdList []int64
	ChildGenre   string
	Rating       int
	Dead         bool
	Size         int64
}

target

func DMGetAllMusicResources

func DMGetAllMusicResources() (dms []DMTargetResource, e error)

func DMGetParentResource

func DMGetParentResource(parentId int64) (tr *DMTargetResource, er error)

获取某个子资源信息的父资源信息

func DMGetTargetResourceById

func DMGetTargetResourceById(id int64) (tr *DMTargetResource, er error)

func DMGetTargetResourceByPath

func DMGetTargetResourceByPath(path string) (tr *DMTargetResource, e error)

如果不存在则返回nil

func DMGetTargetResourcesByTags

func DMGetTargetResourcesByTags(tagIds []int64) ([]DMTargetResource, error)

func GetAllMD5NotComputed

func GetAllMD5NotComputed() (rs []DMTargetResource, e error)

func (*DMTargetResource) ComputeMD5

func (pR *DMTargetResource) ComputeMD5() error

func (DMTargetResource) Decay

func (R DMTargetResource) Decay() (*dm_1.DMResource, error)

退化为DMResource 带文件信息

func (*DMTargetResource) GetChildResourceBackup

func (PR *DMTargetResource) GetChildResourceBackup() (*DMBackupResource, error)

func (*DMTargetResource) GetChildResourceEx

func (PR *DMTargetResource) GetChildResourceEx() (ex *DMTargetResourceEx, e error)

func (DMTargetResource) GetClones

func (R DMTargetResource) GetClones() (rs []DMTargetResource, e error)

返回与 R md5相同的资源 包含自身

func (DMTargetResource) Update

func (R DMTargetResource) Update() (e error)

type DMTargetResourceEx

type DMTargetResourceEx struct {
	Id                       int64
	ParentId                 int64 `xorm:"unique"`
	CompatibilityDescription string
	Commentary               string
	Data                     string
}

func DMGetTargetResourceExById

func DMGetTargetResourceExById(id int64) (ex *DMTargetResourceEx, er error)

func (*DMTargetResourceEx) GetParentResource

func (PR *DMTargetResourceEx) GetParentResource() (p *DMTargetResource, e error)

func (DMTargetResourceEx) Update

func (R DMTargetResourceEx) Update() (e error)

type DMWhiteList

type DMWhiteList struct {
	Id         int64
	Level      int `xorm:"unique"`
	AccountIds []int64
}

permission

func DMGetWhiteList

func DMGetWhiteList(level int) (wl DMWhiteList, er error)

获取文件管理白名单,返回某一等级的管理权限组 当 wl == {} && e == nil 时表明不存在该权限组

type HomeInfoModel

type HomeInfoModel struct {
	Name, Avatar string
	PostCount    int
	// 通过特殊的标题名来进行匹配
	Info, Projects, Gears InfoComponent

	Id    int64
	Level string
	Exp   int64
}

func GetUserHomeInfo

func GetUserHomeInfo(id int64) (him HomeInfoModel, e error)

--------- 账户信息模块 ---------

type InfoComponent

type InfoComponent struct {
	Markdown   string
	LastUpdate string
}

type Post

type Post struct {
	Id         int64
	Title      string
	Text       string
	TagIds     []int64
	OwnerId    int64
	IsPrivate  bool
	Date       string
	CreateDate string
	Path       string
}

上传的文章

func GetInfoComponentPost

func GetInfoComponentPost(id int64, name string) (p []Post, e error)

func GetPostById

func GetPostById(id int64) (Post, error)

func GetPostsByOwnerPublic

func GetPostsByOwnerPublic(OwnerId int64) ([]Post, error)

func GetPostsPublicAll

func GetPostsPublicAll() ([]Post, error)

type PostInfo

type PostInfo struct {
	Id         int64
	Title      string
	CreateDate string
	Date       string
	IsPrivate  bool
	OwnerId    int64
	Path       string
	TagIds     []int64
}

上传的文章

func GetAllFavPostInfos

func GetAllFavPostInfos(id int64) (pis []PostInfo, e error)

func GetAllPublicPostInfosLimited

func GetAllPublicPostInfosLimited(start, count int) ([]PostInfo, error)

func GetPostInfoById

func GetPostInfoById(id int64) (PostInfo, error)

func GetPostInfosAll

func GetPostInfosAll() ([]PostInfo, error)

func GetPostInfosByCateDate

func GetPostInfosByCateDate(id int64, date string) (ps []PostInfo, e error)

func GetPostInfosByIds

func GetPostInfosByIds(ids []int64) ([]PostInfo, error)

func GetPostInfosByOwnerAll

func GetPostInfosByOwnerAll(OwnerId int64) ([]PostInfo, error)

通过某一个人获取所有他的文章 仅通过atk

func GetPostInfosByOwnerPublic

func GetPostInfosByOwnerPublic(OwnerId int64) ([]PostInfo, error)

通过某一个人获取所有公开文章

func GetPostInfosByTags

func GetPostInfosByTags(tags []string) ([]PostInfo, error)

type PostInfoMono

type PostInfoMono struct {
	Id    int64
	Title string
}

上传的文章

func GetOnesRecentPostTitle

func GetOnesRecentPostTitle(id int64) (titles []PostInfoMono, e error)

最新文章 获取最近的8篇文章标题

type Tag

type Tag struct {
	Id         int64
	Text       string
	IsCatalog  bool
	Percentage float32
}

上传的tag标签结构 tag同时将作为分区的主要依据 TODO:tag达到一定数量则升级为分区

func GetAllTags

func GetAllTags() ([]Tag, error)

type UserSearchResult

type UserSearchResult struct {
	Id     int64
	Avatar string // base64 数据
	Name   string
}

func VagueSearchAccountName

func VagueSearchAccountName(text string) (usrs []UserSearchResult, e error)

type VPInfoModel

type VPInfoModel struct {
	Id      int64
	Title   string
	OwnerId int64
}

func VPGetProjectListById

func VPGetProjectListById(id string) (vpis []VPInfoModel, e error)

type VPModel

type VPModel struct {
	Id      int64
	Title   string `xorm:"unique"`
	OwnerId int64  // 前端必须返回正确的ownerid,不得为0
	Data    string
}

target

func VPFindProjectById

func VPFindProjectById(vpid string) (bool, VPModel, error)

func (VPModel) Insert

func (R VPModel) Insert() (id int64, e error)

func (VPModel) Update

func (R VPModel) Update() (e error)

Jump to

Keyboard shortcuts

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