Skip to content

Commit

Permalink
fix(sqlite): slice qurey
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Feb 14, 2025
1 parent 0cebcca commit 28762c8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/FloatTech/floatbox v0.0.0-20241106130736-5aea0a935024
github.com/FloatTech/sqlite v1.7.0
github.com/FloatTech/sqlite v1.7.1
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7
github.com/antchfx/htmlquery v1.3.3
github.com/corona10/goimagehash v1.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/FloatTech/floatbox v0.0.0-20241106130736-5aea0a935024 h1:mrvWpiwfRklt9AyiQjKgDGJjf4YL6FZ3yC+ydbkuF2o=
github.com/FloatTech/floatbox v0.0.0-20241106130736-5aea0a935024/go.mod h1:+P3hs+Cvl10/Aj3SNE96TuBvKAXCe+XD1pKphTZyiwk=
github.com/FloatTech/sqlite v1.7.0 h1:FGSn4pCR12kESozn7IvNx3U39dwR/AcFM9oPyGACsl0=
github.com/FloatTech/sqlite v1.7.0/go.mod h1:/4tzfCGhrZnnjC1U8vcfwGQeF6eR649fhOsS3+Le0+s=
github.com/FloatTech/sqlite v1.7.1 h1:XKUY0+MNaRmvEIgRv7QLbl7PFVpUfQ72+XQg+no2Vq0=
github.com/FloatTech/sqlite v1.7.1/go.mod h1:/4tzfCGhrZnnjC1U8vcfwGQeF6eR649fhOsS3+Le0+s=
github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562 h1:snfw7FNFym1eNnLrQ/VCf80LiQo9C7jHgrunZDwiRcY=
github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7 h1:S/ferNiehVjNaBMNNBxUjLtVmP/YWD6Yh79RfPv4ehU=
Expand Down
13 changes: 0 additions & 13 deletions niu/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,3 @@ func TestCheckProp(t *testing.T) {
}
t.Log("成功")
}

func TestProcessNiuNiuAction(t *testing.T) {
user := &userInfo{
UID: 123,
Length: 12,
WeiGe: 2,
}
action, err := user.processNiuNiuAction("11")
if err != nil {
t.Error(err)
}
t.Log(action, "---------", user)
}
19 changes: 10 additions & 9 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,33 @@ func InsertWalletOf(uid int64, money int) error {
}

// 获取钱包数据 no lock
func (sql *Storage) getWalletOf(uid int64) (wallet Wallet) {
func (s *Storage) getWalletOf(uid int64) (wallet Wallet) {
uidstr := strconv.FormatInt(uid, 10)
_ = sql.db.Find("storage", &wallet, "WHERE uid = ?", uidstr)
_ = s.db.Find("storage", &wallet, "WHERE uid = ?", uidstr)
return
}

// 获取钱包数据组
func (sql *Storage) getGroupWalletOf(sortable bool, uids ...int64) (wallets []Wallet, err error) {
sql.RLock()
defer sql.RUnlock()
func (s *Storage) getGroupWalletOf(sortable bool, uids ...int64) (wallets []Wallet, err error) {
s.RLock()
defer s.RUnlock()
wallets = make([]Wallet, 0, len(uids))
sort := "ASC"
if sortable {
sort = "DESC"
}
info := Wallet{}
err = sql.db.FindFor("storage", &info, "WHERE uid IN ? ORDER BY money "+sort, func() error {
q, sl := sql.QuerySet("WHERE uid", "IN", uids)
err = s.db.FindFor("storage", &info, q+" ORDER BY money "+sort, func() error {
wallets = append(wallets, info)
return nil
}, uids)
}, sl...)
return
}

// 更新钱包 no lock
func (sql *Storage) updateWalletOf(uid int64, money int) (err error) {
return sql.db.Insert("storage", &Wallet{
func (s *Storage) updateWalletOf(uid int64, money int) (err error) {
return s.db.Insert("storage", &Wallet{
UID: uid,
Money: money,
})
Expand Down

0 comments on commit 28762c8

Please sign in to comment.