-
Notifications
You must be signed in to change notification settings - Fork 30
修复issue所提到的bug,重置niuniu数据库 #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
xyy0411
wants to merge
7
commits into
FloatTech:main
Choose a base branch
from
xyy0411:pppp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
261e13d
修复issue所提到的bug,重置niuniu数据库
xyy0411 1b503b7
修lint,优化代码
xyy0411 00119bc
Merge branch 'FloatTech:main' into pppp
xyy0411 6a7c3e3
gorm修改成v1版本
xyy0411 ce484c7
Merge remote-tracking branch 'origin/pppp' into pppp
xyy0411 fdf474a
删除go.mod不使用的go-sqlite依赖
xyy0411 61f930d
修改调用processJJ方法时返回的错误err,优化jj函数的数据库操作
xyy0411 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package niu | ||
|
||
import ( | ||
"fmt" | ||
"github.com/RomiChan/syncx" | ||
"github.com/jinzhu/gorm" | ||
) | ||
|
||
var ( | ||
migratedGroups = syncx.Map[string, bool]{} // key: string, value: bool | ||
) | ||
|
||
func ensureUserInfoTable[T userInfo | AuctionInfo](gid int64, prefix string) error { | ||
table := fmt.Sprintf("group_%d_%s_info", gid, prefix) | ||
if _, ok := migratedGroups.Load(table); ok { | ||
return nil | ||
} | ||
err := db.Table(table).AutoMigrate(new(T)).Error | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// 设置为已迁移 | ||
migratedGroups.Store(table, true) | ||
return nil | ||
} | ||
|
||
// TableFor 大写是为了防止数据操作哪里有问题留个保底可以在zbp的项目里直接改 | ||
func TableFor(gid int64, prefix string) *gorm.DB { | ||
return db.Table(fmt.Sprintf("group_%d_%s_info", gid, prefix)) | ||
} | ||
|
||
func listUsers(gid int64) (users, error) { | ||
var us users | ||
err := TableFor(gid, ur).Find(&us).Error | ||
return us, err | ||
} | ||
|
||
func listAuction(gid int64) ([]AuctionInfo, error) { | ||
var as []AuctionInfo | ||
err := TableFor(gid, ac).Order("money DESC").Find(&as).Error | ||
return as, err | ||
} | ||
|
||
func createUser(gid int64, user *userInfo, fix string) error { | ||
return TableFor(gid, fix).Create(user).Error | ||
} | ||
|
||
func getUserByID(gid int64, uid int64) (*userInfo, error) { | ||
var user userInfo | ||
err := TableFor(gid, ur).Where("user_id = ?", uid).First(&user).Error | ||
return &user, err | ||
} | ||
|
||
func updatesUserByID(gid int64, id int64, fields map[string]interface{}) error { | ||
return TableFor(gid, ur).Where("user_id = ?", id).Updates(fields).Error | ||
} | ||
|
||
func deleteUserByID(gid int64, id int64) error { | ||
return TableFor(gid, ur).Where("user_id = ?", id).Delete(&userInfo{}).Error | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如何直接改,你的函数不是都在AnimeAPI了