From d54d6cadd896121f4e22b7a89fe426b5f495f6d1 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Mon, 28 Aug 2023 17:42:47 +0800 Subject: [PATCH] upgrade github.com/bitbus/sqlx => v1.8.0 --- go.mod | 2 +- go.sum | 4 ++-- internal/conf/db.go | 4 ++++ internal/dao/sakila/comments_pgc.go | 23 ++++++++++------------- internal/dao/sakila/messages.go | 6 +++--- internal/dao/sakila/sakila.go | 2 +- internal/dao/sakila/security.go | 6 +++--- internal/dao/sakila/tweets.go | 9 ++++----- internal/dao/sakila/tweets_pgc.go | 11 +++++------ internal/dao/sakila/user.go | 16 +++++++--------- internal/dao/sakila/wallet.go | 6 +++--- internal/dao/sakila/wallet_pgc.go | 6 +++--- 12 files changed, 46 insertions(+), 49 deletions(-) diff --git a/go.mod b/go.mod index 7eddb000..c8ffe7da 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/alimy/yesql v1.9.0 github.com/aliyun/aliyun-oss-go-sdk v2.2.8+incompatible github.com/allegro/bigcache/v3 v3.1.0 - github.com/bitbus/sqlx v1.7.0 + github.com/bitbus/sqlx v1.8.0 github.com/bufbuild/connect-go v1.10.0 github.com/bytedance/sonic v1.10.0 github.com/cockroachdb/errors v1.10.0 diff --git a/go.sum b/go.sum index e5e0a390..f4eb11e5 100644 --- a/go.sum +++ b/go.sum @@ -178,8 +178,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/bitbus/sqlx v1.7.0 h1:n/hAlfY9bI29J9uObqAtjfITgNU2+XtY1ECnJUdmCZc= -github.com/bitbus/sqlx v1.7.0/go.mod h1:MemKLfQ600g6PxUVsIDe48PlY3wOquyW2ApeiXoynFo= +github.com/bitbus/sqlx v1.8.0 h1:2mhQscUW9Qc95gUONNswkuDaJiluVUfmBP4yw2cSK7M= +github.com/bitbus/sqlx v1.8.0/go.mod h1:MemKLfQ600g6PxUVsIDe48PlY3wOquyW2ApeiXoynFo= github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k= github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA= github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= diff --git a/internal/conf/db.go b/internal/conf/db.go index e81ea4c3..560154f0 100644 --- a/internal/conf/db.go +++ b/internal/conf/db.go @@ -58,14 +58,18 @@ func newSqlDB() (driver string, db *sql.DB, err error) { if cfg.If("MySQL") { driver = "mysql" db, err = sql.Open(driver, MysqlSetting.Dsn()) + logrus.Infof("use MySQL as relation database") } else if cfg.Any("PostgreSQL", "PgSQL", "Postgres") { driver = "pgx" db, err = sql.Open(driver, PostgresSetting.Dsn()) + logrus.Infof("use PostgreSQL as relation database") } else if cfg.If("Sqlite3") { driver, db, err = OpenSqlite3() + logrus.Infof("use Sqlite3 as relation database") } else { driver = "mysql" db, err = sql.Open(driver, MysqlSetting.Dsn()) + logrus.Infof("not set db fetuare so use MySQL as default relation database") } return } diff --git a/internal/dao/sakila/comments_pgc.go b/internal/dao/sakila/comments_pgc.go index e232e530..ba00a0a2 100644 --- a/internal/dao/sakila/comments_pgc.go +++ b/internal/dao/sakila/comments_pgc.go @@ -7,6 +7,7 @@ package sakila import ( "time" + "github.com/bitbus/sqlx/db" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/pgc" @@ -21,23 +22,19 @@ type pgcCommentManageSrv struct { p *pgc.CommentManage } -func (s *pgcCommentManageSrv) CreateComment(r *ms.Comment) (res *ms.Comment, err error) { - err = stmtGet(s.p.CreateComment, &res, - r.PostID, r.UserID, r.IP, - r.IPLoc, time.Now().Unix()) - return +func (s *pgcCommentManageSrv) CreateComment(r *ms.Comment) (*ms.Comment, error) { + return db.Get[ms.Comment](s.p.CreateComment, r.PostID, r.UserID, r.IP, r.IPLoc, time.Now().Unix()) } -func (s *pgcCommentManageSrv) CreateCommentReply(r *ms.CommentReply) (res *ms.CommentReply, err error) { - err = stmtGet(s.p.CreateCommentReply, &res, - r.CommentID, r.UserID, r.Content, - r.AtUserID, r.IP, r.IPLoc, time.Now().Unix()) - return +func (s *pgcCommentManageSrv) CreateCommentReply(r *ms.CommentReply) (*ms.CommentReply, error) { + return db.Get[ms.CommentReply](s.p.CreateCommentReply, r.CommentID, + r.UserID, r.Content, r.AtUserID, + r.IP, r.IPLoc, time.Now().Unix()) } -func (s *pgcCommentManageSrv) CreateCommentContent(r *ms.CommentContent) (res *ms.CommentContent, err error) { - err = stmtGet(s.p.CreateCommentContent, &res, +func (s *pgcCommentManageSrv) CreateCommentContent(r *ms.CommentContent) (*ms.CommentContent, error) { + return db.Get[ms.CommentContent](s.p.CreateCommentContent, r.CommentID, r.UserID, r.Content, r.Type, r.Sort, time.Now().Unix()) - return + } diff --git a/internal/dao/sakila/messages.go b/internal/dao/sakila/messages.go index bee6c2ae..b1e969e9 100644 --- a/internal/dao/sakila/messages.go +++ b/internal/dao/sakila/messages.go @@ -9,6 +9,7 @@ import ( "github.com/alimy/tryst/cfg" "github.com/bitbus/sqlx" + "github.com/bitbus/sqlx/db" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc" @@ -45,9 +46,8 @@ func (s *messageSrv) GetUnreadCount(userID int64) (res int64, err error) { return } -func (s *messageSrv) GetMessageByID(id int64) (res *ms.Message, err error) { - err = stmtGet(s.q.GetMessageById, &res, id) - return +func (s *messageSrv) GetMessageByID(id int64) (*ms.Message, error) { + return db.Get[ms.Message](s.q.GetMessageById, id) } func (s *messageSrv) ReadMessage(r *ms.Message) (err error) { diff --git a/internal/dao/sakila/sakila.go b/internal/dao/sakila/sakila.go index 2769f1f0..853fa0fe 100644 --- a/internal/dao/sakila/sakila.go +++ b/internal/dao/sakila/sakila.go @@ -153,7 +153,7 @@ func (s *dataSrv) Name() string { } func (s *dataSrv) Version() *semver.Version { - return semver.MustParse("v0.1.0") + return semver.MustParse("v0.2.0") } func (s *webDataSrvA) Name() string { diff --git a/internal/dao/sakila/security.go b/internal/dao/sakila/security.go index e89c86b1..988eea40 100644 --- a/internal/dao/sakila/security.go +++ b/internal/dao/sakila/security.go @@ -10,6 +10,7 @@ import ( "time" "github.com/bitbus/sqlx" + "github.com/bitbus/sqlx/db" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" @@ -28,9 +29,8 @@ type securitySrv struct { } // GetLatestPhoneCaptcha 获取最新短信验证码 -func (s *securitySrv) GetLatestPhoneCaptcha(phone string) (res *ms.Captcha, err error) { - err = stmtGet(s.q.GetLatestPhoneCaptcha, &res, phone) - return +func (s *securitySrv) GetLatestPhoneCaptcha(phone string) (*ms.Captcha, error) { + return db.Get[ms.Captcha](s.q.GetLatestPhoneCaptcha, phone) } // UsePhoneCaptcha 更新短信验证码 diff --git a/internal/dao/sakila/tweets.go b/internal/dao/sakila/tweets.go index b685d362..c17640b5 100644 --- a/internal/dao/sakila/tweets.go +++ b/internal/dao/sakila/tweets.go @@ -10,6 +10,7 @@ import ( "github.com/alimy/tryst/cfg" "github.com/bitbus/sqlx" + "github.com/bitbus/sqlx/db" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" "github.com/rocboss/paopao-ce/internal/core/ms" @@ -438,9 +439,8 @@ func (s *tweetSrv) GetUserPostStarCount(userID int64) (res int64, err error) { return } -func (s *tweetSrv) GetUserPostCollection(postID, userID int64) (res *ms.PostCollection, err error) { - err = stmtGet(s.q.GetUserPostCollection, &res, postID, userID, userID) - return +func (s *tweetSrv) GetUserPostCollection(postID, userID int64) (*ms.PostCollection, error) { + return db.Get[ms.PostCollection](s.q.GetUserPostCollection, postID, userID, userID) } func (s *tweetSrv) GetUserPostCollections(userID int64, offset, limit int) (res []*ms.PostCollection, err error) { @@ -465,8 +465,7 @@ func (s *tweetSrv) GetPostContentsByIDs(ids []int64) (res []*ms.PostContent, err } func (s *tweetSrv) GetPostContentByID(id int64) (res *ms.PostContent, err error) { - err = stmtGet(s.q.GetPostContentById, &res, id) - return + return db.Get[ms.PostContent](s.q.GetPostContentById, &res, id) } func newTweetService(db *sqlx.DB) core.TweetService { diff --git a/internal/dao/sakila/tweets_pgc.go b/internal/dao/sakila/tweets_pgc.go index be8e2f29..e4f38772 100644 --- a/internal/dao/sakila/tweets_pgc.go +++ b/internal/dao/sakila/tweets_pgc.go @@ -7,6 +7,7 @@ package sakila import ( "time" + "github.com/bitbus/sqlx/db" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/pgc" @@ -47,12 +48,10 @@ func (s *pgcTweetManageSrv) CreateAttachment(r *ms.Attachment) (res int64, err e return } -func (s *pgcTweetManageSrv) CreatePostStar(postID, userID int64) (res *ms.PostStar, err error) { - err = stmtGet(s.p.AddPostStar, &res, postID, userID, time.Now().Unix()) - return +func (s *pgcTweetManageSrv) CreatePostStar(postID, userID int64) (*ms.PostStar, error) { + return db.Get[ms.PostStar](s.p.AddPostStar, postID, userID, time.Now().Unix()) } -func (s *pgcTweetManageSrv) CreatePostCollection(postID, userID int64) (res *ms.PostCollection, err error) { - err = stmtGet(s.p.AddPostCollection, &res, postID, userID, time.Now().Unix()) - return +func (s *pgcTweetManageSrv) CreatePostCollection(postID, userID int64) (*ms.PostCollection, error) { + return db.Get[ms.PostCollection](s.p.AddPostCollection, postID, userID, time.Now().Unix()) } diff --git a/internal/dao/sakila/user.go b/internal/dao/sakila/user.go index d4338dff..5a3506dc 100644 --- a/internal/dao/sakila/user.go +++ b/internal/dao/sakila/user.go @@ -10,6 +10,7 @@ import ( "github.com/alimy/tryst/cfg" "github.com/bitbus/sqlx" + "github.com/bitbus/sqlx/db" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc" @@ -25,19 +26,16 @@ type userManageSrv struct { q *cc.UserManage } -func (s *userManageSrv) GetUserByID(id int64) (res *ms.User, err error) { - err = stmtGet(s.q.GetUserById, &res, id) - return +func (s *userManageSrv) GetUserByID(id int64) (*ms.User, error) { + return db.Get[ms.User](s.q.GetUserById, id) } -func (s *userManageSrv) GetUserByUsername(username string) (res *ms.User, err error) { - err = stmtGet(s.q.GetUserByUsername, &res, username) - return +func (s *userManageSrv) GetUserByUsername(username string) (*ms.User, error) { + return db.Get[ms.User](s.q.GetUserByUsername, username) } -func (s *userManageSrv) GetUserByPhone(phone string) (res *ms.User, err error) { - err = stmtGet(s.q.GetUserByPhone, &res, phone) - return +func (s *userManageSrv) GetUserByPhone(phone string) (*ms.User, error) { + return db.Get[ms.User](s.q.GetUserByPhone, phone) } func (s *userManageSrv) GetUsersByIDs(ids []int64) (res []*ms.User, err error) { diff --git a/internal/dao/sakila/wallet.go b/internal/dao/sakila/wallet.go index a1818be7..ae492616 100644 --- a/internal/dao/sakila/wallet.go +++ b/internal/dao/sakila/wallet.go @@ -9,6 +9,7 @@ import ( "github.com/alimy/tryst/cfg" "github.com/bitbus/sqlx" + "github.com/bitbus/sqlx/db" "github.com/rocboss/paopao-ce/internal/conf" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" @@ -25,9 +26,8 @@ type walletSrv struct { q *cc.Wallet } -func (s *walletSrv) GetRechargeByID(id int64) (res *ms.WalletRecharge, err error) { - err = stmtGet(s.q.GetRechargeById, &res, id) - return +func (s *walletSrv) GetRechargeByID(id int64) (*ms.WalletRecharge, error) { + return db.Get[ms.WalletRecharge](s.q.GetRechargeById, id) } func (s *walletSrv) CreateRecharge(userId, amount int64) (*ms.WalletRecharge, error) { diff --git a/internal/dao/sakila/wallet_pgc.go b/internal/dao/sakila/wallet_pgc.go index 20e8dd5b..de7dc4e1 100644 --- a/internal/dao/sakila/wallet_pgc.go +++ b/internal/dao/sakila/wallet_pgc.go @@ -7,6 +7,7 @@ package sakila import ( "time" + "github.com/bitbus/sqlx/db" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/pgc" @@ -21,7 +22,6 @@ type pgcWalletSrv struct { p *pgc.Wallet } -func (s *pgcWalletSrv) CreateRecharge(userId, amount int64) (res *ms.WalletRecharge, err error) { - err = stmtGet(s.p.CreateRecharge, &res, userId, amount, time.Now().Unix()) - return +func (s *pgcWalletSrv) CreateRecharge(userId, amount int64) (*ms.WalletRecharge, error) { + return db.Get[ms.WalletRecharge](s.p.CreateRecharge, userId, amount, time.Now().Unix()) }