From 375c761b244c3065f343f1afbbbdc39d12ab1365 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Tue, 28 Mar 2023 18:04:59 +0800 Subject: [PATCH] upgrade github.com/alimy/yesql => v0.3.0 --- .vscode/launch.json | 2 +- go.mod | 2 +- go.sum | 4 ++-- internal/dao/sakila/sqlx.go | 8 ++++++++ internal/dao/sakila/topics.go | 31 +++++++++++++------------------ 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index c18360f6..fb60435b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,7 +6,7 @@ "type": "go", "request": "launch", "mode": "exec", - "program": "${fileDirname}/__debug_bin", + "program": "${workspaceFolder}/.vscode/__debug_bin", "preLaunchTask": "go: build (debug)", "cwd": "${workspaceFolder}" } diff --git a/go.mod b/go.mod index 9d0f15a7..988d1f3a 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/afocus/captcha v0.0.0-20191010092841-4bd1f21c8868 github.com/alimy/cfg v0.3.0 github.com/alimy/mir/v3 v3.1.1 - github.com/alimy/yesql v0.2.0 + github.com/alimy/yesql v0.3.0 github.com/aliyun/aliyun-oss-go-sdk v2.2.6+incompatible github.com/allegro/bigcache/v3 v3.0.2 github.com/bytedance/sonic v1.8.5 diff --git a/go.sum b/go.sum index d874a4f0..27370c71 100644 --- a/go.sum +++ b/go.sum @@ -127,8 +127,8 @@ github.com/alimy/cfg v0.3.0 h1:9xgA0QWVCPSq9fFNRcYahVCAX22IL9ts2wrTQPfAStY= github.com/alimy/cfg v0.3.0/go.mod h1:rOxbasTH2srl6StAjNF5Vyi8bfrdkl3fLGmOYtSw81c= github.com/alimy/mir/v3 v3.1.1 h1:3tz7uGOwuA1IKU0BysyBvGbyqKtEVMuhPBD/APk1ANw= github.com/alimy/mir/v3 v3.1.1/go.mod h1:ybhT2ijOiDn0lLwWzIY6vXdv+uzZrctS7VFfczcXBWU= -github.com/alimy/yesql v0.2.0 h1:tYDPxWSakSUOss1xcYisRjDH//GnUunvlrfB4Ek8ikQ= -github.com/alimy/yesql v0.2.0/go.mod h1:Y0FdRIwIbJyTv56wSX+MpaIHiAW1PyKTDYO6K/er4JY= +github.com/alimy/yesql v0.3.0 h1:KKjDBaDIrWoKor3E2XRc/wtnA6ZIZdScevpQaYizqmo= +github.com/alimy/yesql v0.3.0/go.mod h1:Y0FdRIwIbJyTv56wSX+MpaIHiAW1PyKTDYO6K/er4JY= github.com/aliyun/aliyun-oss-go-sdk v2.2.6+incompatible h1:KXeJoM1wo9I/6xPTyt6qCxoSZnmASiAjlrr0dyTUKt8= github.com/aliyun/aliyun-oss-go-sdk v2.2.6+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= github.com/allegro/bigcache/v3 v3.0.2 h1:AKZCw+5eAaVyNTBmI2fgyPVJhHkdWder3O9IrprcQfI= diff --git a/internal/dao/sakila/sqlx.go b/internal/dao/sakila/sqlx.go index 503b435e..5db704aa 100644 --- a/internal/dao/sakila/sqlx.go +++ b/internal/dao/sakila/sqlx.go @@ -116,6 +116,14 @@ func t(query string) string { return strings.Replace(query, "@", conf.DatabaseSetting.TablePrefix, -1) } +// yesqlScan yesql.Scan help function +func yesqlScan[T any](query yesql.SQLQuery, obj T) T { + if err := yesql.Scan(obj, query); err != nil { + logrus.Fatal(err) + } + return obj +} + func initSqlxDB() { _db = conf.MustSqlxDB() yesql.UseSqlx(_db) diff --git a/internal/dao/sakila/topics.go b/internal/dao/sakila/topics.go index 2ee51bca..c97bac3a 100644 --- a/internal/dao/sakila/topics.go +++ b/internal/dao/sakila/topics.go @@ -12,7 +12,6 @@ import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" - "github.com/sirupsen/logrus" ) var ( @@ -21,17 +20,17 @@ var ( type topicSrv struct { *sqlxSrv - Scope yesql.Scope `yesql:"topic"` - StmtNewestTags *sqlx.Stmt `yesql:"newest_tags"` - StmtHotTags *sqlx.Stmt `yesql:"hot_tags"` - StmtTagsByKeywordA *sqlx.Stmt `yesql:"tags_by_keyword_a"` - StmtTagsByKeywordB *sqlx.Stmt `yesql:"tags_by_keyword_b"` - StmtInsertTag *sqlx.Stmt `yesql:"insert_tag"` - SqlTagsByIdA string `yesql:"tags_by_id_a"` - SqlTagsByIdB string `yesql:"tags_by_id_b"` - SqlDecrTagsById string `yesql:"decr_tags_by_id"` - SqlTagsForIncr string `yesql:"tags_for_incr"` - SqlIncrTagsById string `yesql:"incr_tags_by_id"` + yesql.Namespace `yesql:"topic"` + StmtNewestTags *sqlx.Stmt `yesql:"newest_tags"` + StmtHotTags *sqlx.Stmt `yesql:"hot_tags"` + StmtTagsByKeywordA *sqlx.Stmt `yesql:"tags_by_keyword_a"` + StmtTagsByKeywordB *sqlx.Stmt `yesql:"tags_by_keyword_b"` + StmtInsertTag *sqlx.Stmt `yesql:"insert_tag"` + SqlTagsByIdA string `yesql:"tags_by_id_a"` + SqlTagsByIdB string `yesql:"tags_by_id_b"` + SqlDecrTagsById string `yesql:"decr_tags_by_id"` + SqlTagsForIncr string `yesql:"tags_for_incr"` + SqlIncrTagsById string `yesql:"incr_tags_by_id"` } func (s *topicSrv) UpsertTags(userId int64, tags []string) (res cs.TagInfoList, xerr error) { @@ -124,11 +123,7 @@ func (s *topicSrv) TagsByKeyword(keyword string) (res cs.TagInfoList, err error) } func newTopicService(db *sqlx.DB, query yesql.SQLQuery) core.TopicService { - obj := &topicSrv{ + return yesqlScan(query, &topicSrv{ sqlxSrv: newSqlxSrv(db), - } - if err := yesql.Scan(obj, query); err != nil { - logrus.Fatal(err) - } - return obj + }) }