From c64bac867b1370d7c4107b25f3ea28f24130a410 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Sat, 1 Apr 2023 06:23:54 +0800 Subject: [PATCH] sqlx: add stub sql dml for all data logic service use Yesql --- go.mod | 2 +- go.sum | 4 +- internal/dao/sakila/authority.go | 9 +- internal/dao/sakila/comments.go | 17 +- internal/dao/sakila/contacts.go | 9 +- internal/dao/sakila/messages.go | 11 +- internal/dao/sakila/security.go | 11 +- internal/dao/sakila/sqlx.go | 15 -- internal/dao/sakila/timeline.go | 43 ++-- internal/dao/sakila/tweets.go | 35 +-- internal/dao/sakila/user.go | 11 +- internal/dao/sakila/wallet.go | 11 +- internal/dao/sakila/yesql/cc/yesql.go | 324 +++++++++++++++++++++++++- internal/dao/sakila/yesql/yesql.sql | 123 ++++++++++ 14 files changed, 503 insertions(+), 122 deletions(-) diff --git a/go.mod b/go.mod index c3e0b59f..f4b60596 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 v1.1.2 + github.com/alimy/yesql v1.1.5 github.com/aliyun/aliyun-oss-go-sdk v2.2.7+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 9d34ea36..d8070c8c 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 v1.1.2 h1:gsqmzVvbvY87cuNal9xi5sJZrys6wug4aGSyJNA1W8Q= -github.com/alimy/yesql v1.1.2/go.mod h1:Y0FdRIwIbJyTv56wSX+MpaIHiAW1PyKTDYO6K/er4JY= +github.com/alimy/yesql v1.1.5 h1:kHqF5rXS8if/YXazXyfo2OjqV+NhkvVwR43+dfkxkKU= +github.com/alimy/yesql v1.1.5/go.mod h1:Y0FdRIwIbJyTv56wSX+MpaIHiAW1PyKTDYO6K/er4JY= github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible h1:KpbJFXwhVeuxNtBJ74MCGbIoaBok2uZvkD7QXp2+Wis= github.com/aliyun/aliyun-oss-go-sdk v2.2.7+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/authority.go b/internal/dao/sakila/authority.go index 2b77e1ef..c595b84d 100644 --- a/internal/dao/sakila/authority.go +++ b/internal/dao/sakila/authority.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -16,8 +17,7 @@ var ( type authorizationManageSrv struct { *sqlxSrv - stmtIdx *sqlx.Stmt - stmtUpdateFriend *sqlx.Stmt + q *cc.AuthorizationManage } func (s *authorizationManageSrv) IsAllow(user *core.User, action *core.Action) bool { @@ -52,8 +52,7 @@ func (s *authorizationManageSrv) isFriend(userId int64, friendId int64) bool { func newAuthorizationManageService(db *sqlx.DB) core.AuthorizationManageService { return &authorizationManageSrv{ - sqlxSrv: newSqlxSrv(db), - stmtIdx: c(`SELECT * FROM @user WHERE username=?`), - stmtUpdateFriend: c(`SELECT * FROM @user WHERE username=?`), + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildAuthorizationManage), } } diff --git a/internal/dao/sakila/comments.go b/internal/dao/sakila/comments.go index 0556541f..9ce5efe3 100644 --- a/internal/dao/sakila/comments.go +++ b/internal/dao/sakila/comments.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -17,14 +18,12 @@ var ( type commentSrv struct { *sqlxSrv - stmtGetComments *sqlx.Stmt - stmtGetReply *sqlx.Stmt + q *cc.Comment } type commentManageSrv struct { *sqlxSrv - stmtDelComments *sqlx.Stmt - stmtAddComents *sqlx.Stmt + q *cc.CommentManage } func (s *commentSrv) GetComments(conditions *core.ConditionsT, offset, limit int) ([]*core.Comment, error) { @@ -95,16 +94,14 @@ func (s *commentManageSrv) CreateCommentContent(content *core.CommentContent) (* func newCommentService(db *sqlx.DB) core.CommentService { return &commentSrv{ - sqlxSrv: newSqlxSrv(db), - stmtGetComments: c(`SELECT * FROM @user WHERE username=?`), - stmtGetReply: c(`SELECT * FROM @user WHERE username=?`), + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildComment), } } func newCommentManageService(db *sqlx.DB) core.CommentManageService { return &commentManageSrv{ - sqlxSrv: newSqlxSrv(db), - stmtAddComents: c(`SELECT * FROM @user WHERE username=?`), - stmtDelComments: c(`SELECT * FROM @user WHERE username=?`), + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildCommentManage), } } diff --git a/internal/dao/sakila/contacts.go b/internal/dao/sakila/contacts.go index bf48654c..d969496e 100644 --- a/internal/dao/sakila/contacts.go +++ b/internal/dao/sakila/contacts.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -16,8 +17,7 @@ var ( type contactManageSrv struct { *sqlxSrv - stmtAddFriend *sqlx.Stmt - stmtDelFriend *sqlx.Stmt + q *cc.ContactManager } func (s *contactManageSrv) RequestingFriend(userId int64, friendId int64, greetings string) (err error) { @@ -58,8 +58,7 @@ func (s *contactManageSrv) IsFriend(userId int64, friendId int64) bool { func newContactManageService(db *sqlx.DB) core.ContactManageService { return &contactManageSrv{ - sqlxSrv: newSqlxSrv(db), - stmtAddFriend: c(`SELECT * FROM @user WHERE username=?`), - stmtDelFriend: c(`SELECT * FROM @user WHERE username=?`), + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildContactManager), } } diff --git a/internal/dao/sakila/messages.go b/internal/dao/sakila/messages.go index 71806014..cc1b70a7 100644 --- a/internal/dao/sakila/messages.go +++ b/internal/dao/sakila/messages.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -16,9 +17,7 @@ var ( type messageSrv struct { *sqlxSrv - stmtAddMsg *sqlx.Stmt - stmtGetMsg *sqlx.Stmt - stmtReadMsg *sqlx.Stmt + q *cc.Message } func (s *messageSrv) CreateMessage(msg *core.Message) (*core.Message, error) { @@ -59,9 +58,7 @@ func (s *messageSrv) GetMessageCount(conditions *core.ConditionsT) (int64, error func newMessageService(db *sqlx.DB) core.MessageService { return &messageSrv{ - sqlxSrv: newSqlxSrv(db), - stmtAddMsg: c(`SELECT * FROM @user WHERE username=?`), - stmtGetMsg: c(`SELECT * FROM @user WHERE username=?`), - stmtReadMsg: c(`SELECT * FROM @user WHERE username=?`), + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildMessage), } } diff --git a/internal/dao/sakila/security.go b/internal/dao/sakila/security.go index be27849e..4a959519 100644 --- a/internal/dao/sakila/security.go +++ b/internal/dao/sakila/security.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -16,9 +17,7 @@ var ( type securitySrv struct { *sqlxSrv - phoneVerify core.PhoneVerifyService - stmtAddCaptcha *sqlx.Stmt - stmtGetCaptcha *sqlx.Stmt + q *cc.Security } // GetLatestPhoneCaptcha 获取最新短信验证码 @@ -44,9 +43,7 @@ func (s *securitySrv) SendPhoneCaptcha(phone string) error { func newSecurityService(db *sqlx.DB, phoneVerify core.PhoneVerifyService) core.SecurityService { return &securitySrv{ - sqlxSrv: newSqlxSrv(db), - phoneVerify: phoneVerify, - stmtAddCaptcha: c(`SELECT * FROM @user WHERE username=?`), - stmtGetCaptcha: c(`SELECT * FROM @user WHERE username=?`), + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildSecurity), } } diff --git a/internal/dao/sakila/sqlx.go b/internal/dao/sakila/sqlx.go index 1e3029b6..78598146 100644 --- a/internal/dao/sakila/sqlx.go +++ b/internal/dao/sakila/sqlx.go @@ -20,19 +20,10 @@ var ( _db *sqlx.DB ) -type sqlxDB struct { - *sqlx.DB -} - type sqlxSrv struct { db *sqlx.DB } -// Rebind fixed table name in query and rebind the fixed query -func (s *sqlxDB) Rebind(query string) string { - return s.DB.Rebind(query) -} - func (s *sqlxSrv) with(handle func(tx *sqlx.Tx) error) error { tx, err := s.db.Beginx() if err != nil { @@ -130,12 +121,6 @@ func yesqlScan[T any](query yesql.SQLQuery, obj T) T { return obj } -func newSqlxDB(db *sqlx.DB) *sqlxDB { - return &sqlxDB{ - DB: db, - } -} - func mustBuild[T any](db *sqlx.DB, fn func(yesql.PreparexBuilder, ...context.Context) (T, error)) T { p := yesql.NewPreparexBuilder(db, func(query string) string { return strings.Replace(query, "@", conf.DatabaseSetting.TablePrefix, -1) diff --git a/internal/dao/sakila/timeline.go b/internal/dao/sakila/timeline.go index f6717a9e..e8d39249 100644 --- a/internal/dao/sakila/timeline.go +++ b/internal/dao/sakila/timeline.go @@ -8,6 +8,7 @@ import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -20,27 +21,27 @@ var ( type friendIndexSrv struct { *sqlxSrv - ams core.AuthorizationManageService - ths core.TweetHelpService - stmtIndex *sqlx.Stmt + ams core.AuthorizationManageService + ths core.TweetHelpService + q *cc.FriendIndex } type followIndexSrv struct { *sqlxSrv - ths core.TweetHelpService - stmtIndex *sqlx.Stmt + ths core.TweetHelpService + q *cc.FollowIndex } type lightIndexSrv struct { *sqlxSrv - ths core.TweetHelpService - stmtIndex *sqlx.Stmt + ths core.TweetHelpService + q *cc.LightIndex } type simpleIndexPostsSrv struct { *sqlxSrv - ths core.TweetHelpService - stmtIndex *sqlx.Stmt + ths core.TweetHelpService + q *cc.SimpleIndex } // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; @@ -89,32 +90,32 @@ func (s *simpleIndexPostsSrv) TweetTimeline(userId int64, offset int, limit int) func newFriendIndexService(db *sqlx.DB, ams core.AuthorizationManageService, ths core.TweetHelpService) core.IndexPostsService { return &friendIndexSrv{ - ams: ams, - sqlxSrv: newSqlxSrv(db), - stmtIndex: c(`SELECT * FROM @user WHERE username=?`), + ams: ams, + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildFriendIndex), } } func newFollowIndexService(db *sqlx.DB, ths core.TweetHelpService) core.IndexPostsService { return &followIndexSrv{ - ths: ths, - sqlxSrv: newSqlxSrv(db), - stmtIndex: c(`SELECT * FROM @user WHERE username=?`), + ths: ths, + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildFollowIndex), } } func newLightIndexService(db *sqlx.DB, ths core.TweetHelpService) core.IndexPostsService { return &lightIndexSrv{ - ths: ths, - sqlxSrv: newSqlxSrv(db), - stmtIndex: c(`SELECT * FROM @user WHERE username=?`), + ths: ths, + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildLightIndex), } } func newSimpleIndexPostsService(db *sqlx.DB, ths core.TweetHelpService) core.IndexPostsService { return &simpleIndexPostsSrv{ - ths: ths, - sqlxSrv: newSqlxSrv(db), - stmtIndex: c(`SELECT * FROM @user WHERE username=?`), + ths: ths, + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildSimpleIndex), } } diff --git a/internal/dao/sakila/tweets.go b/internal/dao/sakila/tweets.go index fc7e88cd..509802cd 100644 --- a/internal/dao/sakila/tweets.go +++ b/internal/dao/sakila/tweets.go @@ -9,6 +9,7 @@ import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" + "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" "gorm.io/gorm" ) @@ -21,24 +22,18 @@ var ( type tweetSrv struct { *sqlxSrv - stmtGetTweet *sqlx.Stmt - stmtListTweet *sqlx.Stmt - stmtListStar *sqlx.Stmt + q *cc.Tweet } type tweetManageSrv struct { *sqlxSrv - cacheIndex core.CacheIndexService - stmtAddTweet *sqlx.Stmt - stmtDelTweet *sqlx.Stmt - stmtStickTweet *sqlx.Stmt + cacheIndex core.CacheIndexService + q *cc.TweetManage } type tweetHelpSrv struct { *sqlxSrv - stmtAddTag *sqlx.Stmt - stmtDelTag *sqlx.Stmt - stmtListTag *sqlx.Stmt + q *cc.TweetHelp } // MergePosts post数据整合 @@ -325,28 +320,22 @@ func (s *tweetSrv) AttachmentByTweetId(userId int64, tweetId int64) (*cs.Attachm func newTweetService(db *sqlx.DB) core.TweetService { return &tweetSrv{ - sqlxSrv: newSqlxSrv(db), - stmtGetTweet: c(`SELECT * FROM @user WHERE username=?`), - stmtListTweet: c(`SELECT * FROM @user WHERE username=?`), - stmtListStar: c(`SELECT * FROM @user WHERE username=?`), + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildTweet), } } func newTweetManageService(db *sqlx.DB, cacheIndex core.CacheIndexService) core.TweetManageService { return &tweetManageSrv{ - sqlxSrv: newSqlxSrv(db), - cacheIndex: cacheIndex, - stmtAddTweet: c(`SELECT * FROM @user WHERE username=?`), - stmtDelTweet: c(`SELECT * FROM @user WHERE username=?`), - stmtStickTweet: c(`SELECT * FROM @user WHERE username=?`), + sqlxSrv: newSqlxSrv(db), + cacheIndex: cacheIndex, + q: mustBuild(db, cc.BuildTweetManage), } } func newTweetHelpService(db *sqlx.DB) core.TweetHelpService { return &tweetHelpSrv{ - sqlxSrv: newSqlxSrv(db), - stmtAddTag: c(`SELECT * FROM @user WHERE username=?`), - stmtDelTag: c(`SELECT * FROM @user WHERE username=?`), - stmtListTag: c(`SELECT * FROM @user WHERE username=?`), + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildTweetHelp), } } diff --git a/internal/dao/sakila/user.go b/internal/dao/sakila/user.go index 6d058ad8..c063fc81 100644 --- a/internal/dao/sakila/user.go +++ b/internal/dao/sakila/user.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -16,9 +17,7 @@ var ( type userManageSrv struct { *sqlxSrv - stmtAddUser *sqlx.Stmt - stmtUpdateUser *sqlx.Stmt - stmtGetUser *sqlx.Stmt + q *cc.UserManage } func (s *userManageSrv) GetUserByID(id int64) (*core.User, error) { @@ -65,9 +64,7 @@ func (s *userManageSrv) UpdateUser(user *core.User) error { func newUserManageService(db *sqlx.DB) core.UserManageService { return &userManageSrv{ - sqlxSrv: newSqlxSrv(db), - stmtAddUser: c(`SELECT * FROM @user WHERE username=?`), - stmtUpdateUser: c(`SELECT * FROM @user WHERE username=?`), - stmtGetUser: c(`SELECT * FROM @user WHERE username=?`), + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildUserManage), } } diff --git a/internal/dao/sakila/wallet.go b/internal/dao/sakila/wallet.go index 6775d084..c733965a 100644 --- a/internal/dao/sakila/wallet.go +++ b/internal/dao/sakila/wallet.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -16,9 +17,7 @@ var ( type walletSrv struct { *sqlxSrv - stmtAddRecharge *sqlx.Stmt - stmtGetRecharge *sqlx.Stmt - stmtGetBills *sqlx.Stmt + q *cc.Wallet } func (s *walletSrv) GetRechargeByID(id int64) (*core.WalletRecharge, error) { @@ -58,9 +57,7 @@ func (s *walletSrv) HandlePostAttachmentBought(post *core.Post, user *core.User) func newWalletService(db *sqlx.DB) core.WalletService { return &walletSrv{ - sqlxSrv: newSqlxSrv(db), - stmtAddRecharge: c(`SELECT * FROM @user WHERE username=?`), - stmtGetRecharge: c(`SELECT * FROM @user WHERE username=?`), - stmtGetBills: c(`SELECT * FROM @user WHERE username=?`), + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildWallet), } } diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index 6c16b8f4..b2423f88 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -1,6 +1,6 @@ -// Code generated by go-mir. DO NOT EDIT. +// Code generated by Yesql. DO NOT EDIT. // versions: -// - Yesql v1.1.2 +// - Yesql v1.1.5 package cc @@ -12,18 +12,83 @@ import ( ) const ( - _TagsByKeywordB_Topic = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6` - _InsertTag_Topic = `INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)` - _TagsByIdA_Topic = `SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0` - _TagsByIdB_Topic = `SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)` - _TagsForIncr_Topic = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` - _IncrTagsById_Topic = `UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)` - _NewestTags_Topic = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.id DESC LIMIT ? OFFSET ?` - _TagsByKeywordA_Topic = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6` - _DecrTagsById_Topic = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)` - _HotTags_Topic = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.quote_num DESC LIMIT ? OFFSET ?` + _UserInfo_LightIndex = `SELECT * FROM @user WHERE username=?` + _NewestTags_Topic = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.id DESC LIMIT ? OFFSET ?` + _TagsByKeywordA_Topic = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6` + _TagsByKeywordB_Topic = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6` + _TagsByIdB_Topic = `SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)` + _HotTags_Topic = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.quote_num DESC LIMIT ? OFFSET ?` + _InsertTag_Topic = `INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)` + _TagsByIdA_Topic = `SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0` + _DecrTagsById_Topic = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)` + _TagsForIncr_Topic = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` + _IncrTagsById_Topic = `UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)` + _UserInfo_Wallet = `SELECT * FROM @user WHERE username=?` + _UserInfo_ContactManager = `SELECT * FROM @user WHERE username=?` + _UserInfo_FollowIndex = `SELECT * FROM @user WHERE username=?` + _UserInfo_SimpleIndex = `SELECT * FROM @user WHERE username=?` + _UserInfo_UserManage = `SELECT * FROM @user WHERE username=?` + _UserInfo_CommentManage = `SELECT * FROM @user WHERE username=?` + _UserInfo_Security = `SELECT * FROM @user WHERE username=?` + _UserInfo_TweetHelp = `SELECT * FROM @user WHERE username=?` + _UserInfo_AuthorizationManage = `SELECT * FROM @user WHERE username=?` + _UserInfo_Comment = `SELECT * FROM @user WHERE username=?` + _UserInfo_Message = `SELECT * FROM @user WHERE username=?` + _UserInfo_FriendIndex = `SELECT * FROM @user WHERE username=?` + _UserInfo_Tweet = `SELECT * FROM @user WHERE username=?` + _UserInfo_TweetManage = `SELECT * FROM @user WHERE username=?` ) +type AuthorizationManage struct { + yesql.Namespace `yesql:"authorization_manage"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + +type Comment struct { + yesql.Namespace `yesql:"comment"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + +type CommentManage struct { + yesql.Namespace `yesql:"comment_manage"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + +type ContactManager struct { + yesql.Namespace `yesql:"contact_manager"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + +type FollowIndex struct { + yesql.Namespace `yesql:"follow_index"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + +type FriendIndex struct { + yesql.Namespace `yesql:"friend_index"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + +type LightIndex struct { + yesql.Namespace `yesql:"light_index"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + +type Message struct { + yesql.Namespace `yesql:"message"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + +type Security struct { + yesql.Namespace `yesql:"security"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + +type SimpleIndex struct { + yesql.Namespace `yesql:"simple_index"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + type Topic struct { yesql.Namespace `yesql:"topic"` DecrTagsById string `yesql:"decr_tags_by_id"` @@ -38,6 +103,171 @@ type Topic struct { TagsByKeywordB *sqlx.Stmt `yesql:"tags_by_keyword_b"` } +type Tweet struct { + yesql.Namespace `yesql:"tweet"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + +type TweetHelp struct { + yesql.Namespace `yesql:"tweet_help"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + +type TweetManage struct { + yesql.Namespace `yesql:"tweet_manage"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + +type UserManage struct { + yesql.Namespace `yesql:"user_manage"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + +type Wallet struct { + yesql.Namespace `yesql:"wallet"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + +func BuildAuthorizationManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *AuthorizationManage, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &AuthorizationManage{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_AuthorizationManage))); err != nil { + return + } + return +} + +func BuildComment(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Comment, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &Comment{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_Comment))); err != nil { + return + } + return +} + +func BuildCommentManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *CommentManage, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &CommentManage{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_CommentManage))); err != nil { + return + } + return +} + +func BuildContactManager(p yesql.PreparexBuilder, ctx ...context.Context) (obj *ContactManager, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &ContactManager{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_ContactManager))); err != nil { + return + } + return +} + +func BuildFollowIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *FollowIndex, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &FollowIndex{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_FollowIndex))); err != nil { + return + } + return +} + +func BuildFriendIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *FriendIndex, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &FriendIndex{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_FriendIndex))); err != nil { + return + } + return +} + +func BuildLightIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *LightIndex, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &LightIndex{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_LightIndex))); err != nil { + return + } + return +} + +func BuildMessage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Message, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &Message{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_Message))); err != nil { + return + } + return +} + +func BuildSecurity(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Security, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &Security{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_Security))); err != nil { + return + } + return +} + +func BuildSimpleIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *SimpleIndex, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &SimpleIndex{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_SimpleIndex))); err != nil { + return + } + return +} + func BuildTopic(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Topic, err error) { var c context.Context if len(ctx) > 0 && ctx[0] != nil { @@ -69,3 +299,73 @@ func BuildTopic(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Topic, er } return } + +func BuildTweet(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Tweet, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &Tweet{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_Tweet))); err != nil { + return + } + return +} + +func BuildTweetHelp(p yesql.PreparexBuilder, ctx ...context.Context) (obj *TweetHelp, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &TweetHelp{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_TweetHelp))); err != nil { + return + } + return +} + +func BuildTweetManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *TweetManage, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &TweetManage{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_TweetManage))); err != nil { + return + } + return +} + +func BuildUserManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *UserManage, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &UserManage{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_UserManage))); err != nil { + return + } + return +} + +func BuildWallet(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Wallet, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &Wallet{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_Wallet))); err != nil { + return + } + return +} diff --git a/internal/dao/sakila/yesql/yesql.sql b/internal/dao/sakila/yesql/yesql.sql index 4cf8dee0..e14e18d2 100644 --- a/internal/dao/sakila/yesql/yesql.sql +++ b/internal/dao/sakila/yesql/yesql.sql @@ -1,3 +1,110 @@ +-------------------------------------------------------------------------------- +-- authorization_manage sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@authorization_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- comment sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@comment +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- comment_manage sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@comment_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- contact_manager sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@contact_manager +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- message sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@message +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- security sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@security +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- friend_index sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@friend_index +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- follow_index sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@follow_index +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- light_index sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@light_index +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- simple_index sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@simple_index +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- tweet sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@tweet +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- tweet_manage sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@tweet_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- tweet_help sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@tweet_help +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- topic sql dml +-------------------------------------------------------------------------------- -- name: newest_tags@topic -- get newest tag information @@ -53,3 +160,19 @@ SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?); -- prepare: raw -- clause: in UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?); + +-------------------------------------------------------------------------------- +-- user_manage sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@user_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- wallet sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@wallet +-- prepare: stmt +SELECT * FROM @user WHERE username=? \ No newline at end of file