diff --git a/Makefile b/Makefile index 5aa5b24c..9a56e84e 100644 --- a/Makefile +++ b/Makefile @@ -84,7 +84,7 @@ gen-mir: .PHONY: gen-yesql gen-yesql: @go generate internal/dao/sakila/yesql/gen.go - @go fmt ./internal/dao/sakila/yesql/... + @go fmt ./internal/dao/sakila/auto/... .PHONY: gen-rpc gen-rpc: diff --git a/go.mod b/go.mod index b1d49af1..c6dbd466 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.4.0 github.com/alimy/mir/v4 v4.0.0 - github.com/alimy/yesql v1.8.0 + github.com/alimy/yesql v1.8.4 github.com/aliyun/aliyun-oss-go-sdk v2.2.8+incompatible github.com/allegro/bigcache/v3 v3.1.0 github.com/bitbus/sqlx v1.6.0 diff --git a/go.sum b/go.sum index d5071801..51fc32b8 100644 --- a/go.sum +++ b/go.sum @@ -127,8 +127,8 @@ github.com/alimy/cfg v0.4.0 h1:SslKPndmxRViT1ePWLmNsEq7okYP0GVeuowQlRWZPkw= github.com/alimy/cfg v0.4.0/go.mod h1:rOxbasTH2srl6StAjNF5Vyi8bfrdkl3fLGmOYtSw81c= github.com/alimy/mir/v4 v4.0.0 h1:MzGfmoLjjvR69jbZEmpKJO3tUuqB0RGRv1UWPbtukBg= github.com/alimy/mir/v4 v4.0.0/go.mod h1:d58dBvw2KImcVbAUANrciEV/of0arMNsI9c/5UNCMMc= -github.com/alimy/yesql v1.8.0 h1:nOyElCU740uQ+S1hmG49Kpb6Sve5zqKayCj7mL21Dro= -github.com/alimy/yesql v1.8.0/go.mod h1:ROvO5FnBWhyAMI+sSSGzoXi2q/cCs0cW3WuelHCkLlk= +github.com/alimy/yesql v1.8.4 h1:Nj4u681SS6uEQTOqXUXBSFnXI67akStnYtv6eYXjPlM= +github.com/alimy/yesql v1.8.4/go.mod h1:ROvO5FnBWhyAMI+sSSGzoXi2q/cCs0cW3WuelHCkLlk= github.com/aliyun/aliyun-oss-go-sdk v2.2.8+incompatible h1:6JF1bjhT0WN2srEmijfOFtVWwV91KZ6dJY1/JbdtGrI= github.com/aliyun/aliyun-oss-go-sdk v2.2.8+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= github.com/allegro/bigcache/v3 v3.1.0 h1:H2Vp8VOvxcrB91o86fUSVJFqeuz8kpyyB02eH3bSzwk= diff --git a/internal/dao/sakila/authority.go b/internal/dao/sakila/authority.go index 05885460..78d81228 100644 --- a/internal/dao/sakila/authority.go +++ b/internal/dao/sakila/authority.go @@ -9,7 +9,7 @@ import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" "github.com/rocboss/paopao-ce/internal/core/ms" - "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" + "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc" "github.com/rocboss/paopao-ce/pkg/types" "github.com/sirupsen/logrus" ) @@ -74,6 +74,6 @@ func (s *authorizationManageSrv) isFriend(userId int64, friendId int64) bool { func newAuthorizationManageService(db *sqlx.DB) core.AuthorizationManageService { return &authorizationManageSrv{ sqlxSrv: newSqlxSrv(db), - q: mustBuild(db, cc.BuildAuthorizationManage), + q: ccBuild(db, cc.BuildAuthorizationManage), } } diff --git a/internal/dao/sakila/auto/ac/yesql.go b/internal/dao/sakila/auto/ac/yesql.go new file mode 100644 index 00000000..2ebf69fe --- /dev/null +++ b/internal/dao/sakila/auto/ac/yesql.go @@ -0,0 +1,222 @@ +// Code generated by Yesql. DO NOT EDIT. +// versions: +// - Yesql v1.8.4 + +package ac + +import ( + "context" + + "github.com/alimy/yesql" + "github.com/bitbus/sqlx" +) + +const ( + _ShipIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` + _SimpleIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` + _TopicA_DecrTagsById = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)` + _TopicA_ExistTopicUser = `SELECT 1 FROM @topic_user WHERE user_id=? AND topic_id=? AND is_del=0` + _TopicA_FollowTags = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id "u.id", 1 as is_following, c.is_top, u.nickname "u.nickname", u.username "u.username", u.status "u.status", u.avatar "u.avatar", u.is_admin "u.is_admin" FROM @topic_user c JOIN @user u ON c.user_id = u.id JOIN @tag t ON c.topic_id = t.id WHERE c.is_del = 0 AND t.quote_num > 0 AND AND c.user_id=? ORDER BY t.quote_num DESC LIMIT ? OFFSET ?` + _TopicA_FollowTopic = `INSERT INTO @topic_user(user_id, topic_id, created_on) VALUES (?, ?, ?)` + _TopicA_HotTags = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id "u.id", u.nickname "u.nickname", u.username "u.username", u.status "u.status", u.avatar "u.avatar", u.is_admin "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 ?` + _TopicA_IncrTagsById = `UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)` + _TopicA_InsertTag = `INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)` + _TopicA_NewestTags = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id "u.id", u.nickname "u.nickname", u.username "u.username", u.status "u.status", u.avatar "u.avatar", u.is_admin "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 ?` + _TopicA_StickTopic = `UPDATE @topic_user SET is_top=1-is_top; modified_on=? WHERE user_id=? AND topic_id=? AND is_del=0` + _TopicA_TagsByIdA = `SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0` + _TopicA_TagsByIdB = `SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)` + _TopicA_TagsByKeywordA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6` + _TopicA_TagsByKeywordB = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6` + _TopicA_TagsForIncr = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` + _TopicA_TopicInfos = `SELECT topic_id, is_top FROM @topic_user WHERE is_del=0 AND user_id=? AND topic_id IN ?` + _TopicA_TopicIsTop = `SELECT is_top FROM @topic_user WHERE user_id=? AND topic_id=? AND is_del=0` + _TopicA_UnfollowTopic = `UPDATE @topic_user SET is_del=1, deleted_on=? WHERE user_id=? AND topic_id=? AND is_del=0` + _TweetA_AttachmentByTweetId = `SELECT * FROM @user WHERE username=?` + _TweetA_FavoriteByTweetId = `SELECT * FROM @user WHERE username=?` + _TweetA_ReactionByTweetId = `SELECT * FROM @user WHERE username=?` + _TweetA_TweetInfoById = `SELECT * FROM @user WHERE username=?` + _TweetA_TweetItemById = `SELECT * FROM @user WHERE username=?` + _TweetA_UserFavorites = `SELECT * FROM @user WHERE username=?` + _TweetA_UserInfo = `SELECT * FROM @user WHERE username=?` + _TweetA_UserReactions = `SELECT * FROM @user WHERE username=?` + _TweetA_UserTweetsByAdmin = `SELECT * FROM @user WHERE username=?` + _TweetA_UserTweetsByFriend = `SELECT * FROM @user WHERE username=?` + _TweetA_UserTweetsByGuest = `SELECT * FROM @user WHERE username=?` + _TweetA_UserTweetsBySelf = `SELECT * FROM @user WHERE username=?` + _TweetHelpA_UserInfo = `SELECT * FROM @user WHERE username=?` + _TweetManageA_UserInfo = `SELECT * FROM @user WHERE username=?` +) + +// PreparexContext enhances the Conn interface with context. +type PreparexContext interface { + // PrepareContext prepares a statement. + // The provided context is used for the preparation of the statement, not for + // the execution of the statement. + PreparexContext(ctx context.Context, query string) (*sqlx.Stmt, error) + + // PrepareNamedContext returns an sqlx.NamedStmt + PrepareNamedContext(ctx context.Context, query string) (*sqlx.NamedStmt, error) + + // Rebind rebind query to adapte SQL Driver + Rebind(query string) string +} + +// PreparexBuilder preparex builder interface for sqlx +type PreparexBuilder interface { + PreparexContext + QueryHook(query string) string +} + +type ShipIndexA struct { + yesql.Namespace `yesql:"ship_index_a"` + UserInfo string `yesql:"user_info"` +} + +type SimpleIndexA struct { + yesql.Namespace `yesql:"simple_index_a"` + UserInfo string `yesql:"user_info"` +} + +type TopicA struct { + yesql.Namespace `yesql:"topic_a"` + DecrTagsById string `yesql:"decr_tags_by_id"` + IncrTagsById string `yesql:"incr_tags_by_id"` + TagsByIdA string `yesql:"tags_by_id_a"` + TagsByIdB string `yesql:"tags_by_id_b"` + TagsForIncr string `yesql:"tags_for_incr"` + TopicInfos string `yesql:"topic_infos"` + ExistTopicUser *sqlx.Stmt `yesql:"exist_topic_user"` + FollowTags *sqlx.Stmt `yesql:"follow_tags"` + FollowTopic *sqlx.Stmt `yesql:"follow_topic"` + HotTags *sqlx.Stmt `yesql:"hot_tags"` + InsertTag *sqlx.Stmt `yesql:"insert_tag"` + NewestTags *sqlx.Stmt `yesql:"newest_tags"` + StickTopic *sqlx.Stmt `yesql:"stick_topic"` + TagsByKeywordA *sqlx.Stmt `yesql:"tags_by_keyword_a"` + TagsByKeywordB *sqlx.Stmt `yesql:"tags_by_keyword_b"` + TopicIsTop *sqlx.Stmt `yesql:"topic_is_top"` + UnfollowTopic *sqlx.Stmt `yesql:"unfollow_topic"` +} + +type TweetA struct { + yesql.Namespace `yesql:"tweet_a"` + AttachmentByTweetId string `yesql:"attachment_by_tweet_id"` + FavoriteByTweetId string `yesql:"favorite_by_tweet_id"` + ReactionByTweetId string `yesql:"reaction_by_tweet_id"` + TweetInfoById string `yesql:"tweet_info_by_id"` + TweetItemById string `yesql:"tweet_item_by_id"` + UserFavorites string `yesql:"user_favorites"` + UserInfo string `yesql:"user_info"` + UserReactions string `yesql:"user_reactions"` + UserTweetsByAdmin string `yesql:"user_tweets_by_admin"` + UserTweetsByFriend string `yesql:"user_tweets_by_friend"` + UserTweetsByGuest string `yesql:"user_tweets_by_guest"` + UserTweetsBySelf string `yesql:"user_tweets_by_self"` +} + +type TweetHelpA struct { + yesql.Namespace `yesql:"tweet_help_a"` + UserInfo string `yesql:"user_info"` +} + +type TweetManageA struct { + yesql.Namespace `yesql:"tweet_manage_a"` + UserInfo string `yesql:"user_info"` +} + +func BuildShipIndexA(p PreparexBuilder) (obj *ShipIndexA, err error) { + obj = &ShipIndexA{ + UserInfo: p.QueryHook(_ShipIndexA_UserInfo), + } + return +} + +func BuildSimpleIndexA(p PreparexBuilder) (obj *SimpleIndexA, err error) { + obj = &SimpleIndexA{ + UserInfo: p.QueryHook(_SimpleIndexA_UserInfo), + } + return +} + +func BuildTopicA(p PreparexBuilder, ctx ...context.Context) (obj *TopicA, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &TopicA{ + DecrTagsById: p.QueryHook(_TopicA_DecrTagsById), + IncrTagsById: p.QueryHook(_TopicA_IncrTagsById), + TagsByIdA: p.QueryHook(_TopicA_TagsByIdA), + TagsByIdB: p.QueryHook(_TopicA_TagsByIdB), + TagsForIncr: p.QueryHook(_TopicA_TagsForIncr), + TopicInfos: p.QueryHook(_TopicA_TopicInfos), + } + if obj.ExistTopicUser, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_ExistTopicUser))); err != nil { + return + } + if obj.FollowTags, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_FollowTags))); err != nil { + return + } + if obj.FollowTopic, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_FollowTopic))); err != nil { + return + } + if obj.HotTags, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_HotTags))); err != nil { + return + } + if obj.InsertTag, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_InsertTag))); err != nil { + return + } + if obj.NewestTags, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_NewestTags))); err != nil { + return + } + if obj.StickTopic, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_StickTopic))); err != nil { + return + } + if obj.TagsByKeywordA, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_TagsByKeywordA))); err != nil { + return + } + if obj.TagsByKeywordB, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_TagsByKeywordB))); err != nil { + return + } + if obj.TopicIsTop, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_TopicIsTop))); err != nil { + return + } + if obj.UnfollowTopic, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_UnfollowTopic))); err != nil { + return + } + return +} + +func BuildTweetA(p PreparexBuilder) (obj *TweetA, err error) { + obj = &TweetA{ + AttachmentByTweetId: p.QueryHook(_TweetA_AttachmentByTweetId), + FavoriteByTweetId: p.QueryHook(_TweetA_FavoriteByTweetId), + ReactionByTweetId: p.QueryHook(_TweetA_ReactionByTweetId), + TweetInfoById: p.QueryHook(_TweetA_TweetInfoById), + TweetItemById: p.QueryHook(_TweetA_TweetItemById), + UserFavorites: p.QueryHook(_TweetA_UserFavorites), + UserInfo: p.QueryHook(_TweetA_UserInfo), + UserReactions: p.QueryHook(_TweetA_UserReactions), + UserTweetsByAdmin: p.QueryHook(_TweetA_UserTweetsByAdmin), + UserTweetsByFriend: p.QueryHook(_TweetA_UserTweetsByFriend), + UserTweetsByGuest: p.QueryHook(_TweetA_UserTweetsByGuest), + UserTweetsBySelf: p.QueryHook(_TweetA_UserTweetsBySelf), + } + return +} + +func BuildTweetHelpA(p PreparexBuilder) (obj *TweetHelpA, err error) { + obj = &TweetHelpA{ + UserInfo: p.QueryHook(_TweetHelpA_UserInfo), + } + return +} + +func BuildTweetManageA(p PreparexBuilder) (obj *TweetManageA, err error) { + obj = &TweetManageA{ + UserInfo: p.QueryHook(_TweetManageA_UserInfo), + } + return +} diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/auto/cc/yesql.go similarity index 84% rename from internal/dao/sakila/yesql/cc/yesql.go rename to internal/dao/sakila/auto/cc/yesql.go index 5c807c5c..38fe0b8e 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/auto/cc/yesql.go @@ -1,6 +1,6 @@ // Code generated by Yesql. DO NOT EDIT. // versions: -// - Yesql v1.8.0 +// - Yesql v1.8.4 package cc @@ -12,8 +12,6 @@ import ( ) const ( - _TagsFromNames = `SELECT * FROM @tag WHERE tag IN (?) AND is_del=0` - _UpdateTagQuote = `UPDATE @tag SET quote_num=?, modified_on=? WHERE id=? AND is_del=0` _AuthorizationManage_BeFriendIds = `SELECT user_id FROM @contact WHERE friend_id=? AND status=2 AND is_del=0` _AuthorizationManage_IsFriend = `SELECT status FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0` _AuthorizationManage_MyFriendSet = `SELECT friend_id FROM @contact WHERE user_id=? AND status=2 AND is_del=0` @@ -66,45 +64,14 @@ const ( _Security_CreatePhoneCaptcha = `INSERT INTO @captcha (phone, captcha, expired_on, created_on) VALUES (:phone, :captcha, :expired_on, :created_on)` _Security_GetLatestPhoneCaptcha = `SELECT * FROM @captcha WHERE phone=? AND is_del=0` _Security_UsePhoneCaptcha = `UPDATE @captcha SET use_times=use_times+1, modified_on=? WHERE id=? AND is_del=0` - _ShipIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` _ShipIndex_IndexByAdmin = `SELECT * FROM @p_post WHERE is_del=0 ORDER BY is_top DESC, latest_replied_on DESC LIMIT ? OFFSET ?` _ShipIndex_IndexByGuest = `SELECT * FROM @p_post WHERE visibility=0 AND is_del=0 ORDER BY is_top DESC, latest_replied_on DESC LIMIT ? OFFSET ?` _ShipIndex_IndexBySelf = `SELECT * FROM @p_post WHERE is_del=0 AND (visibility=0 OR (visibility=1 AND user_id=?) OR (visibility=2 AND user_id IN ?)) ORDER BY is_top DESC, latest_replied_on DESC LIMIT ? OFFSET ?` _ShipIndex_IndexCountByAdmin = `SELECT count(*) FROM @p_post WHERE is_del=0` _ShipIndex_IndexCountByGuest = `SELECT count(*) FROM @p_post WHERE visibility=0 AND is_del=0` _ShipIndex_IndexCountBySelf = `SELECT count(*) FROM @p_post WHERE is_del=0 AND (visibility=0 OR (visibility=1 AND user_id=?) OR (visibility=2 AND user_id IN ?))` - _SimpleIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` _SimpleIndex_Index = `SELECT * FROM @p_post WHERE visibility=0 ORDER BY is_top DESC, latest_replied_on DESC LIMIT ? OFFSET ?` _SimpleIndex_IndexCount = `SELECT count(*) FROM @p_post WHERE visibility=0` - _TopicA_DecrTagsById = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)` - _TopicA_ExistTopicUser = `SELECT 1 FROM @topic_user WHERE user_id=? AND topic_id=? AND is_del=0` - _TopicA_FollowTags = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id "u.id", 1 as is_following, c.is_top, u.nickname "u.nickname", u.username "u.username", u.status "u.status", u.avatar "u.avatar", u.is_admin "u.is_admin" FROM @topic_user c JOIN @user u ON c.user_id = u.id JOIN @tag t ON c.topic_id = t.id WHERE c.is_del = 0 AND t.quote_num > 0 AND AND c.user_id=? ORDER BY t.quote_num DESC LIMIT ? OFFSET ?` - _TopicA_FollowTopic = `INSERT INTO @topic_user(user_id, topic_id, created_on) VALUES (?, ?, ?)` - _TopicA_HotTags = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id "u.id", u.nickname "u.nickname", u.username "u.username", u.status "u.status", u.avatar "u.avatar", u.is_admin "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 ?` - _TopicA_IncrTagsById = `UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)` - _TopicA_InsertTag = `INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)` - _TopicA_NewestTags = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id "u.id", u.nickname "u.nickname", u.username "u.username", u.status "u.status", u.avatar "u.avatar", u.is_admin "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 ?` - _TopicA_StickTopic = `UPDATE @topic_user SET is_top=1-is_top; modified_on=? WHERE user_id=? AND topic_id=? AND is_del=0` - _TopicA_TagsByIdA = `SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0` - _TopicA_TagsByIdB = `SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)` - _TopicA_TagsByKeywordA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6` - _TopicA_TagsByKeywordB = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6` - _TopicA_TagsForIncr = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` - _TopicA_TopicInfos = `SELECT topic_id, is_top FROM @topic_user WHERE is_del=0 AND user_id=? AND topic_id IN ?` - _TopicA_TopicIsTop = `SELECT is_top FROM @topic_user WHERE user_id=? AND topic_id=? AND is_del=0` - _TopicA_UnfollowTopic = `UPDATE @topic_user SET is_del=1, deleted_on=? WHERE user_id=? AND topic_id=? AND is_del=0` - _TweetA_AttachmentByTweetId = `SELECT * FROM @user WHERE username=?` - _TweetA_FavoriteByTweetId = `SELECT * FROM @user WHERE username=?` - _TweetA_ReactionByTweetId = `SELECT * FROM @user WHERE username=?` - _TweetA_TweetInfoById = `SELECT * FROM @user WHERE username=?` - _TweetA_TweetItemById = `SELECT * FROM @user WHERE username=?` - _TweetA_UserFavorites = `SELECT * FROM @user WHERE username=?` - _TweetA_UserInfo = `SELECT * FROM @user WHERE username=?` - _TweetA_UserReactions = `SELECT * FROM @user WHERE username=?` - _TweetA_UserTweetsByAdmin = `SELECT * FROM @user WHERE username=?` - _TweetA_UserTweetsByFriend = `SELECT * FROM @user WHERE username=?` - _TweetA_UserTweetsByGuest = `SELECT * FROM @user WHERE username=?` - _TweetA_UserTweetsBySelf = `SELECT * FROM @user WHERE username=?` _Tweet_GetAnyPostCount = `SELECT count(*) FROM @post WHERE visibility IN (?)` _Tweet_GetAnyPosts = `SELECT * FROM @post WHERE visibility IN (?) AND is_del=0 LIMIT ? OFFSET ?` _Tweet_GetPostAttachmentBill = `SELECT * FROM @post_attachment_bill WHERE post_id=? AND user_id=? AND is_del=0` @@ -119,10 +86,8 @@ const ( _Tweet_GetUserPostStarCount = `SELECT count(*) FROM @post_star s JOIN @post P ON s.post_id = P.ID WHERE s.user_id = ? AND s.is_del = 0 AND ( visibility <> 1 OR ( visibility = 1 AND P.user_id = ? ) )` _Tweet_GetUserPostStars = `SELECT s.*, P.ID "post.id", P.user_id "post.user_id", P.comment_count "post.comment_count", P.collection_count "post.collection_count", P.upvote_count "post.upvote_count", P.share_count "post.share_count", P.visibility "post.visibility", P.is_top "post.is_top", P.is_essence "post.is_essence", P.is_lock "post.is_lock", P.latest_replied_on "post.latest_replied_on", P.tags "post.tags", P.attachment_price "post.attachment_price", P.ip "post.ip", P.ip_loc "post.ip_loc", P.is_del "post.is_del", P.created_on "post.created_on", P.modified_on "post.modified_on", P.deleted_on "post.deleted_on" FROM @post_star s JOIN @post P ON s.post_id = P.ID WHERE s.user_id = ? AND s.is_del = 0 AND ( visibility <> 1 OR ( visibility = 1 AND P.user_id = ? ) ) ORDER BY s.ID DESC, P.ID DESC LIMIT ? OFFSET ?` _Tweet_GetUserPosts = `SELECT * FROM @post WHERE user_id=? AND visibility IN (?) ORDER BY latest_replies_on DESC LIMIT ? OFFSET ?` - _TweetHelpA_UserInfo = `SELECT * FROM @user WHERE username=?` _TweetHelp_GetPostContentByIds = `SELECT id, post_id, content, type, sort FROM @post_content WHERE post_id IN (?) AND is_del=0` _TweetHelp_GetUsersByIds = `SELECT id, username, nickname, status, avatar, is_admin FROM @user WHERE id IN (?) AND is_del=0` - _TweetManageA_UserInfo = `SELECT * FROM @user WHERE username=?` _TweetManage_AddAttachment = `INSERT INTO @attachment (user_id, file_size, img_width, img_height, type, content, created_on) VALUES (?, ?, ?, ?, ?, ?, ?)` _TweetManage_AddPost = `INSERT INTO @post (user_id, tags, ip, ip_loc, attachment_price, visibility, latest_replies_on, created_on) VALUES (:user_id, :tags, :ip, :ip_loc, :attachment_price, :visibility, :latest_replies_on, :created_on)` _TweetManage_AddPostCollection = `INSERT INTO @post_collection (post_id, user_id, created_on) VALUES (?, ?, ?)` @@ -205,11 +170,6 @@ type PreparexBuilder interface { QueryHook(query string) string } -type Yesql struct { - TagsFromNames string `yesql:"tags_from_names"` - UpdateTagQuote *sqlx.Stmt `yesql:"update_tag_quote"` -} - type AuthorizationManage struct { yesql.Namespace `yesql:"authorization_manage"` BeFriendIds *sqlx.Stmt `yesql:"be_friend_ids"` @@ -300,43 +260,12 @@ type ShipIndex struct { IndexCountByGuest *sqlx.Stmt `yesql:"index_count_by_guest"` } -type ShipIndexA struct { - yesql.Namespace `yesql:"ship_index_a"` - UserInfo string `yesql:"user_info"` -} - type SimpleIndex struct { yesql.Namespace `yesql:"simple_index"` Index *sqlx.Stmt `yesql:"index"` IndexCount *sqlx.Stmt `yesql:"index_count"` } -type SimpleIndexA struct { - yesql.Namespace `yesql:"simple_index_a"` - UserInfo string `yesql:"user_info"` -} - -type TopicA struct { - yesql.Namespace `yesql:"topic_a"` - DecrTagsById string `yesql:"decr_tags_by_id"` - IncrTagsById string `yesql:"incr_tags_by_id"` - TagsByIdA string `yesql:"tags_by_id_a"` - TagsByIdB string `yesql:"tags_by_id_b"` - TagsForIncr string `yesql:"tags_for_incr"` - TopicInfos string `yesql:"topic_infos"` - ExistTopicUser *sqlx.Stmt `yesql:"exist_topic_user"` - FollowTags *sqlx.Stmt `yesql:"follow_tags"` - FollowTopic *sqlx.Stmt `yesql:"follow_topic"` - HotTags *sqlx.Stmt `yesql:"hot_tags"` - InsertTag *sqlx.Stmt `yesql:"insert_tag"` - NewestTags *sqlx.Stmt `yesql:"newest_tags"` - StickTopic *sqlx.Stmt `yesql:"stick_topic"` - TagsByKeywordA *sqlx.Stmt `yesql:"tags_by_keyword_a"` - TagsByKeywordB *sqlx.Stmt `yesql:"tags_by_keyword_b"` - TopicIsTop *sqlx.Stmt `yesql:"topic_is_top"` - UnfollowTopic *sqlx.Stmt `yesql:"unfollow_topic"` -} - type Tweet struct { yesql.Namespace `yesql:"tweet"` GetAnyPostCount string `yesql:"get_any_post_count"` @@ -375,33 +304,12 @@ type Tweet struct { UserStarTweetsCountBySelf *sqlx.Stmt `yesql:"user_star_tweets_count_by_self"` } -type TweetA struct { - yesql.Namespace `yesql:"tweet_a"` - AttachmentByTweetId string `yesql:"attachment_by_tweet_id"` - FavoriteByTweetId string `yesql:"favorite_by_tweet_id"` - ReactionByTweetId string `yesql:"reaction_by_tweet_id"` - TweetInfoById string `yesql:"tweet_info_by_id"` - TweetItemById string `yesql:"tweet_item_by_id"` - UserFavorites string `yesql:"user_favorites"` - UserInfo string `yesql:"user_info"` - UserReactions string `yesql:"user_reactions"` - UserTweetsByAdmin string `yesql:"user_tweets_by_admin"` - UserTweetsByFriend string `yesql:"user_tweets_by_friend"` - UserTweetsByGuest string `yesql:"user_tweets_by_guest"` - UserTweetsBySelf string `yesql:"user_tweets_by_self"` -} - type TweetHelp struct { yesql.Namespace `yesql:"tweet_help"` GetPostContentByIds string `yesql:"get_post_content_by_ids"` GetUsersByIds string `yesql:"get_users_by_ids"` } -type TweetHelpA struct { - yesql.Namespace `yesql:"tweet_help_a"` - UserInfo string `yesql:"user_info"` -} - type TweetManage struct { yesql.Namespace `yesql:"tweet_manage"` CommentMediaFromCommentIds string `yesql:"comment_media_from_comment_ids"` @@ -426,11 +334,6 @@ type TweetManage struct { UpdatePost *sqlx.NamedStmt `yesql:"update_post"` } -type TweetManageA struct { - yesql.Namespace `yesql:"tweet_manage_a"` - UserInfo string `yesql:"user_info"` -} - type UserManage struct { yesql.Namespace `yesql:"user_manage"` GetUsersByIds string `yesql:"get_users_by_ids"` @@ -459,22 +362,6 @@ type Wallet struct { NewPostBill *sqlx.Stmt `yesql:"new_post_bill"` } -func BuildYesql(p PreparexBuilder, ctx ...context.Context) (obj *Yesql, err error) { - var c context.Context - if len(ctx) > 0 && ctx[0] != nil { - c = ctx[0] - } else { - c = context.Background() - } - obj = &Yesql{ - TagsFromNames: p.QueryHook(_TagsFromNames), - } - if obj.UpdateTagQuote, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UpdateTagQuote))); err != nil { - return - } - return -} - func BuildAuthorizationManage(p PreparexBuilder, ctx ...context.Context) (obj *AuthorizationManage, err error) { var c context.Context if len(ctx) > 0 && ctx[0] != nil { @@ -727,13 +614,6 @@ func BuildShipIndex(p PreparexBuilder, ctx ...context.Context) (obj *ShipIndex, return } -func BuildShipIndexA(p PreparexBuilder) (obj *ShipIndexA, err error) { - obj = &ShipIndexA{ - UserInfo: p.QueryHook(_ShipIndexA_UserInfo), - } - return -} - func BuildSimpleIndex(p PreparexBuilder, ctx ...context.Context) (obj *SimpleIndex, err error) { var c context.Context if len(ctx) > 0 && ctx[0] != nil { @@ -751,64 +631,6 @@ func BuildSimpleIndex(p PreparexBuilder, ctx ...context.Context) (obj *SimpleInd return } -func BuildSimpleIndexA(p PreparexBuilder) (obj *SimpleIndexA, err error) { - obj = &SimpleIndexA{ - UserInfo: p.QueryHook(_SimpleIndexA_UserInfo), - } - return -} - -func BuildTopicA(p PreparexBuilder, ctx ...context.Context) (obj *TopicA, err error) { - var c context.Context - if len(ctx) > 0 && ctx[0] != nil { - c = ctx[0] - } else { - c = context.Background() - } - obj = &TopicA{ - DecrTagsById: p.QueryHook(_TopicA_DecrTagsById), - IncrTagsById: p.QueryHook(_TopicA_IncrTagsById), - TagsByIdA: p.QueryHook(_TopicA_TagsByIdA), - TagsByIdB: p.QueryHook(_TopicA_TagsByIdB), - TagsForIncr: p.QueryHook(_TopicA_TagsForIncr), - TopicInfos: p.QueryHook(_TopicA_TopicInfos), - } - if obj.ExistTopicUser, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_ExistTopicUser))); err != nil { - return - } - if obj.FollowTags, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_FollowTags))); err != nil { - return - } - if obj.FollowTopic, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_FollowTopic))); err != nil { - return - } - if obj.HotTags, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_HotTags))); err != nil { - return - } - if obj.InsertTag, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_InsertTag))); err != nil { - return - } - if obj.NewestTags, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_NewestTags))); err != nil { - return - } - if obj.StickTopic, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_StickTopic))); err != nil { - return - } - if obj.TagsByKeywordA, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_TagsByKeywordA))); err != nil { - return - } - if obj.TagsByKeywordB, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_TagsByKeywordB))); err != nil { - return - } - if obj.TopicIsTop, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_TopicIsTop))); err != nil { - return - } - if obj.UnfollowTopic, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_UnfollowTopic))); err != nil { - return - } - return -} - func BuildTweet(p PreparexBuilder, ctx ...context.Context) (obj *Tweet, err error) { var c context.Context if len(ctx) > 0 && ctx[0] != nil { @@ -913,24 +735,6 @@ func BuildTweet(p PreparexBuilder, ctx ...context.Context) (obj *Tweet, err erro return } -func BuildTweetA(p PreparexBuilder) (obj *TweetA, err error) { - obj = &TweetA{ - AttachmentByTweetId: p.QueryHook(_TweetA_AttachmentByTweetId), - FavoriteByTweetId: p.QueryHook(_TweetA_FavoriteByTweetId), - ReactionByTweetId: p.QueryHook(_TweetA_ReactionByTweetId), - TweetInfoById: p.QueryHook(_TweetA_TweetInfoById), - TweetItemById: p.QueryHook(_TweetA_TweetItemById), - UserFavorites: p.QueryHook(_TweetA_UserFavorites), - UserInfo: p.QueryHook(_TweetA_UserInfo), - UserReactions: p.QueryHook(_TweetA_UserReactions), - UserTweetsByAdmin: p.QueryHook(_TweetA_UserTweetsByAdmin), - UserTweetsByFriend: p.QueryHook(_TweetA_UserTweetsByFriend), - UserTweetsByGuest: p.QueryHook(_TweetA_UserTweetsByGuest), - UserTweetsBySelf: p.QueryHook(_TweetA_UserTweetsBySelf), - } - return -} - func BuildTweetHelp(p PreparexBuilder) (obj *TweetHelp, err error) { obj = &TweetHelp{ GetPostContentByIds: p.QueryHook(_TweetHelp_GetPostContentByIds), @@ -939,13 +743,6 @@ func BuildTweetHelp(p PreparexBuilder) (obj *TweetHelp, err error) { return } -func BuildTweetHelpA(p PreparexBuilder) (obj *TweetHelpA, err error) { - obj = &TweetHelpA{ - UserInfo: p.QueryHook(_TweetHelpA_UserInfo), - } - return -} - func BuildTweetManage(p PreparexBuilder, ctx ...context.Context) (obj *TweetManage, err error) { var c context.Context if len(ctx) > 0 && ctx[0] != nil { @@ -1012,13 +809,6 @@ func BuildTweetManage(p PreparexBuilder, ctx ...context.Context) (obj *TweetMana return } -func BuildTweetManageA(p PreparexBuilder) (obj *TweetManageA, err error) { - obj = &TweetManageA{ - UserInfo: p.QueryHook(_TweetManageA_UserInfo), - } - return -} - func BuildUserManage(p PreparexBuilder, ctx ...context.Context) (obj *UserManage, err error) { var c context.Context if len(ctx) > 0 && ctx[0] != nil { diff --git a/internal/dao/sakila/auto/yesql.go b/internal/dao/sakila/auto/yesql.go new file mode 100644 index 00000000..35aac96f --- /dev/null +++ b/internal/dao/sakila/auto/yesql.go @@ -0,0 +1,57 @@ +// Code generated by Yesql. DO NOT EDIT. +// versions: +// - Yesql v1.8.4 + +package yesql + +import ( + "context" + + "github.com/bitbus/sqlx" +) + +const ( + _TagsFromNames = `SELECT * FROM @tag WHERE tag IN (?) AND is_del=0` + _UpdateTagQuote = `UPDATE @tag SET quote_num=?, modified_on=? WHERE id=? AND is_del=0` +) + +// PreparexContext enhances the Conn interface with context. +type PreparexContext interface { + // PrepareContext prepares a statement. + // The provided context is used for the preparation of the statement, not for + // the execution of the statement. + PreparexContext(ctx context.Context, query string) (*sqlx.Stmt, error) + + // PrepareNamedContext returns an sqlx.NamedStmt + PrepareNamedContext(ctx context.Context, query string) (*sqlx.NamedStmt, error) + + // Rebind rebind query to adapte SQL Driver + Rebind(query string) string +} + +// PreparexBuilder preparex builder interface for sqlx +type PreparexBuilder interface { + PreparexContext + QueryHook(query string) string +} + +type Yesql struct { + TagsFromNames string `yesql:"tags_from_names"` + UpdateTagQuote *sqlx.Stmt `yesql:"update_tag_quote"` +} + +func BuildYesql(p PreparexBuilder, ctx ...context.Context) (obj *Yesql, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &Yesql{ + TagsFromNames: p.QueryHook(_TagsFromNames), + } + if obj.UpdateTagQuote, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UpdateTagQuote))); err != nil { + return + } + return +} diff --git a/internal/dao/sakila/comments.go b/internal/dao/sakila/comments.go index 1455afad..328619f7 100644 --- a/internal/dao/sakila/comments.go +++ b/internal/dao/sakila/comments.go @@ -13,7 +13,7 @@ import ( "github.com/rocboss/paopao-ce/internal/core/cs" "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" - "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" + "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc" "github.com/rocboss/paopao-ce/pkg/types" ) @@ -374,13 +374,13 @@ func (s *commentManageSrv) ThumbsDownReply(userId int64, tweetId, commentId, rep func newCommentService(db *sqlx.DB) core.CommentService { return &commentSrv{ sqlxSrv: newSqlxSrv(db), - q: mustBuild(db, cc.BuildComment), + q: ccBuild(db, cc.BuildComment), } } func newCommentManageService(db *sqlx.DB) core.CommentManageService { return &commentManageSrv{ sqlxSrv: newSqlxSrv(db), - q: mustBuild(db, cc.BuildCommentManage), + q: ccBuild(db, cc.BuildCommentManage), } } diff --git a/internal/dao/sakila/contacts.go b/internal/dao/sakila/contacts.go index 40d5eb82..b5d48181 100644 --- a/internal/dao/sakila/contacts.go +++ b/internal/dao/sakila/contacts.go @@ -11,7 +11,7 @@ import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" "github.com/rocboss/paopao-ce/internal/core/ms" - "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" + "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc" "github.com/sirupsen/logrus" ) @@ -182,6 +182,6 @@ func (s *contactManageSrv) fetchOrNewContact(tx *sqlx.Tx, userId int64, friendId func newContactManageService(db *sqlx.DB) core.ContactManageService { return &contactManageSrv{ sqlxSrv: newSqlxSrv(db), - q: mustBuild(db, cc.BuildContactManager), + q: ccBuild(db, cc.BuildContactManager), } } diff --git a/internal/dao/sakila/following.go b/internal/dao/sakila/following.go index 7abab267..6ec611ac 100644 --- a/internal/dao/sakila/following.go +++ b/internal/dao/sakila/following.go @@ -10,7 +10,7 @@ import ( "github.com/bitbus/sqlx" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" - "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" + "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc" ) var ( @@ -97,6 +97,6 @@ func (s *followingManageSrv) IsFollow(userId int64, followId int64) (yn bool) { func newFollowingManageService(db *sqlx.DB) core.FollowingManageService { return &followingManageSrv{ sqlxSrv: newSqlxSrv(db), - q: mustBuild(db, cc.BuildFollowingManager), + q: ccBuild(db, cc.BuildFollowingManager), } } diff --git a/internal/dao/sakila/messages.go b/internal/dao/sakila/messages.go index 7e9e45eb..1d013143 100644 --- a/internal/dao/sakila/messages.go +++ b/internal/dao/sakila/messages.go @@ -11,7 +11,7 @@ import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" - "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" + "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc" ) var ( @@ -75,6 +75,6 @@ func (s *messageSrv) GetMessageCount(r *ms.ConditionsT) (res int64, err error) { func newMessageService(db *sqlx.DB) core.MessageService { return &messageSrv{ sqlxSrv: newSqlxSrv(db), - q: mustBuild(db, cc.BuildMessage), + q: ccBuild(db, cc.BuildMessage), } } diff --git a/internal/dao/sakila/security.go b/internal/dao/sakila/security.go index 1f0674d3..4df9031d 100644 --- a/internal/dao/sakila/security.go +++ b/internal/dao/sakila/security.go @@ -13,7 +13,7 @@ import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" - "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" + "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc" ) var ( @@ -63,7 +63,7 @@ func (s *securitySrv) SendPhoneCaptcha(phone string) error { func newSecurityService(db *sqlx.DB, phoneVerify core.PhoneVerifyService) core.SecurityService { return &securitySrv{ sqlxSrv: newSqlxSrv(db), - q: mustBuild(db, cc.BuildSecurity), + q: ccBuild(db, cc.BuildSecurity), rand: rand.New(rand.NewSource(time.Now().UnixNano())), phoneVerify: phoneVerify, } diff --git a/internal/dao/sakila/sqlx.go b/internal/dao/sakila/sqlx.go index c0c8721b..9877d51e 100644 --- a/internal/dao/sakila/sqlx.go +++ b/internal/dao/sakila/sqlx.go @@ -11,7 +11,9 @@ import ( "github.com/alimy/yesql" "github.com/bitbus/sqlx" "github.com/rocboss/paopao-ce/internal/conf" - "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" + yc "github.com/rocboss/paopao-ce/internal/dao/sakila/auto" + "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/ac" + "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc" "github.com/sirupsen/logrus" ) @@ -22,13 +24,13 @@ var ( type sqlxSrv struct { db *sqlx.DB - y *cc.Yesql + y *yc.Yesql } func newSqlxSrv(db *sqlx.DB) *sqlxSrv { return &sqlxSrv{ db: db, - y: mustBuild(db, cc.BuildYesql), + y: mustBuild(db, yc.BuildYesql), } } @@ -92,7 +94,7 @@ func yesqlScan[T any](query yesql.SQLQuery, obj T) T { return obj } -func mustBuild[T any](db *sqlx.DB, fn func(cc.PreparexBuilder, ...context.Context) (T, error)) T { +func mustBuild[T any](db *sqlx.DB, fn func(yc.PreparexBuilder, ...context.Context) (T, error)) T { p := yesql.NewPreparexBuilder(db, t) obj, err := fn(p) if err != nil { @@ -101,7 +103,43 @@ func mustBuild[T any](db *sqlx.DB, fn func(cc.PreparexBuilder, ...context.Contex return obj } -func mustBuildFn[T any](db *sqlx.DB, fn func(cc.PreparexBuilder) (T, error)) T { +func mustBuildFn[T any](db *sqlx.DB, fn func(yc.PreparexBuilder) (T, error)) T { + p := yesql.NewPreparexBuilder(db, t) + obj, err := fn(p) + if err != nil { + logrus.Fatalf("build object failure: %s", err) + } + return obj +} + +func acBuild[T any](db *sqlx.DB, fn func(ac.PreparexBuilder, ...context.Context) (T, error)) T { + p := yesql.NewPreparexBuilder(db, t) + obj, err := fn(p) + if err != nil { + logrus.Fatalf("build object failure: %s", err) + } + return obj +} + +func acBuildFn[T any](db *sqlx.DB, fn func(ac.PreparexBuilder) (T, error)) T { + p := yesql.NewPreparexBuilder(db, t) + obj, err := fn(p) + if err != nil { + logrus.Fatalf("build object failure: %s", err) + } + return obj +} + +func ccBuild[T any](db *sqlx.DB, fn func(cc.PreparexBuilder, ...context.Context) (T, error)) T { + p := yesql.NewPreparexBuilder(db, t) + obj, err := fn(p) + if err != nil { + logrus.Fatalf("build object failure: %s", err) + } + return obj +} + +func ccBuildFn[T any](db *sqlx.DB, fn func(cc.PreparexBuilder) (T, error)) T { p := yesql.NewPreparexBuilder(db, t) obj, err := fn(p) if err != nil { diff --git a/internal/dao/sakila/timeline.go b/internal/dao/sakila/timeline.go index cc685596..8f6e3fdd 100644 --- a/internal/dao/sakila/timeline.go +++ b/internal/dao/sakila/timeline.go @@ -9,7 +9,8 @@ import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" "github.com/rocboss/paopao-ce/internal/core/ms" - "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" + "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/ac" + "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc" "github.com/rocboss/paopao-ce/pkg/debug" "github.com/sirupsen/logrus" ) @@ -39,13 +40,13 @@ type shipIndexSrvA struct { *sqlxSrv ams core.AuthorizationManageService ths core.TweetHelpServantA - q *cc.ShipIndexA + q *ac.ShipIndexA } type simpleIndexPostsSrvA struct { *sqlxSrv ths core.TweetHelpServantA - q *cc.SimpleIndexA + q *ac.SimpleIndexA } // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; @@ -115,7 +116,7 @@ func newShipIndexService(db *sqlx.DB, ams core.AuthorizationManageService, ths c ams: ams, ths: ths, sqlxSrv: newSqlxSrv(db), - q: mustBuild(db, cc.BuildShipIndex), + q: ccBuild(db, cc.BuildShipIndex), } } @@ -123,7 +124,7 @@ func newSimpleIndexPostsService(db *sqlx.DB, ths core.TweetHelpService) core.Ind return &simpleIndexPostsSrv{ ths: ths, sqlxSrv: newSqlxSrv(db), - q: mustBuild(db, cc.BuildSimpleIndex), + q: ccBuild(db, cc.BuildSimpleIndex), } } @@ -133,7 +134,7 @@ func newShipIndexServantA(db *sqlx.DB, ams core.AuthorizationManageService, ths ams: ams, ths: ths, sqlxSrv: newSqlxSrv(db), - q: mustBuildFn(db, cc.BuildShipIndexA), + q: acBuildFn(db, ac.BuildShipIndexA), } } @@ -142,6 +143,6 @@ func newSimpleIndexPostsServantA(db *sqlx.DB, ths core.TweetHelpServantA) core.I return &simpleIndexPostsSrvA{ ths: ths, sqlxSrv: newSqlxSrv(db), - q: mustBuildFn(db, cc.BuildSimpleIndexA), + q: acBuildFn(db, ac.BuildSimpleIndexA), } } diff --git a/internal/dao/sakila/topics.go b/internal/dao/sakila/topics.go index 9793f741..b4be80be 100644 --- a/internal/dao/sakila/topics.go +++ b/internal/dao/sakila/topics.go @@ -11,7 +11,7 @@ import ( "github.com/bitbus/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/internal/dao/sakila/auto/ac" ) var ( @@ -26,7 +26,7 @@ type topicInfo struct { type topicSrvA struct { *sqlxSrv - q *cc.TopicA + q *ac.TopicA } func (s *topicSrvA) UpsertTags(userId int64, tags []string) (res cs.TagInfoList, xerr error) { @@ -190,13 +190,13 @@ func (s *topicSrvA) tagsFormatA(userId int64, tags cs.TagList) (cs.TagList, erro func newTopicService(db *sqlx.DB) core.TopicService { return &topicSrvA{ sqlxSrv: newSqlxSrv(db), - q: mustBuild(db, cc.BuildTopicA), + q: acBuild(db, ac.BuildTopicA), } } func newTopicServantA(db *sqlx.DB) core.TopicServantA { return &topicSrvA{ sqlxSrv: newSqlxSrv(db), - q: mustBuild(db, cc.BuildTopicA), + q: acBuild(db, ac.BuildTopicA), } } diff --git a/internal/dao/sakila/tweets.go b/internal/dao/sakila/tweets.go index 94f04b0a..c0ffcb6f 100644 --- a/internal/dao/sakila/tweets.go +++ b/internal/dao/sakila/tweets.go @@ -13,18 +13,13 @@ import ( "github.com/rocboss/paopao-ce/internal/core/cs" "github.com/rocboss/paopao-ce/internal/core/ms" "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" + "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc" ) var ( _ core.TweetService = (*tweetSrv)(nil) _ core.TweetManageService = (*tweetManageSrv)(nil) _ core.TweetHelpService = (*tweetHelpSrv)(nil) - - _ core.TweetServantA = (*tweetSrvA)(nil) - _ core.TweetManageServantA = (*tweetManageSrvA)(nil) - _ core.TweetHelpServantA = (*tweetHelpSrvA)(nil) ) type tweetSrv struct { @@ -43,22 +38,6 @@ type tweetHelpSrv struct { q *cc.TweetHelp } -type tweetSrvA struct { - *sqlxSrv - q *cc.TweetA -} - -type tweetManageSrvA struct { - *sqlxSrv - cis core.CacheIndexService - q *cc.TweetManageA -} - -type tweetHelpSrvA struct { - *sqlxSrv - q *cc.TweetHelpA -} - // MergePosts post数据整合 func (s *tweetHelpSrv) MergePosts(posts []*ms.Post) ([]*ms.PostFormated, error) { postIds := make([]int64, 0, len(posts)) @@ -480,110 +459,10 @@ func (s *tweetSrv) GetPostContentByID(id int64) (res *ms.PostContent, err error) return } -func (s *tweetSrvA) TweetInfoById(id int64) (*cs.TweetInfo, error) { - // TODO - return nil, debug.ErrNotImplemented -} - -func (s *tweetSrvA) TweetItemById(id int64) (*cs.TweetItem, error) { - // TODO - return nil, debug.ErrNotImplemented -} - -func (s *tweetSrvA) UserTweets(visitorId, userId int64) (res cs.TweetList, err error) { - // TODO - return nil, debug.ErrNotImplemented -} - -func (s *tweetSrvA) ReactionByTweetId(userId int64, tweetId int64) (*cs.ReactionItem, error) { - // TODO - return nil, debug.ErrNotImplemented -} - -func (s *tweetSrvA) UserReactions(userId int64, limit int, offset int) (cs.ReactionList, error) { - // TODO - return nil, debug.ErrNotImplemented -} - -func (s *tweetSrvA) FavoriteByTweetId(userId int64, tweetId int64) (*cs.FavoriteItem, error) { - // TODO - return nil, debug.ErrNotImplemented -} - -func (s *tweetSrvA) UserFavorites(userId int64, limit int, offset int) (cs.FavoriteList, error) { - // TODO - return nil, debug.ErrNotImplemented -} - -func (s *tweetSrvA) AttachmentByTweetId(userId int64, tweetId int64) (*cs.AttachmentBill, error) { - // TODO - return nil, debug.ErrNotImplemented -} - -func (s *tweetManageSrvA) CreateAttachment(obj *cs.Attachment) (int64, error) { - // TODO - return 0, debug.ErrNotImplemented -} - -func (s *tweetManageSrvA) CreateTweet(userId int64, req *cs.NewTweetReq) (*cs.TweetItem, error) { - // TODO - return nil, debug.ErrNotImplemented -} - -func (s *tweetManageSrvA) DeleteTweet(userId int64, tweetId int64) ([]string, error) { - // TODO - return nil, debug.ErrNotImplemented -} - -func (s *tweetManageSrvA) LockTweet(userId int64, tweetId int64) error { - // TODO - return debug.ErrNotImplemented -} - -func (s *tweetManageSrvA) StickTweet(userId int64, tweetId int64) error { - // TODO - return debug.ErrNotImplemented -} - -func (s *tweetManageSrvA) VisibleTweet(userId int64, visibility cs.TweetVisibleType) error { - // TODO - return debug.ErrNotImplemented -} - -func (s *tweetManageSrvA) CreateReaction(userId int64, tweetId int64) error { - // TODO - return debug.ErrNotImplemented -} - -func (s *tweetManageSrvA) DeleteReaction(userId int64, reactionId int64) error { - // TODO - return debug.ErrNotImplemented -} - -func (s *tweetManageSrvA) CreateFavorite(userId int64, tweetId int64) error { - // TODO - return debug.ErrNotImplemented -} - -func (s *tweetManageSrvA) DeleteFavorite(userId int64, favoriteId int64) error { - // TODO - return debug.ErrNotImplemented -} - -func (s *tweetHelpSrvA) RevampTweets(tweets cs.TweetList) (cs.TweetList, error) { - // TODO - return nil, debug.ErrNotImplemented -} - -func (s *tweetHelpSrvA) MergeTweets(tweets cs.TweetInfo) (cs.TweetList, error) { - // TODO - return nil, debug.ErrNotImplemented -} - func newTweetService(db *sqlx.DB) core.TweetService { return &tweetSrv{ sqlxSrv: newSqlxSrv(db), - q: mustBuild(db, cc.BuildTweet), + q: ccBuild(db, cc.BuildTweet), } } @@ -591,35 +470,13 @@ func newTweetManageService(db *sqlx.DB, cacheIndex core.CacheIndexService) core. return &tweetManageSrv{ sqlxSrv: newSqlxSrv(db), cis: cacheIndex, - q: mustBuild(db, cc.BuildTweetManage), + q: ccBuild(db, cc.BuildTweetManage), } } func newTweetHelpService(db *sqlx.DB) core.TweetHelpService { return &tweetHelpSrv{ sqlxSrv: newSqlxSrv(db), - q: mustBuildFn(db, cc.BuildTweetHelp), - } -} - -func newTweetServantA(db *sqlx.DB) core.TweetServantA { - return &tweetSrvA{ - sqlxSrv: newSqlxSrv(db), - q: mustBuildFn(db, cc.BuildTweetA), - } -} - -func newTweetManageServantA(db *sqlx.DB, cacheIndex core.CacheIndexService) core.TweetManageServantA { - return &tweetManageSrvA{ - sqlxSrv: newSqlxSrv(db), - cis: cacheIndex, - q: mustBuildFn(db, cc.BuildTweetManageA), - } -} - -func newTweetHelpServantA(db *sqlx.DB) core.TweetHelpServantA { - return &tweetHelpSrvA{ - sqlxSrv: newSqlxSrv(db), - q: mustBuildFn(db, cc.BuildTweetHelpA), + q: ccBuildFn(db, cc.BuildTweetHelp), } } diff --git a/internal/dao/sakila/tweets_a.go b/internal/dao/sakila/tweets_a.go new file mode 100644 index 00000000..2dc725e9 --- /dev/null +++ b/internal/dao/sakila/tweets_a.go @@ -0,0 +1,157 @@ +// Copyright 2023 ROC. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +package sakila + +import ( + "github.com/bitbus/sqlx" + "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/ac" + "github.com/rocboss/paopao-ce/pkg/debug" +) + +var ( + _ core.TweetServantA = (*tweetSrvA)(nil) + _ core.TweetManageServantA = (*tweetManageSrvA)(nil) + _ core.TweetHelpServantA = (*tweetHelpSrvA)(nil) +) + +type tweetSrvA struct { + *sqlxSrv + q *ac.TweetA +} + +type tweetManageSrvA struct { + *sqlxSrv + cis core.CacheIndexService + q *ac.TweetManageA +} + +type tweetHelpSrvA struct { + *sqlxSrv + q *ac.TweetHelpA +} + +func (s *tweetSrvA) TweetInfoById(id int64) (*cs.TweetInfo, error) { + // TODO + return nil, debug.ErrNotImplemented +} + +func (s *tweetSrvA) TweetItemById(id int64) (*cs.TweetItem, error) { + // TODO + return nil, debug.ErrNotImplemented +} + +func (s *tweetSrvA) UserTweets(visitorId, userId int64) (res cs.TweetList, err error) { + // TODO + return nil, debug.ErrNotImplemented +} + +func (s *tweetSrvA) ReactionByTweetId(userId int64, tweetId int64) (*cs.ReactionItem, error) { + // TODO + return nil, debug.ErrNotImplemented +} + +func (s *tweetSrvA) UserReactions(userId int64, limit int, offset int) (cs.ReactionList, error) { + // TODO + return nil, debug.ErrNotImplemented +} + +func (s *tweetSrvA) FavoriteByTweetId(userId int64, tweetId int64) (*cs.FavoriteItem, error) { + // TODO + return nil, debug.ErrNotImplemented +} + +func (s *tweetSrvA) UserFavorites(userId int64, limit int, offset int) (cs.FavoriteList, error) { + // TODO + return nil, debug.ErrNotImplemented +} + +func (s *tweetSrvA) AttachmentByTweetId(userId int64, tweetId int64) (*cs.AttachmentBill, error) { + // TODO + return nil, debug.ErrNotImplemented +} + +func (s *tweetManageSrvA) CreateAttachment(obj *cs.Attachment) (int64, error) { + // TODO + return 0, debug.ErrNotImplemented +} + +func (s *tweetManageSrvA) CreateTweet(userId int64, req *cs.NewTweetReq) (*cs.TweetItem, error) { + // TODO + return nil, debug.ErrNotImplemented +} + +func (s *tweetManageSrvA) DeleteTweet(userId int64, tweetId int64) ([]string, error) { + // TODO + return nil, debug.ErrNotImplemented +} + +func (s *tweetManageSrvA) LockTweet(userId int64, tweetId int64) error { + // TODO + return debug.ErrNotImplemented +} + +func (s *tweetManageSrvA) StickTweet(userId int64, tweetId int64) error { + // TODO + return debug.ErrNotImplemented +} + +func (s *tweetManageSrvA) VisibleTweet(userId int64, visibility cs.TweetVisibleType) error { + // TODO + return debug.ErrNotImplemented +} + +func (s *tweetManageSrvA) CreateReaction(userId int64, tweetId int64) error { + // TODO + return debug.ErrNotImplemented +} + +func (s *tweetManageSrvA) DeleteReaction(userId int64, reactionId int64) error { + // TODO + return debug.ErrNotImplemented +} + +func (s *tweetManageSrvA) CreateFavorite(userId int64, tweetId int64) error { + // TODO + return debug.ErrNotImplemented +} + +func (s *tweetManageSrvA) DeleteFavorite(userId int64, favoriteId int64) error { + // TODO + return debug.ErrNotImplemented +} + +func (s *tweetHelpSrvA) RevampTweets(tweets cs.TweetList) (cs.TweetList, error) { + // TODO + return nil, debug.ErrNotImplemented +} + +func (s *tweetHelpSrvA) MergeTweets(tweets cs.TweetInfo) (cs.TweetList, error) { + // TODO + return nil, debug.ErrNotImplemented +} + +func newTweetServantA(db *sqlx.DB) core.TweetServantA { + return &tweetSrvA{ + sqlxSrv: newSqlxSrv(db), + q: acBuildFn(db, ac.BuildTweetA), + } +} + +func newTweetManageServantA(db *sqlx.DB, cacheIndex core.CacheIndexService) core.TweetManageServantA { + return &tweetManageSrvA{ + sqlxSrv: newSqlxSrv(db), + cis: cacheIndex, + q: acBuildFn(db, ac.BuildTweetManageA), + } +} + +func newTweetHelpServantA(db *sqlx.DB) core.TweetHelpServantA { + return &tweetHelpSrvA{ + sqlxSrv: newSqlxSrv(db), + q: acBuildFn(db, ac.BuildTweetHelpA), + } +} diff --git a/internal/dao/sakila/user.go b/internal/dao/sakila/user.go index d1479eb0..18f469b0 100644 --- a/internal/dao/sakila/user.go +++ b/internal/dao/sakila/user.go @@ -11,7 +11,7 @@ import ( "github.com/bitbus/sqlx" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" - "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" + "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc" ) var ( @@ -73,6 +73,6 @@ func (s *userManageSrv) UpdateUser(r *ms.User) error { func newUserManageService(db *sqlx.DB) core.UserManageService { return &userManageSrv{ sqlxSrv: newSqlxSrv(db), - q: mustBuild(db, cc.BuildUserManage), + q: ccBuild(db, cc.BuildUserManage), } } diff --git a/internal/dao/sakila/wallet.go b/internal/dao/sakila/wallet.go index 9ec9b587..ab7f09a2 100644 --- a/internal/dao/sakila/wallet.go +++ b/internal/dao/sakila/wallet.go @@ -12,7 +12,7 @@ import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" - "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" + "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc" ) var ( @@ -126,6 +126,6 @@ func (s *walletSrv) HandlePostAttachmentBought(post *ms.Post, user *ms.User) err func newWalletService(db *sqlx.DB) core.WalletService { return &walletSrv{ sqlxSrv: newSqlxSrv(db), - q: mustBuild(db, cc.BuildWallet), + q: ccBuild(db, cc.BuildWallet), } } diff --git a/internal/dao/sakila/yesql/gen.go b/internal/dao/sakila/yesql/gen.go index 5c413056..4bda5dc1 100644 --- a/internal/dao/sakila/yesql/gen.go +++ b/internal/dao/sakila/yesql/gen.go @@ -21,7 +21,13 @@ func main() { query.Query = strings.TrimRight(query.Query, ";") return query, nil }) - if err := yesql.Generate("yesql.sql", "cc", "cc", yesql.SqlxPkgName("github.com/bitbus/sqlx")); err != nil { + opt := yesql.SqlxPkgName("github.com/bitbus/sqlx") + sqlInfos := []yesql.SqlInfo{ + yesql.NewSqlInfo("yesql.sql", "../auto", "yesql"), + yesql.NewSqlInfo("yesql_ac.sql", "../auto/ac", "ac"), + yesql.NewSqlInfo("yesql_cc.sql", "../auto/cc", "cc"), + } + if err := yesql.GenerateFrom(sqlInfos, opt); err != nil { log.Fatalf("generate code occurs error: %s", err) } log.Println("[Yesql] generate code finish") diff --git a/internal/dao/sakila/yesql/yesql.sql b/internal/dao/sakila/yesql/yesql.sql index f2d2c5d6..483f76b8 100644 --- a/internal/dao/sakila/yesql/yesql.sql +++ b/internal/dao/sakila/yesql/yesql.sql @@ -1,5 +1,10 @@ -------------------------------------------------------------------------------- --- global sql dml +-- file yesql.sql +-- this sql file just define global sql dml +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- global sql dml -------------------------------------------------------------------------------- -- name: tags_from_names @@ -11,1268 +16,3 @@ SELECT * FROM @tag WHERE tag IN (?) AND is_del=0; -- prepare: stmt UPDATE @tag SET quote_num=?, modified_on=? WHERE id=? AND is_del=0; - --------------------------------------------------------------------------------- --- authorization_manage sql dml --------------------------------------------------------------------------------- - --- name: be_friend_ids@authorization_manage --- prepare: stmt -SELECT user_id FROM @contact WHERE friend_id=? AND status=2 AND is_del=0; - --- name: my_friend_set@authorization_manage --- prepare: stmt -SELECT friend_id FROM @contact WHERE user_id=? AND status=2 AND is_del=0; - --- name: is_friend@authorization_manage --- prepare: stmt -SELECT status FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0; - --------------------------------------------------------------------------------- --- comment sql dml --------------------------------------------------------------------------------- - --- name: get_comments@comment --- prepare: raw -SELECT * FROM @comment WHERE post_id=? AND is_del=0 ORDER BY %order% LIMIT ? OFFSET ?; - --- name: get_comment_by_id@comment --- prepare: stmt -SELECT * FROM @comment WHERE id=? AND is_del=0; - --- name: get_comment_count@comment --- prepare: named_stmt -SELECT count(*) FROM @comment WHERE post_id=:post_id AND is_del=0; - --- name: get_comment_reply_by_id@comment --- prepare: stmt -SELECT * FROM @comment_reply WHERE id=? AND is_del=0; - --- name: get_comment_contents_by_ids@comment --- prepare: raw --- clause: in -SELECT * FROM @comment_content WHERE comment_id IN (?); - --- name: get_commment_replies_by_ids@comment --- prepare: raw --- clause: in -SELECT * FROM @comment_reply WHERE comment_id IN (?) ORDER BY id ASC; - --- name: get_users_by_ids@comment --- prepare: raw --- clause: in -SELECT id, nickname, username, status, avatar, is_admin FROM @user WHERE id IN (?); - --- name: get_comment_thumbs@comment --- prepare: stmt -SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=?; - --------------------------------------------------------------------------------- --- comment_manage sql dml --------------------------------------------------------------------------------- - --- name: delete_comment@comment_manage --- prepare: stmt -UPDATE @comment SET deleted_on=?, is_del=1 WHERE id=? AND is_del=0; - --- name: delete_comment_thumbs@comment_manage --- prepare: stmt -UPDATE @tweet_comment_thumbs -SET deleted_on=?, is_del=1 -WHERE user_id=? AND tweet_id=? AND comment_id=? AND is_del=0; - --- name: create_comment@comment_manage --- prepare: stmt -INSERT INTO @comment (post_id, user_id, ip, ip_loc, created_on) -VALUES (?, ?, ?, ?, ?); - --- name: create_comment_reply@comment_manage --- prepare: stmt -INSERT INTO @comment_reply (comment_id, user_id, content, at_user_id, ip, ip_loc, created_on) -VALUES (?, ?, ?, ?, ?, ?, ?); - --- name: delete_comment_reply@comment_manage --- prepare: stmt -UPDATE @comment_reply SET deleted_on=?, is_del=1 WHERE id=? AND is_del=0; - --- name: delete_reply_thumbs@comment_manage --- prepare: stmt -UPDATE @tweet_comment_thumbs -SET deleted_on=?, is_del=1 -WHERE user_id=? AND comment_id=? AND reply_id=? AND is_del=0; - --- name: create_comment_content@comment_manage --- prepare: stmt -INSERT INTO @comment_content (comment_id, user_id, content, type, sort, created_on) -VALUES (?, ?, ?, ?, ?, ?); - --- name: update_thumbs_updown_comment@comment_manage --- prepare: named_stmt -UPDATE @tweet_comment_thumbs -SET is_thumbs_up=:is_thumbs_up, is_thumbs_down=:is_thumbs_down, modified_on=:modified_on -WHERE id=:id AND is_del=0; - --- name: create_thumbs_updown_comment@comment_manage --- prepare: named_stmt -INSERT INTO @tweet_comment_thumbs (user_id, tweet_id, comment_id, reply_id, is_thumbs_up, is_thumbs_down, comment_type, created_on) -VALUES (:user_id, :tweet_id, :comment_id, :reply_id, :is_thumbs_up, :is_thumbs_down, :comment_type, :created_on); - --- name: update_comment_thumbs_count@comment_manage --- prepare: stmt -UPDATE @comment -SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? -WHERE id=? AND is_del=0; - --- name: get_tweet_comment_thumb@comment_manage --- prepare: stmt -SELECT * -FROM @tweet_comment_thumbs -WHERE user_id=? AND tweet_id=? AND comment_id=? AND comment_type=0 AND is_del=0; - --- name: get_comment_reply_thumb@comment_manage --- prepare: stmt -SELECT * -FROM @tweet_comment_thumbs -WHERE user_id=? AND tweet_id=? AND comment_id=? AND reply_id=? AND comment_type=1 AND is_del=0; - --- name: update_reply_thumbs_count@comment_manage --- prepare: stmt -UPDATE @comment_reply -SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? -WHERE id=? AND is_del=0; - --------------------------------------------------------------------------------- --- following_manager sql dml --------------------------------------------------------------------------------- - --- name: create_following@following_manager --- prepare: stmt -INSERT INTO @following (user_id, follow_id, created_on) VALUES (?, ?, ?); - --- name: exist_following@following_manager --- prepare: stmt -SELECT 1 FROM @following WHERE user_id=? AND follow_id=? AND is_del=0; - --- name: delete_following@following_manager --- prepare: stmt -UPDATE @following -SET is_del=0, deleted_on=? -WHERE user_id=? AND follow_id=? AND is_del=0; - --- name: list_follows@following_manager --- prepare: stmt -SELECT u.user_id user_id, - u.username username, - u.nickname nickname, - u.avatar avatar, - u.created_on created_on -FROM @following f JOIN @user u ON f.follow_id=u.id -WHERE f.user_id=? AND f.is_del=0 -ORDER BY u.nickname ASC -LIMIT ? OFFSET ?; - --- name: count_follows@following_manager --- prepare: stmt -SELECT count(*) FROM @following WHERE user_id=? AND is_del=0; - --- name: list_followings@following_manager --- prepare: stmt -SELECT u.user_id user_id, - u.username username, - u.nickname nickname, - u.avatar avatar, - u.created_on created_on -FROM @following f JOIN @user u ON f.user_id=u.id -WHERE f.follow_id=? AND f.is_del=0 -ORDER BY u.nickname ASC -LIMIT ? OFFSET ?; - --- name: count_followings@following_manager --- prepare: stmt -SELECT count(*) FROM @following WHERE follow_id=? AND is_del=0; - --------------------------------------------------------------------------------- --- contact_manager sql dml --------------------------------------------------------------------------------- - --- name: create_contact@contact_manager --- prepare: stmt -INSERT INTO @contact (user_id, friend_id, status, created_on) VALUES (?, ?, ?, ?); - --- name: fresh_contact_status@contact_manager --- prepare: stmt -UPDATE @contact SET status=?, modified_on=?, is_del=0 WHERE id=?; - --- name: create_message@contact_manager --- prepare: named_stmt -INSERT INTO @message (sender_user_id, receiver_user_id, type, brief, content, reply_id, created_on) -VALUES (:sender_user_id, :receiver_user_id, :type, :brief, :content, :reply_id, :created_on); - --- name: add_friend_msgs_update@contact_manager --- prepare: stmt -UPDATE @message -SET reply_id=?, modified_on=? -WHERE ((sender_user_id = ? AND receiver_user_id = ?) OR (sender_user_id = ? AND receiver_user_id = ?)) AND type = ? AND reply_id = ?; - --- name: reject_friend_msgs_update@contact_manager --- prepare: stmt -UPDATE @message -SET reply_id=?, modified_on=? -WHERE sender_user_id = ? AND receiver_user_id = ? AND type = ? AND reply_id = ?; - --- name: del_friend@contact_manager --- prepare: stmt -UPDATE @contact SET status=4, is_del=1, deleted_on=? WHERE id=?; - --- name: list_friend@contact_manager --- prepare: stmt -SELECT c.friend_id user_id, u.username username, u.nickname nickname, u.avatar avatar, u.phone phone -FROM @contact c JOIN @user u -ON c.friend_id=u.id -WHERE user_id=? AND status=2 AND is_del=0 -ORDER BY u.nickname ASC -LIMIT ? OFFSET ?; - --- name: total_friends_by_id@contact_manager --- prepare: stmt -SELECT count(*) -FROM @contact -WHERE user_id=? AND status=2 AND is_del=0; - --- name: get_contacts@contact_manager --- prepare: stmt -SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del -FROM @contact -WHERE (user_id=? AND friend_id=?) OR (user_id=? AND friend_id=?); - --- name: get_user_friend@contact_manager --- prepare: stmt -SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del -FROM @contact -WHERE user_id=? AND friend_id=? AND is_del=0; - --- name: get_contact@contact_manager --- prepare: stmt -SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del -FROM @contact -WHERE user_id=? AND friend_id=?; - --- name: is_friend@contact_manager --- prepare: stmt -SELECT true FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0 AND status=2; - --------------------------------------------------------------------------------- --- message sql dml --------------------------------------------------------------------------------- - --- name: create_message@message --- prepare: named_stmt -INSERT INTO @message (sender_user_id, receiver_user_id, type, brief, content, post_id, comment_id, reply_id, created_on) -VALUES (:sender_user_id, :receiver_user_id, :type, :brief, :content, :post_id, :comment_id, :reply_id, :created_on); - --- name: get_unread_count@message --- prepare: stmt -SELECT count(*) FROM @message WHERE receiver_user_id=? AND is_read=0 AND is_del=0; - --- name: get_message_by_id@message --- prepare: stmt -SELECT * FROM @message WHERE id=? AND is_del=0; - --- name: read_message@message --- prepare: stmt -UPDATE @message SET is_read=1, modified_on=? WHERE id=?; - --- name: get_messages@message --- prepare: named_stmt -SELECT * -FROM @message -WHERE receiver_user_id=:recerver_user_id AND is_del=0 -ORDER BY id DESC -LIMIT :limit OFFSET :offset - --- name: get_message_count@message --- prepare: named_stmt -SELECT count(*) FROM @message WHERE receiver_user_id=:recerver_user_id AND is_del=0; - --------------------------------------------------------------------------------- --- security sql dml --------------------------------------------------------------------------------- - --- name: get_latest_phone_captcha@security --- prepare: stmt -SELECT * FROM @captcha WHERE phone=? AND is_del=0; - --- name: use_phone_captcha@security --- prepare: stmt -UPDATE @captcha SET use_times=use_times+1, modified_on=? WHERE id=? AND is_del=0; - --- name: create_phone_captcha@security --- prepare: named_stmt -INSERT INTO @captcha (phone, captcha, expired_on, created_on) -VALUES (:phone, :captcha, :expired_on, :created_on); - --------------------------------------------------------------------------------- --- ship_index sql dml --------------------------------------------------------------------------------- - --- name: index_by_admin@ship_index --- prepare: stmt -SELECT * -FROM @p_post -WHERE is_del=0 -ORDER BY is_top DESC, latest_replied_on DESC -LIMIT ? OFFSET ?; - --- name: index_count_by_admin@ship_index --- prepare: stmt -SELECT count(*) -FROM @p_post -WHERE is_del=0; - --- name: index_by_guest@ship_index --- prepare: stmt -SELECT * -FROM @p_post -WHERE visibility=0 AND is_del=0 -ORDER BY is_top DESC, latest_replied_on DESC -LIMIT ? OFFSET ?; - --- name: index_count_by_guest@ship_index --- prepare: stmt -SELECT count(*) -FROM @p_post -WHERE visibility=0 AND is_del=0; - --- name: index_by_self@ship_index --- prepare: raw --- clause: in -SELECT * -FROM @p_post -WHERE is_del=0 AND - (visibility=0 OR - (visibility=1 AND user_id=?) OR - (visibility=2 AND user_id IN ?)) -ORDER BY is_top DESC, latest_replied_on DESC -LIMIT ? OFFSET ?; - --- name: index_count_by_self@ship_index --- prepare: raw --- clause: in -SELECT count(*) -FROM @p_post -WHERE is_del=0 AND - (visibility=0 OR - (visibility=1 AND user_id=?) OR - (visibility=2 AND user_id IN ?)); - --------------------------------------------------------------------------------- --- simple_index sql dml --------------------------------------------------------------------------------- - --- name: index@simple_index --- prepare: stmt -SELECT * -FROM @p_post -WHERE visibility=0 -ORDER BY is_top DESC, latest_replied_on DESC -LIMIT ? OFFSET ?; - --- name: index_count@simple_index --- prepare: stmt -SELECT count(*) -FROM @p_post -WHERE visibility=0; - --------------------------------------------------------------------------------- --- ship_index_a sql dml --------------------------------------------------------------------------------- - --- name: user_info@ship_index_a --- prepare: raw -SELECT * FROM @user WHERE username=? - --------------------------------------------------------------------------------- --- simple_index_a sql dml --------------------------------------------------------------------------------- - --- name: user_info@simple_index_a --- prepare: raw -SELECT * FROM @user WHERE username=? - --------------------------------------------------------------------------------- --- tweet sql dml --------------------------------------------------------------------------------- - --- name: get_post_by_id@tweet --- prepare: stmt -SELECT * FROM @post WHERE id=? AND is_del=0; - --- name: get_user_posts@tweet --- prepare: raw --- clause: in -SELECT * FROM @post -WHERE user_id=? AND visibility IN (?) -ORDER BY latest_replies_on DESC -LIMIT ? OFFSET ?; - --- name: get_any_posts@tweet --- prepare: raw --- clause: in -SELECT * FROM @post WHERE visibility IN (?) AND is_del=0 LIMIT ? OFFSET ?; - --- name: get_user_post_count@tweet --- prepare: raw --- clause: in -SELECT count(*) FROM @post WHERE user_id=? AND visibility IN (?); - --- name: get_any_post_count@tweet --- prepare: raw --- clause: in -SELECT count(*) FROM @post WHERE visibility IN (?); - --- name: get_user_post_star@tweet --- prepare: stmt -SELECT - s.*, - P.ID "post.id", - P.user_id "post.user_id", - P.comment_count "post.comment_count", - P.collection_count "post.collection_count", - P.upvote_count "post.upvote_count", - P.share_count "post.share_count", - P.visibility "post.visibility", - P.is_top "post.is_top", - P.is_essence "post.is_essence", - P.is_lock "post.is_lock", - P.latest_replied_on "post.latest_replied_on", - P.tags "post.tags", - P.attachment_price "post.attachment_price", - P.ip "post.ip", - P.ip_loc "post.ip_loc", - P.is_del "post.is_del", - P.created_on "post.created_on", - P.modified_on "post.modified_on", - P.deleted_on "post.deleted_on" -FROM - @post_star s - JOIN @post P ON s.post_id = P.ID -WHERE - s.post_id = ? - AND s.user_id = ? - AND s.is_del = 0 - AND ( visibility <> 1 OR ( visibility = 1 AND P.user_id = ? ) ) -ORDER BY - P.ID DESC; - --- name: get_user_post_stars@tweet --- prepare: stmt -SELECT - s.*, - P.ID "post.id", - P.user_id "post.user_id", - P.comment_count "post.comment_count", - P.collection_count "post.collection_count", - P.upvote_count "post.upvote_count", - P.share_count "post.share_count", - P.visibility "post.visibility", - P.is_top "post.is_top", - P.is_essence "post.is_essence", - P.is_lock "post.is_lock", - P.latest_replied_on "post.latest_replied_on", - P.tags "post.tags", - P.attachment_price "post.attachment_price", - P.ip "post.ip", - P.ip_loc "post.ip_loc", - P.is_del "post.is_del", - P.created_on "post.created_on", - P.modified_on "post.modified_on", - P.deleted_on "post.deleted_on" -FROM - @post_star s - JOIN @post P ON s.post_id = P.ID -WHERE - s.user_id = ? - AND s.is_del = 0 - AND ( visibility <> 1 OR ( visibility = 1 AND P.user_id = ? ) ) -ORDER BY - s.ID DESC, - P.ID DESC -LIMIT ? OFFSET ?; - --- name: get_user_post_star_count@tweet --- prepare: stmt -SELECT - count(*) -FROM - @post_star s - JOIN @post P ON s.post_id = P.ID -WHERE - s.user_id = ? - AND s.is_del = 0 - AND ( visibility <> 1 OR ( visibility = 1 AND P.user_id = ? ) ); - --- name: get_user_post_collection@tweet --- prepare: stmt -SELECT - s.*, - P.ID "post.id", - P.user_id "post.user_id", - P.comment_count "post.comment_count", - P.collection_count "post.collection_count", - P.upvote_count "post.upvote_count", - P.share_count "post.share_count", - P.visibility "post.visibility", - P.is_top "post.is_top", - P.is_essence "post.is_essence", - P.is_lock "post.is_lock", - P.latest_replied_on "post.latest_replied_on", - P.tags "post.tags", - P.attachment_price "post.attachment_price", - P.ip "post.ip", - P.ip_loc "post.ip_loc", - P.is_del "post.is_del", - P.created_on "post.created_on", - P.modified_on "post.modified_on", - P.deleted_on "post.deleted_on" -FROM - @post_collection s - JOIN @post P ON s.post_id = P.ID -WHERE - s.post_id = ? - AND s.user_id = ? - AND s.is_del = 0 - AND ( visibility <> 1 OR ( visibility = 1 AND P.user_id = ? ) ) -ORDER BY - P.ID DESC; - --- name: get_user_post_collections@tweet --- prepare: stmt -SELECT - s.*, - P.ID "post.id", - P.user_id "post.user_id", - P.comment_count "post.comment_count", - P.collection_count "post.collection_count", - P.upvote_count "post.upvote_count", - P.share_count "post.share_count", - P.visibility "post.visibility", - P.is_top "post.is_top", - P.is_essence "post.is_essence", - P.is_lock "post.is_lock", - P.latest_replied_on "post.latest_replied_on", - P.tags "post.tags", - P.attachment_price "post.attachment_price", - P.ip "post.ip", - P.ip_loc "post.ip_loc", - P.is_del "post.is_del", - P.created_on "post.created_on", - P.modified_on "post.modified_on", - P.deleted_on "post.deleted_on" -FROM - @post_collection s - JOIN @post P ON s.post_id = P.ID -WHERE - s.user_id = ? - AND s.is_del = 0 - AND ( visibility <> 1 OR ( visibility = 1 AND P.user_id = ? ) ) -ORDER BY - s.ID DESC, - P.ID DESC -LIMIT ? OFFSET ?; - --- name: get_user_post_collection_count@tweet --- prepare: stmt -SELECT - count(*) -FROM - @post_collection s - JOIN @post P ON s.post_id = P.ID -WHERE - s.user_id = ? - AND s.is_del = 0 - AND ( visibility <> 1 OR ( visibility = 1 AND P.user_id = ? ) ); - --- name: get_post_attachment_bill@tweet --- prepare: stmt -SELECT * FROM @post_attachment_bill WHERE post_id=? AND user_id=? AND is_del=0; - --- name: get_post_contents_by_ids@tweet --- prepare: raw --- clause: in -SELECT * -FROM @post_content -WHERE post_id IN (?) AND is_del=0; - --- name: get_post_content_by_id@tweet --- prepare: stmt -SELECT * FROM @post_content WHERE id=? AND is_del=0; - --- name: user_media_tweets_by_guest@tweet --- prepare: stmt -SELECT * -FROM @post_by_media -WHERE is_del=0 AND user_id=? AND visibility=0 -ORDER BY latest_replied_on DESC -LIMIT ? OFFSET ?; - --- name: user_media_tweets_count_by_guest@tweet --- prepare: stmt -SELECT count(*) -FROM @post_by_media -WHERE is_del=0 AND user_id=? AND visibility=0; - --- name: user_media_tweets_by_friend@tweet --- prepare: stmt -SELECT * -FROM @post_by_media -WHERE is_del=0 AND user_id=? AND (visibility=0 OR visibility=2) -ORDER BY latest_replied_on DESC -LIMIT ? OFFSET ?; - --- name: user_media_tweets_count_by_friend@tweet --- prepare: stmt -SELECT count(*) -FROM @post_by_media -WHERE is_del=0 AND user_id=? AND (visibility=0 OR visibility=2); - --- name: user_media_tweets_by_self@tweet --- prepare: stmt -SELECT * -FROM @post_by_media -WHERE is_del=0 AND user_id=? -ORDER BY latest_replied_on DESC -LIMIT ? OFFSET ?; - --- name: user_media_tweets_count_by_self@tweet --- prepare: stmt -SELECT count(*) -FROM @post_by_media -WHERE is_del=0 AND user_id=?; - --- name: user_comment_tweets_by_guest@tweet --- prepare: stmt -SELECT * -FROM @post_by_comment -WHERE is_del=0 AND comment_user_id=? AND visibility=0 -ORDER BY latest_replied_on DESC -LIMIT ? OFFSET ?; - --- name: user_comment_tweets_count_by_guest@tweet --- prepare: stmt -SELECT count(*) -FROM @post_by_comment -WHERE is_del=0 AND comment_user_id=? AND visibility=0; - --- name: user_comment_tweets_by_friend@tweet --- prepare: stmt -SELECT * -FROM @post_by_comment -WHERE is_del=0 AND comment_user_id=? AND (visibility=0 OR visibility=2) -ORDER BY latest_replied_on DESC -LIMIT ? OFFSET ?; - --- name: user_comment_tweets_count_by_friend@tweet --- prepare: stmt -SELECT count(*) -FROM @post_by_comment -WHERE is_del=0 AND comment_user_id=? AND (visibility=0 OR visibility=2); - --- name: user_comment_tweets_by_self@tweet --- prepare: stmt -SELECT * -FROM @post_by_comment -WHERE is_del=0 AND comment_user_id=? -ORDER BY latest_replied_on DESC -LIMIT ? OFFSET ?; - --- name: user_comment_tweets_count_by_self@tweet --- prepare: stmt -SELECT count(*) -FROM @post_by_comment -WHERE is_del=0 AND comment_user_id=?; - --- name: user_star_tweets_by_guest@tweet --- prepare: stmt -SELECT - star.*, - post.ID "post.id", - post.created_on "post.created_on", - post.modified_on "post.modified_on", - post.deleted_on "post.deleted_on", - post.is_del "post.is_del", - post.user_id "post.user_id", - post.comment_count "post.comment_count", - post.collection_count "post.collection_count", - post.share_count "post.share_count", - post.upvote_count "post.upvote_count", - post.visibility "post.visibility", - post.is_top "post.is_top", - post.is_essence "post.is_essence", - post.is_lock "post.is_lock", - post.latest_replied_on "post.latest_replied_on", - post.tags "post.tags", - post.attachment_price "post.attachment_price", - post.ip "post.ip", - post.ip_loc "post.ip_loc" -FROM - @post_star star - JOIN @post post ON star.post_id = post.ID -WHERE - star.is_del = 0 - AND star.user_id =? - AND post.visibility = 0 -ORDER BY post.latest_replied_on DESC -LIMIT ? OFFSET ?; - --- name: user_star_tweets_count_by_guest@tweet --- prepare: stmt -SELECT count(*) -FROM - @post_star star - JOIN @post post ON star.post_id = post.ID -WHERE star.is_del=0 AND star.user_id=? AND post.visibility=0; - --- name: user_star_tweets_by_friend@tweet --- prepare: stmt -SELECT - star.*, - post.ID "post.id", - post.created_on "post.created_on", - post.modified_on "post.modified_on", - post.deleted_on "post.deleted_on", - post.is_del "post.is_del", - post.user_id "post.user_id", - post.comment_count "post.comment_count", - post.collection_count "post.collection_count", - post.share_count "post.share_count", - post.upvote_count "post.upvote_count", - post.visibility "post.visibility", - post.is_top "post.is_top", - post.is_essence "post.is_essence", - post.is_lock "post.is_lock", - post.latest_replied_on "post.latest_replied_on", - post.tags "post.tags", - post.attachment_price "post.attachment_price", - post.ip "post.ip", - post.ip_loc "post.ip_loc" -FROM - @post_star star - JOIN @post post ON star.post_id = post.ID -WHERE star.is_del=0 AND star.user_id=? AND (post.visibility=0 OR post.visibility=2) -ORDER BY post.latest_replied_on DESC -LIMIT ? OFFSET ?; - --- name: user_star_tweets_count_by_friend@tweet --- prepare: stmt -SELECT count(*) -FROM - @post_star star - JOIN @post post ON star.post_id = post.ID -WHERE star.is_del=0 AND star.user_id=? AND (post.visibility=0 OR post.visibility=2); - --- name: user_star_tweets_by_self@tweet --- prepare: stmt -SELECT - star.*, - post.ID "post.id", - post.created_on "post.created_on", - post.modified_on "post.modified_on", - post.deleted_on "post.deleted_on", - post.is_del "post.is_del", - post.user_id "post.user_id", - post.comment_count "post.comment_count", - post.collection_count "post.collection_count", - post.share_count "post.share_count", - post.upvote_count "post.upvote_count", - post.visibility "post.visibility", - post.is_top "post.is_top", - post.is_essence "post.is_essence", - post.is_lock "post.is_lock", - post.latest_replied_on "post.latest_replied_on", - post.tags "post.tags", - post.attachment_price "post.attachment_price", - post.ip "post.ip", - post.ip_loc "post.ip_loc" -FROM - @post_star star - JOIN @post post ON star.post_id = post.ID -WHERE star.is_del=0 AND star.user_id=? AND (post.visibility<>0 (post.visibility=0 AND post.user_id=?)) -ORDER BY post.latest_replied_on DESC; -LIMIT ? OFFSET ?; - --- name: user_star_tweets_count_by_self@tweet --- prepare: stmt -SELECT count(*) -FROM - @post_star star - JOIN @post post ON star.post_id = post.ID -WHERE star.is_del=0 AND star.user_id=? AND (post.visibility<>0 (post.visibility=0 AND post.user_id=?)); - --- name: user_star_tweets_by_admin@tweet --- prepare: stmt -SELECT - star.*, - post.ID "post.id", - post.created_on "post.created_on", - post.modified_on "post.modified_on", - post.deleted_on "post.deleted_on", - post.is_del "post.is_del", - post.user_id "post.user_id", - post.comment_count "post.comment_count", - post.collection_count "post.collection_count", - post.share_count "post.share_count", - post.upvote_count "post.upvote_count", - post.visibility "post.visibility", - post.is_top "post.is_top", - post.is_essence "post.is_essence", - post.is_lock "post.is_lock", - post.latest_replied_on "post.latest_replied_on", - post.tags "post.tags", - post.attachment_price "post.attachment_price", - post.ip "post.ip", - post.ip_loc "post.ip_loc" -FROM - @post_star star - JOIN @post post ON star.post_id = post.ID -WHERE star.is_del=0 AND star.user_id=? -ORDER BY post.latest_replied_on DESC; -LIMIT ? OFFSET ?; - --- name: user_star_tweets_count_by_admin@tweet --- prepare: stmt -SELECT count(*) -FROM - @post_star star - JOIN @post post ON star.post_id = post.ID -WHERE star.is_del=0 AND star.user_id=?; - --------------------------------------------------------------------------------- --- tweet_manage sql dml --------------------------------------------------------------------------------- - --- name: add_post@tweet_manage --- prepare: named_stmt -INSERT INTO @post (user_id, tags, ip, ip_loc, attachment_price, visibility, latest_replies_on, created_on) -VALUES (:user_id, :tags, :ip, :ip_loc, :attachment_price, :visibility, :latest_replies_on, :created_on); - --- name: media_content_by_post_id@tweet_manage --- prepare stmt -SELECT content FROM post_content WHERE post_id=? AND is_del=0 AND type IN (3, 4, 5, 7, 8); - --- name: del_post_by_id@tweet_manage --- prepare: stmt -UPDATE @post SET is_del=1, deleted_on=? WHERE id=? AND is_del=0; - --- name: lock_post@tweet_manage --- prepare: stmt -UPDATE @post SET is_lock=1-is_lock, modified_on=? WHERE id=? AND is_del=0; - --- name: stick_post@tweet_manage --- prepare: stmt -UPDATE @post SET is_top=1-is_top, modified_on=? WHERE id=? AND is_del=0; - --- name: visible_post@tweet_manage --- prepare: stmt -UPDATE @post SET visibility=?, is_top=?, modified_on=? WHERE id=? AND is_del=0; - --- name: highlight_post@tweet_manage --- prepare: stmt -UPDATE @post SET is_essence=1-is_essence WHERE id=? AND is_del=0; - --- name: post_highlight_status@tweet_manage --- prepare: stmt -SELECT user_id, is_essence FROM @post WHERE id=? AND is_del=0; - --- name: update_post@tweet_manage --- prepare: named_stmt -UPDATE @post SET comment_count=:comment_count, - upvote_count=:upvote_count, - collection_count=:collection_count, - latest_replies_on=:latest_replies_on, - modified_on=:modified_on -WHERE id=:id AND is_del=0; - --- name: add_post_star@tweet_manage --- prepare: stmt -INSERT INTO @post_star (post_id, user_id, created_on) -VALUES (?, ?, ?); - --- name: del_post_star@tweet_manage --- prepare: stmt -UPDATE @post_star SET is_del=1, deleted_on=? WHERE id=? AND is_del=0; - --- name: add_post_collection@tweet_manage --- prepare: stmt -INSERT INTO @post_collection (post_id, user_id, created_on) -VALUES (?, ?, ?); - --- name: del_post_collection@tweet_manage --- prepare: stmt -UPDATE @post_collection SET is_del=1, deleted_on=? WHERE id=? AND is_del=0; - --- name: add_post_content@tweet_manage --- prepare: named_stmt -INSERT INTO @post_content (post_id, user_id, content, type, sort, created_on) -VALUES (:post_id, :user_id, :content, :type, :sort, :created_on); - --- name: add_attachment@tweet_manage --- prepare: stmt -INSERT INTO @attachment (user_id, file_size, img_width, img_height, type, content, created_on) -VALUES (?, ?, ?, ?, ?, ?, ?); - --- name: comment_ids_by_post_id@tweet_manage --- prepare: stmt -SELECT id FROM @comment WHERE post_id=? AND is_del=0; - --- name: comment_media_from_comment_ids@tweet_manage --- prepare: raw --- clause: in -SELECT content FROM @comment_content WHERE comment_id IN (?) AND type=3 AND is_del=0; - --- name: del_comment_by_post_id@tweet_manage --- prepare: stmt -UPDATE @comment SET deleted_on=?, is_del=1 WHERE post_id=? AND is_del=0; - --- name: del_comment_content_by_comment_ids@tweet_manage --- prepare: raw --- clause: in -UPDATE @comment_content SET deleted_on=?, is_del=1 WHERE comment_id IN (?) AND is_del=0; - --- name: del_reply_by_comment_ids@tweet_manage --- prepare: raw --- clause: in -UPDATE @comment_reply SET deleted_on=?, is_del=1 WHERE comment_id IN (?) AND is_del=0; - --------------------------------------------------------------------------------- --- tweet_help sql dml --------------------------------------------------------------------------------- - --- name: get_post_content_by_ids@tweet_help --- prepare: raw --- clause: in -SELECT id, post_id, content, type, sort -FROM @post_content -WHERE post_id IN (?) AND is_del=0; - --- name: get_users_by_ids@tweet_help --- prepare: raw --- clause: in -SELECT id, username, nickname, status, avatar, is_admin -FROM @user -WHERE id IN (?) AND is_del=0; - --------------------------------------------------------------------------------- --- tweet_a sql dml --------------------------------------------------------------------------------- - --- name: user_info@tweet_a --- prepare: raw -SELECT * FROM @user WHERE username=? - --- name: tweet_info_by_id@tweet_a --- prepare: raw -SELECT * FROM @user WHERE username=? - --- name: tweet_item_by_id@tweet_a --- prepare: raw -SELECT * FROM @user WHERE username=? - --- name: user_tweets_by_admin@tweet_a --- prepare: raw -SELECT * FROM @user WHERE username=? - --- name: user_tweets_by_self@tweet_a --- prepare: raw -SELECT * FROM @user WHERE username=? - --- name: user_tweets_by_friend@tweet_a --- prepare: raw -SELECT * FROM @user WHERE username=? - --- name: user_tweets_by_guest@tweet_a --- prepare: raw -SELECT * FROM @user WHERE username=? - --- name: reaction_by_tweet_id@tweet_a --- prepare: raw -SELECT * FROM @user WHERE username=? - --- name: user_reactions@tweet_a --- prepare: raw -SELECT * FROM @user WHERE username=? - --- name: favorite_by_tweet_id@tweet_a --- prepare: raw -SELECT * FROM @user WHERE username=? - --- name: user_favorites@tweet_a --- prepare: raw -SELECT * FROM @user WHERE username=? - --- name: attachment_by_tweet_id@tweet_a --- prepare: raw -SELECT * FROM @user WHERE username=? - --------------------------------------------------------------------------------- --- tweet_manage_a sql dml --------------------------------------------------------------------------------- - --- name: user_info@tweet_manage_a --- prepare: raw -SELECT * FROM @user WHERE username=? - --------------------------------------------------------------------------------- --- tweet_help_a sql dml --------------------------------------------------------------------------------- - --- name: user_info@tweet_help_a --- prepare: raw -SELECT * FROM @user WHERE username=? - --------------------------------------------------------------------------------- --- topic_a sql dml --------------------------------------------------------------------------------- - --- name: newest_tags@topic_a --- get newest tag information --- prepare: stmt -SELECT t.id id, - t.user_id user_id, - t.tag tag, - t.quote_num quote_num, - u.id "u.id", - u.nickname "u.nickname", - u.username "u.username", - u.status "u.status", - u.avatar "u.avatar", - u.is_admin "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 ?; - --- name: hot_tags@topic_a --- get get host tag information --- prepare: stmt -SELECT t.id id, - t.user_id user_id, - t.tag tag, - t.quote_num quote_num, - u.id "u.id", - u.nickname "u.nickname", - u.username "u.username", - u.status "u.status", - u.avatar "u.avatar", - u.is_admin "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 ?; - --- name: follow_tags@topic_a --- get get follow tag information --- prepare: stmt -SELECT t.id id, - t.user_id user_id, - t.tag tag, - t.quote_num quote_num, - u.id "u.id", - 1 as is_following, - c.is_top, - u.nickname "u.nickname", - u.username "u.username", - u.status "u.status", - u.avatar "u.avatar", - u.is_admin "u.is_admin" -FROM @topic_user c -JOIN @user u ON c.user_id = u.id -JOIN @tag t ON c.topic_id = t.id -WHERE c.is_del = 0 AND t.quote_num > 0 AND AND c.user_id=? -ORDER BY t.quote_num DESC -LIMIT ? OFFSET ?; - --- name: topic_infos@topic_a --- prepare: raw --- clause: in -SELECT topic_id, is_top -FROM @topic_user -WHERE is_del=0 AND user_id=? AND topic_id IN ?; - --- name: exist_topic_user@topic_a --- prepare: stmt -SELECT 1 FROM @topic_user WHERE user_id=? AND topic_id=? AND is_del=0; - --- name: follow_topic@topic_a --- prepare: stmt -INSERT INTO @topic_user(user_id, topic_id, created_on) VALUES (?, ?, ?) - --- name: unfollow_topic@topic_a --- prepare: stmt -UPDATE @topic_user -SET is_del=1, deleted_on=? -WHERE user_id=? AND topic_id=? AND is_del=0; - --- name: stick_topic@topic_a --- prepare: stmt -UPDATE @topic_user -SET is_top=1-is_top; modified_on=? -WHERE user_id=? AND topic_id=? AND is_del=0; - --- name: topic_is_top@topic_a --- prepare: stmt -SELECT is_top FROM @topic_user WHERE user_id=? AND topic_id=? AND is_del=0; - --- name: tags_by_keyword_a@topic_a --- get tags by keyword -SELECT id, user_id, tag, quote_num -FROM @tag -WHERE is_del = 0 -ORDER BY quote_num DESC -LIMIT 6; - --- name: tags_by_keyword_b@topic_a -SELECT id, user_id, tag, quote_num -FROM @tag WHERE is_del = 0 AND tag LIKE ? -ORDER BY quote_num DESC -LIMIT 6; - --- name: insert_tag@topic_a -INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) -VALUES (?, ?, ?, ?, 1); - --- name: tags_by_id_a@topic_a --- prepare: raw --- clause: in -SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0; - --- name: tags_by_id_b@topic_a --- prepare: raw --- clause: in -SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?); - --- name: decr_tags_by_id@topic_a --- prepare: raw --- clause: in -UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?); - --- name: tags_for_incr@topic_a --- prepare: raw --- clause: in -SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?); - --- name: incr_tags_by_id@topic_a --- 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: get_user_by_id@user_manage --- prepare: stmt -SELECT * FROM @user WHERE id=? AND is_del=0; - --- name: get_user_by_username@user_manage --- prepare: stmt -SELECT * FROM @user WHERE username=? AND is_del=0; - --- name: get_user_by_phone@user_manage --- prepare: stmt -SELECT * FROM @user WHERE phone=? AND is_del=0; - --- name: get_users_by_ids@user_manage --- prepare: raw --- clause: in -SELECT * FROM @user WHERE id IN (?) AND is_del=0; - --- name: get_users_by_keyword@user_manage --- prepare: stmt -SELECT * FROM @user WHERE username LIKE ? AND is_del=0 limit 6; - --- name: get_any_users@user_manage --- prepare: stmt -SELECT * FROM @user WHERE is_del=0 ORDER BY id ASC limit 6; - --- name: create_user@user_manage --- prepare: named_stmt -INSERT INTO @user (username, nickname, password, salt, avatar, status, created_on) -VALUES (:username, :nickname, :password, :salt, :avatar, :status, :created_on); - --- name: update_user@user_manage --- prepare: named_stmt -UPDATE @user -SET username=:username, - nickname=:nickname, - phone=:phone, - password=:password, - salt=:salt, - status=:status, - avatar=:avatar, - balance=:balance, - is_admin=:is_admin, - modified_on=:modified_on -WHERE id=? AND is_del=0; - --------------------------------------------------------------------------------- --- wallet sql dml --------------------------------------------------------------------------------- - --- name: get_user_wallet_bills@wallet --- prepare: stmt -SELECT * -FROM @wallet_statement -WHERE user_id=? AND is_del=0 -ORDER BY id DESC -LIMIT ? OFFSET ?; - --- name: get_user_wallet_bill_count@wallet --- prepare: stmt -SELECT count(*) FROM @wallet_statement WHERE user_id=? AND is_del=0; - --- name: get_recharge_by_id@wallet --- prepare: stmt -SELECT * FROM @wallet_recharge WHERE id=? AND is_del=?; - --- name: create_recharge@wallet --- prepare: stmt -INSERT INTO @wallet_recharge (user_id, amount, created_on) VALUES (?, ?, ?); - --- name: get_user_by_uid@wallet --- prepare: stmt -SELECT * FROM @user WHERE id=? AND is_del=0; - --- name: add_user_balance@wallet --- prepare: stmt -UPDATE @user SET balance=balance+?, modified_on=? WHERE id=? AND is_del=0; - --- name: minus_user_balance@wallet --- prepare: stmt -UPDATE @user SET balance=balance-?, modified_on=? WHERE id=? AND is_del=0; - --- name: create_wallet_statement@wallet --- prepare: stmt -INSERT INTO @wallet_statement (user_id, change_amount, balance_snapshot, reason, created_on) -VALUES (?, ?, ?, ?, ?); - --- name: get_user_balance@wallet --- prepare: stmt -SELECT balance FROM @user WHERE id=? AND is_del=0; - --- name: mark_success_recharge@wallet --- prepare: stmt -UPDATE @wallet_recharge -SET trade_no=?, trade_status='TRADE_SUCCESS', modified_on=? -WHERE id=? AND is_del=0; - --- name: new_post_attachment_bill@wallet --- prepare: stmt -INSERT INTO @post_attachment_bill (post_id, user_id, paid_amount, created_on) -VALUES (?, ?, ?, ?); - --- name: new_post_bill@wallet --- prepare: stmt -INSERT INTO @wallet_statement (post_id, user_id, change_amount, balance_snapshot, reason, created_on) -VALUES (?, ?, ?, ?, ?, ?); diff --git a/internal/dao/sakila/yesql/yesql_ac.sql b/internal/dao/sakila/yesql/yesql_ac.sql new file mode 100644 index 00000000..68d5036d --- /dev/null +++ b/internal/dao/sakila/yesql/yesql_ac.sql @@ -0,0 +1,226 @@ +-------------------------------------------------------------------------------- +-- file yesql_ac.sql +-- this sql file define all sql dml for next "A" version data logic +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- ship_index_a sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@ship_index_a +-- prepare: raw +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- simple_index_a sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@simple_index_a +-- prepare: raw +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- tweet_a sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@tweet_a +-- prepare: raw +SELECT * FROM @user WHERE username=? + +-- name: tweet_info_by_id@tweet_a +-- prepare: raw +SELECT * FROM @user WHERE username=? + +-- name: tweet_item_by_id@tweet_a +-- prepare: raw +SELECT * FROM @user WHERE username=? + +-- name: user_tweets_by_admin@tweet_a +-- prepare: raw +SELECT * FROM @user WHERE username=? + +-- name: user_tweets_by_self@tweet_a +-- prepare: raw +SELECT * FROM @user WHERE username=? + +-- name: user_tweets_by_friend@tweet_a +-- prepare: raw +SELECT * FROM @user WHERE username=? + +-- name: user_tweets_by_guest@tweet_a +-- prepare: raw +SELECT * FROM @user WHERE username=? + +-- name: reaction_by_tweet_id@tweet_a +-- prepare: raw +SELECT * FROM @user WHERE username=? + +-- name: user_reactions@tweet_a +-- prepare: raw +SELECT * FROM @user WHERE username=? + +-- name: favorite_by_tweet_id@tweet_a +-- prepare: raw +SELECT * FROM @user WHERE username=? + +-- name: user_favorites@tweet_a +-- prepare: raw +SELECT * FROM @user WHERE username=? + +-- name: attachment_by_tweet_id@tweet_a +-- prepare: raw +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- tweet_manage_a sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@tweet_manage_a +-- prepare: raw +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- tweet_help_a sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@tweet_help_a +-- prepare: raw +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- topic_a sql dml +-------------------------------------------------------------------------------- + +-- name: newest_tags@topic_a +-- get newest tag information +-- prepare: stmt +SELECT t.id id, + t.user_id user_id, + t.tag tag, + t.quote_num quote_num, + u.id "u.id", + u.nickname "u.nickname", + u.username "u.username", + u.status "u.status", + u.avatar "u.avatar", + u.is_admin "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 ?; + +-- name: hot_tags@topic_a +-- get get host tag information +-- prepare: stmt +SELECT t.id id, + t.user_id user_id, + t.tag tag, + t.quote_num quote_num, + u.id "u.id", + u.nickname "u.nickname", + u.username "u.username", + u.status "u.status", + u.avatar "u.avatar", + u.is_admin "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 ?; + +-- name: follow_tags@topic_a +-- get get follow tag information +-- prepare: stmt +SELECT t.id id, + t.user_id user_id, + t.tag tag, + t.quote_num quote_num, + u.id "u.id", + 1 as is_following, + c.is_top, + u.nickname "u.nickname", + u.username "u.username", + u.status "u.status", + u.avatar "u.avatar", + u.is_admin "u.is_admin" +FROM @topic_user c +JOIN @user u ON c.user_id = u.id +JOIN @tag t ON c.topic_id = t.id +WHERE c.is_del = 0 AND t.quote_num > 0 AND AND c.user_id=? +ORDER BY t.quote_num DESC +LIMIT ? OFFSET ?; + +-- name: topic_infos@topic_a +-- prepare: raw +-- clause: in +SELECT topic_id, is_top +FROM @topic_user +WHERE is_del=0 AND user_id=? AND topic_id IN ?; + +-- name: exist_topic_user@topic_a +-- prepare: stmt +SELECT 1 FROM @topic_user WHERE user_id=? AND topic_id=? AND is_del=0; + +-- name: follow_topic@topic_a +-- prepare: stmt +INSERT INTO @topic_user(user_id, topic_id, created_on) VALUES (?, ?, ?) + +-- name: unfollow_topic@topic_a +-- prepare: stmt +UPDATE @topic_user +SET is_del=1, deleted_on=? +WHERE user_id=? AND topic_id=? AND is_del=0; + +-- name: stick_topic@topic_a +-- prepare: stmt +UPDATE @topic_user +SET is_top=1-is_top; modified_on=? +WHERE user_id=? AND topic_id=? AND is_del=0; + +-- name: topic_is_top@topic_a +-- prepare: stmt +SELECT is_top FROM @topic_user WHERE user_id=? AND topic_id=? AND is_del=0; + +-- name: tags_by_keyword_a@topic_a +-- get tags by keyword +SELECT id, user_id, tag, quote_num +FROM @tag +WHERE is_del = 0 +ORDER BY quote_num DESC +LIMIT 6; + +-- name: tags_by_keyword_b@topic_a +SELECT id, user_id, tag, quote_num +FROM @tag WHERE is_del = 0 AND tag LIKE ? +ORDER BY quote_num DESC +LIMIT 6; + +-- name: insert_tag@topic_a +INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) +VALUES (?, ?, ?, ?, 1); + +-- name: tags_by_id_a@topic_a +-- prepare: raw +-- clause: in +SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0; + +-- name: tags_by_id_b@topic_a +-- prepare: raw +-- clause: in +SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?); + +-- name: decr_tags_by_id@topic_a +-- prepare: raw +-- clause: in +UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?); + +-- name: tags_for_incr@topic_a +-- prepare: raw +-- clause: in +SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?); + +-- name: incr_tags_by_id@topic_a +-- prepare: raw +-- clause: in +UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?); diff --git a/internal/dao/sakila/yesql/yesql_cc.sql b/internal/dao/sakila/yesql/yesql_cc.sql new file mode 100644 index 00000000..cc23932d --- /dev/null +++ b/internal/dao/sakila/yesql/yesql_cc.sql @@ -0,0 +1,1047 @@ +-------------------------------------------------------------------------------- +-- file yesql_cc.sql +-- this sql file define all sql dml for old version data logic +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- authorization_manage sql dml +-------------------------------------------------------------------------------- + +-- name: be_friend_ids@authorization_manage +-- prepare: stmt +SELECT user_id FROM @contact WHERE friend_id=? AND status=2 AND is_del=0; + +-- name: my_friend_set@authorization_manage +-- prepare: stmt +SELECT friend_id FROM @contact WHERE user_id=? AND status=2 AND is_del=0; + +-- name: is_friend@authorization_manage +-- prepare: stmt +SELECT status FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0; + +-------------------------------------------------------------------------------- +-- comment sql dml +-------------------------------------------------------------------------------- + +-- name: get_comments@comment +-- prepare: raw +SELECT * FROM @comment WHERE post_id=? AND is_del=0 ORDER BY %order% LIMIT ? OFFSET ?; + +-- name: get_comment_by_id@comment +-- prepare: stmt +SELECT * FROM @comment WHERE id=? AND is_del=0; + +-- name: get_comment_count@comment +-- prepare: named_stmt +SELECT count(*) FROM @comment WHERE post_id=:post_id AND is_del=0; + +-- name: get_comment_reply_by_id@comment +-- prepare: stmt +SELECT * FROM @comment_reply WHERE id=? AND is_del=0; + +-- name: get_comment_contents_by_ids@comment +-- prepare: raw +-- clause: in +SELECT * FROM @comment_content WHERE comment_id IN (?); + +-- name: get_commment_replies_by_ids@comment +-- prepare: raw +-- clause: in +SELECT * FROM @comment_reply WHERE comment_id IN (?) ORDER BY id ASC; + +-- name: get_users_by_ids@comment +-- prepare: raw +-- clause: in +SELECT id, nickname, username, status, avatar, is_admin FROM @user WHERE id IN (?); + +-- name: get_comment_thumbs@comment +-- prepare: stmt +SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=?; + +-------------------------------------------------------------------------------- +-- comment_manage sql dml +-------------------------------------------------------------------------------- + +-- name: delete_comment@comment_manage +-- prepare: stmt +UPDATE @comment SET deleted_on=?, is_del=1 WHERE id=? AND is_del=0; + +-- name: delete_comment_thumbs@comment_manage +-- prepare: stmt +UPDATE @tweet_comment_thumbs +SET deleted_on=?, is_del=1 +WHERE user_id=? AND tweet_id=? AND comment_id=? AND is_del=0; + +-- name: create_comment@comment_manage +-- prepare: stmt +INSERT INTO @comment (post_id, user_id, ip, ip_loc, created_on) +VALUES (?, ?, ?, ?, ?); + +-- name: create_comment_reply@comment_manage +-- prepare: stmt +INSERT INTO @comment_reply (comment_id, user_id, content, at_user_id, ip, ip_loc, created_on) +VALUES (?, ?, ?, ?, ?, ?, ?); + +-- name: delete_comment_reply@comment_manage +-- prepare: stmt +UPDATE @comment_reply SET deleted_on=?, is_del=1 WHERE id=? AND is_del=0; + +-- name: delete_reply_thumbs@comment_manage +-- prepare: stmt +UPDATE @tweet_comment_thumbs +SET deleted_on=?, is_del=1 +WHERE user_id=? AND comment_id=? AND reply_id=? AND is_del=0; + +-- name: create_comment_content@comment_manage +-- prepare: stmt +INSERT INTO @comment_content (comment_id, user_id, content, type, sort, created_on) +VALUES (?, ?, ?, ?, ?, ?); + +-- name: update_thumbs_updown_comment@comment_manage +-- prepare: named_stmt +UPDATE @tweet_comment_thumbs +SET is_thumbs_up=:is_thumbs_up, is_thumbs_down=:is_thumbs_down, modified_on=:modified_on +WHERE id=:id AND is_del=0; + +-- name: create_thumbs_updown_comment@comment_manage +-- prepare: named_stmt +INSERT INTO @tweet_comment_thumbs (user_id, tweet_id, comment_id, reply_id, is_thumbs_up, is_thumbs_down, comment_type, created_on) +VALUES (:user_id, :tweet_id, :comment_id, :reply_id, :is_thumbs_up, :is_thumbs_down, :comment_type, :created_on); + +-- name: update_comment_thumbs_count@comment_manage +-- prepare: stmt +UPDATE @comment +SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? +WHERE id=? AND is_del=0; + +-- name: get_tweet_comment_thumb@comment_manage +-- prepare: stmt +SELECT * +FROM @tweet_comment_thumbs +WHERE user_id=? AND tweet_id=? AND comment_id=? AND comment_type=0 AND is_del=0; + +-- name: get_comment_reply_thumb@comment_manage +-- prepare: stmt +SELECT * +FROM @tweet_comment_thumbs +WHERE user_id=? AND tweet_id=? AND comment_id=? AND reply_id=? AND comment_type=1 AND is_del=0; + +-- name: update_reply_thumbs_count@comment_manage +-- prepare: stmt +UPDATE @comment_reply +SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? +WHERE id=? AND is_del=0; + +-------------------------------------------------------------------------------- +-- following_manager sql dml +-------------------------------------------------------------------------------- + +-- name: create_following@following_manager +-- prepare: stmt +INSERT INTO @following (user_id, follow_id, created_on) VALUES (?, ?, ?); + +-- name: exist_following@following_manager +-- prepare: stmt +SELECT 1 FROM @following WHERE user_id=? AND follow_id=? AND is_del=0; + +-- name: delete_following@following_manager +-- prepare: stmt +UPDATE @following +SET is_del=0, deleted_on=? +WHERE user_id=? AND follow_id=? AND is_del=0; + +-- name: list_follows@following_manager +-- prepare: stmt +SELECT u.user_id user_id, + u.username username, + u.nickname nickname, + u.avatar avatar, + u.created_on created_on +FROM @following f JOIN @user u ON f.follow_id=u.id +WHERE f.user_id=? AND f.is_del=0 +ORDER BY u.nickname ASC +LIMIT ? OFFSET ?; + +-- name: count_follows@following_manager +-- prepare: stmt +SELECT count(*) FROM @following WHERE user_id=? AND is_del=0; + +-- name: list_followings@following_manager +-- prepare: stmt +SELECT u.user_id user_id, + u.username username, + u.nickname nickname, + u.avatar avatar, + u.created_on created_on +FROM @following f JOIN @user u ON f.user_id=u.id +WHERE f.follow_id=? AND f.is_del=0 +ORDER BY u.nickname ASC +LIMIT ? OFFSET ?; + +-- name: count_followings@following_manager +-- prepare: stmt +SELECT count(*) FROM @following WHERE follow_id=? AND is_del=0; + +-------------------------------------------------------------------------------- +-- contact_manager sql dml +-------------------------------------------------------------------------------- + +-- name: create_contact@contact_manager +-- prepare: stmt +INSERT INTO @contact (user_id, friend_id, status, created_on) VALUES (?, ?, ?, ?); + +-- name: fresh_contact_status@contact_manager +-- prepare: stmt +UPDATE @contact SET status=?, modified_on=?, is_del=0 WHERE id=?; + +-- name: create_message@contact_manager +-- prepare: named_stmt +INSERT INTO @message (sender_user_id, receiver_user_id, type, brief, content, reply_id, created_on) +VALUES (:sender_user_id, :receiver_user_id, :type, :brief, :content, :reply_id, :created_on); + +-- name: add_friend_msgs_update@contact_manager +-- prepare: stmt +UPDATE @message +SET reply_id=?, modified_on=? +WHERE ((sender_user_id = ? AND receiver_user_id = ?) OR (sender_user_id = ? AND receiver_user_id = ?)) AND type = ? AND reply_id = ?; + +-- name: reject_friend_msgs_update@contact_manager +-- prepare: stmt +UPDATE @message +SET reply_id=?, modified_on=? +WHERE sender_user_id = ? AND receiver_user_id = ? AND type = ? AND reply_id = ?; + +-- name: del_friend@contact_manager +-- prepare: stmt +UPDATE @contact SET status=4, is_del=1, deleted_on=? WHERE id=?; + +-- name: list_friend@contact_manager +-- prepare: stmt +SELECT c.friend_id user_id, u.username username, u.nickname nickname, u.avatar avatar, u.phone phone +FROM @contact c JOIN @user u +ON c.friend_id=u.id +WHERE user_id=? AND status=2 AND is_del=0 +ORDER BY u.nickname ASC +LIMIT ? OFFSET ?; + +-- name: total_friends_by_id@contact_manager +-- prepare: stmt +SELECT count(*) +FROM @contact +WHERE user_id=? AND status=2 AND is_del=0; + +-- name: get_contacts@contact_manager +-- prepare: stmt +SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del +FROM @contact +WHERE (user_id=? AND friend_id=?) OR (user_id=? AND friend_id=?); + +-- name: get_user_friend@contact_manager +-- prepare: stmt +SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del +FROM @contact +WHERE user_id=? AND friend_id=? AND is_del=0; + +-- name: get_contact@contact_manager +-- prepare: stmt +SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del +FROM @contact +WHERE user_id=? AND friend_id=?; + +-- name: is_friend@contact_manager +-- prepare: stmt +SELECT true FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0 AND status=2; + +-------------------------------------------------------------------------------- +-- message sql dml +-------------------------------------------------------------------------------- + +-- name: create_message@message +-- prepare: named_stmt +INSERT INTO @message (sender_user_id, receiver_user_id, type, brief, content, post_id, comment_id, reply_id, created_on) +VALUES (:sender_user_id, :receiver_user_id, :type, :brief, :content, :post_id, :comment_id, :reply_id, :created_on); + +-- name: get_unread_count@message +-- prepare: stmt +SELECT count(*) FROM @message WHERE receiver_user_id=? AND is_read=0 AND is_del=0; + +-- name: get_message_by_id@message +-- prepare: stmt +SELECT * FROM @message WHERE id=? AND is_del=0; + +-- name: read_message@message +-- prepare: stmt +UPDATE @message SET is_read=1, modified_on=? WHERE id=?; + +-- name: get_messages@message +-- prepare: named_stmt +SELECT * +FROM @message +WHERE receiver_user_id=:recerver_user_id AND is_del=0 +ORDER BY id DESC +LIMIT :limit OFFSET :offset + +-- name: get_message_count@message +-- prepare: named_stmt +SELECT count(*) FROM @message WHERE receiver_user_id=:recerver_user_id AND is_del=0; + +-------------------------------------------------------------------------------- +-- security sql dml +-------------------------------------------------------------------------------- + +-- name: get_latest_phone_captcha@security +-- prepare: stmt +SELECT * FROM @captcha WHERE phone=? AND is_del=0; + +-- name: use_phone_captcha@security +-- prepare: stmt +UPDATE @captcha SET use_times=use_times+1, modified_on=? WHERE id=? AND is_del=0; + +-- name: create_phone_captcha@security +-- prepare: named_stmt +INSERT INTO @captcha (phone, captcha, expired_on, created_on) +VALUES (:phone, :captcha, :expired_on, :created_on); + +-------------------------------------------------------------------------------- +-- ship_index sql dml +-------------------------------------------------------------------------------- + +-- name: index_by_admin@ship_index +-- prepare: stmt +SELECT * +FROM @p_post +WHERE is_del=0 +ORDER BY is_top DESC, latest_replied_on DESC +LIMIT ? OFFSET ?; + +-- name: index_count_by_admin@ship_index +-- prepare: stmt +SELECT count(*) +FROM @p_post +WHERE is_del=0; + +-- name: index_by_guest@ship_index +-- prepare: stmt +SELECT * +FROM @p_post +WHERE visibility=0 AND is_del=0 +ORDER BY is_top DESC, latest_replied_on DESC +LIMIT ? OFFSET ?; + +-- name: index_count_by_guest@ship_index +-- prepare: stmt +SELECT count(*) +FROM @p_post +WHERE visibility=0 AND is_del=0; + +-- name: index_by_self@ship_index +-- prepare: raw +-- clause: in +SELECT * +FROM @p_post +WHERE is_del=0 AND + (visibility=0 OR + (visibility=1 AND user_id=?) OR + (visibility=2 AND user_id IN ?)) +ORDER BY is_top DESC, latest_replied_on DESC +LIMIT ? OFFSET ?; + +-- name: index_count_by_self@ship_index +-- prepare: raw +-- clause: in +SELECT count(*) +FROM @p_post +WHERE is_del=0 AND + (visibility=0 OR + (visibility=1 AND user_id=?) OR + (visibility=2 AND user_id IN ?)); + +-------------------------------------------------------------------------------- +-- simple_index sql dml +-------------------------------------------------------------------------------- + +-- name: index@simple_index +-- prepare: stmt +SELECT * +FROM @p_post +WHERE visibility=0 +ORDER BY is_top DESC, latest_replied_on DESC +LIMIT ? OFFSET ?; + +-- name: index_count@simple_index +-- prepare: stmt +SELECT count(*) +FROM @p_post +WHERE visibility=0; + +-------------------------------------------------------------------------------- +-- tweet sql dml +-------------------------------------------------------------------------------- + +-- name: get_post_by_id@tweet +-- prepare: stmt +SELECT * FROM @post WHERE id=? AND is_del=0; + +-- name: get_user_posts@tweet +-- prepare: raw +-- clause: in +SELECT * FROM @post +WHERE user_id=? AND visibility IN (?) +ORDER BY latest_replies_on DESC +LIMIT ? OFFSET ?; + +-- name: get_any_posts@tweet +-- prepare: raw +-- clause: in +SELECT * FROM @post WHERE visibility IN (?) AND is_del=0 LIMIT ? OFFSET ?; + +-- name: get_user_post_count@tweet +-- prepare: raw +-- clause: in +SELECT count(*) FROM @post WHERE user_id=? AND visibility IN (?); + +-- name: get_any_post_count@tweet +-- prepare: raw +-- clause: in +SELECT count(*) FROM @post WHERE visibility IN (?); + +-- name: get_user_post_star@tweet +-- prepare: stmt +SELECT + s.*, + P.ID "post.id", + P.user_id "post.user_id", + P.comment_count "post.comment_count", + P.collection_count "post.collection_count", + P.upvote_count "post.upvote_count", + P.share_count "post.share_count", + P.visibility "post.visibility", + P.is_top "post.is_top", + P.is_essence "post.is_essence", + P.is_lock "post.is_lock", + P.latest_replied_on "post.latest_replied_on", + P.tags "post.tags", + P.attachment_price "post.attachment_price", + P.ip "post.ip", + P.ip_loc "post.ip_loc", + P.is_del "post.is_del", + P.created_on "post.created_on", + P.modified_on "post.modified_on", + P.deleted_on "post.deleted_on" +FROM + @post_star s + JOIN @post P ON s.post_id = P.ID +WHERE + s.post_id = ? + AND s.user_id = ? + AND s.is_del = 0 + AND ( visibility <> 1 OR ( visibility = 1 AND P.user_id = ? ) ) +ORDER BY + P.ID DESC; + +-- name: get_user_post_stars@tweet +-- prepare: stmt +SELECT + s.*, + P.ID "post.id", + P.user_id "post.user_id", + P.comment_count "post.comment_count", + P.collection_count "post.collection_count", + P.upvote_count "post.upvote_count", + P.share_count "post.share_count", + P.visibility "post.visibility", + P.is_top "post.is_top", + P.is_essence "post.is_essence", + P.is_lock "post.is_lock", + P.latest_replied_on "post.latest_replied_on", + P.tags "post.tags", + P.attachment_price "post.attachment_price", + P.ip "post.ip", + P.ip_loc "post.ip_loc", + P.is_del "post.is_del", + P.created_on "post.created_on", + P.modified_on "post.modified_on", + P.deleted_on "post.deleted_on" +FROM + @post_star s + JOIN @post P ON s.post_id = P.ID +WHERE + s.user_id = ? + AND s.is_del = 0 + AND ( visibility <> 1 OR ( visibility = 1 AND P.user_id = ? ) ) +ORDER BY + s.ID DESC, + P.ID DESC +LIMIT ? OFFSET ?; + +-- name: get_user_post_star_count@tweet +-- prepare: stmt +SELECT + count(*) +FROM + @post_star s + JOIN @post P ON s.post_id = P.ID +WHERE + s.user_id = ? + AND s.is_del = 0 + AND ( visibility <> 1 OR ( visibility = 1 AND P.user_id = ? ) ); + +-- name: get_user_post_collection@tweet +-- prepare: stmt +SELECT + s.*, + P.ID "post.id", + P.user_id "post.user_id", + P.comment_count "post.comment_count", + P.collection_count "post.collection_count", + P.upvote_count "post.upvote_count", + P.share_count "post.share_count", + P.visibility "post.visibility", + P.is_top "post.is_top", + P.is_essence "post.is_essence", + P.is_lock "post.is_lock", + P.latest_replied_on "post.latest_replied_on", + P.tags "post.tags", + P.attachment_price "post.attachment_price", + P.ip "post.ip", + P.ip_loc "post.ip_loc", + P.is_del "post.is_del", + P.created_on "post.created_on", + P.modified_on "post.modified_on", + P.deleted_on "post.deleted_on" +FROM + @post_collection s + JOIN @post P ON s.post_id = P.ID +WHERE + s.post_id = ? + AND s.user_id = ? + AND s.is_del = 0 + AND ( visibility <> 1 OR ( visibility = 1 AND P.user_id = ? ) ) +ORDER BY + P.ID DESC; + +-- name: get_user_post_collections@tweet +-- prepare: stmt +SELECT + s.*, + P.ID "post.id", + P.user_id "post.user_id", + P.comment_count "post.comment_count", + P.collection_count "post.collection_count", + P.upvote_count "post.upvote_count", + P.share_count "post.share_count", + P.visibility "post.visibility", + P.is_top "post.is_top", + P.is_essence "post.is_essence", + P.is_lock "post.is_lock", + P.latest_replied_on "post.latest_replied_on", + P.tags "post.tags", + P.attachment_price "post.attachment_price", + P.ip "post.ip", + P.ip_loc "post.ip_loc", + P.is_del "post.is_del", + P.created_on "post.created_on", + P.modified_on "post.modified_on", + P.deleted_on "post.deleted_on" +FROM + @post_collection s + JOIN @post P ON s.post_id = P.ID +WHERE + s.user_id = ? + AND s.is_del = 0 + AND ( visibility <> 1 OR ( visibility = 1 AND P.user_id = ? ) ) +ORDER BY + s.ID DESC, + P.ID DESC +LIMIT ? OFFSET ?; + +-- name: get_user_post_collection_count@tweet +-- prepare: stmt +SELECT + count(*) +FROM + @post_collection s + JOIN @post P ON s.post_id = P.ID +WHERE + s.user_id = ? + AND s.is_del = 0 + AND ( visibility <> 1 OR ( visibility = 1 AND P.user_id = ? ) ); + +-- name: get_post_attachment_bill@tweet +-- prepare: stmt +SELECT * FROM @post_attachment_bill WHERE post_id=? AND user_id=? AND is_del=0; + +-- name: get_post_contents_by_ids@tweet +-- prepare: raw +-- clause: in +SELECT * +FROM @post_content +WHERE post_id IN (?) AND is_del=0; + +-- name: get_post_content_by_id@tweet +-- prepare: stmt +SELECT * FROM @post_content WHERE id=? AND is_del=0; + +-- name: user_media_tweets_by_guest@tweet +-- prepare: stmt +SELECT * +FROM @post_by_media +WHERE is_del=0 AND user_id=? AND visibility=0 +ORDER BY latest_replied_on DESC +LIMIT ? OFFSET ?; + +-- name: user_media_tweets_count_by_guest@tweet +-- prepare: stmt +SELECT count(*) +FROM @post_by_media +WHERE is_del=0 AND user_id=? AND visibility=0; + +-- name: user_media_tweets_by_friend@tweet +-- prepare: stmt +SELECT * +FROM @post_by_media +WHERE is_del=0 AND user_id=? AND (visibility=0 OR visibility=2) +ORDER BY latest_replied_on DESC +LIMIT ? OFFSET ?; + +-- name: user_media_tweets_count_by_friend@tweet +-- prepare: stmt +SELECT count(*) +FROM @post_by_media +WHERE is_del=0 AND user_id=? AND (visibility=0 OR visibility=2); + +-- name: user_media_tweets_by_self@tweet +-- prepare: stmt +SELECT * +FROM @post_by_media +WHERE is_del=0 AND user_id=? +ORDER BY latest_replied_on DESC +LIMIT ? OFFSET ?; + +-- name: user_media_tweets_count_by_self@tweet +-- prepare: stmt +SELECT count(*) +FROM @post_by_media +WHERE is_del=0 AND user_id=?; + +-- name: user_comment_tweets_by_guest@tweet +-- prepare: stmt +SELECT * +FROM @post_by_comment +WHERE is_del=0 AND comment_user_id=? AND visibility=0 +ORDER BY latest_replied_on DESC +LIMIT ? OFFSET ?; + +-- name: user_comment_tweets_count_by_guest@tweet +-- prepare: stmt +SELECT count(*) +FROM @post_by_comment +WHERE is_del=0 AND comment_user_id=? AND visibility=0; + +-- name: user_comment_tweets_by_friend@tweet +-- prepare: stmt +SELECT * +FROM @post_by_comment +WHERE is_del=0 AND comment_user_id=? AND (visibility=0 OR visibility=2) +ORDER BY latest_replied_on DESC +LIMIT ? OFFSET ?; + +-- name: user_comment_tweets_count_by_friend@tweet +-- prepare: stmt +SELECT count(*) +FROM @post_by_comment +WHERE is_del=0 AND comment_user_id=? AND (visibility=0 OR visibility=2); + +-- name: user_comment_tweets_by_self@tweet +-- prepare: stmt +SELECT * +FROM @post_by_comment +WHERE is_del=0 AND comment_user_id=? +ORDER BY latest_replied_on DESC +LIMIT ? OFFSET ?; + +-- name: user_comment_tweets_count_by_self@tweet +-- prepare: stmt +SELECT count(*) +FROM @post_by_comment +WHERE is_del=0 AND comment_user_id=?; + +-- name: user_star_tweets_by_guest@tweet +-- prepare: stmt +SELECT + star.*, + post.ID "post.id", + post.created_on "post.created_on", + post.modified_on "post.modified_on", + post.deleted_on "post.deleted_on", + post.is_del "post.is_del", + post.user_id "post.user_id", + post.comment_count "post.comment_count", + post.collection_count "post.collection_count", + post.share_count "post.share_count", + post.upvote_count "post.upvote_count", + post.visibility "post.visibility", + post.is_top "post.is_top", + post.is_essence "post.is_essence", + post.is_lock "post.is_lock", + post.latest_replied_on "post.latest_replied_on", + post.tags "post.tags", + post.attachment_price "post.attachment_price", + post.ip "post.ip", + post.ip_loc "post.ip_loc" +FROM + @post_star star + JOIN @post post ON star.post_id = post.ID +WHERE + star.is_del = 0 + AND star.user_id =? + AND post.visibility = 0 +ORDER BY post.latest_replied_on DESC +LIMIT ? OFFSET ?; + +-- name: user_star_tweets_count_by_guest@tweet +-- prepare: stmt +SELECT count(*) +FROM + @post_star star + JOIN @post post ON star.post_id = post.ID +WHERE star.is_del=0 AND star.user_id=? AND post.visibility=0; + +-- name: user_star_tweets_by_friend@tweet +-- prepare: stmt +SELECT + star.*, + post.ID "post.id", + post.created_on "post.created_on", + post.modified_on "post.modified_on", + post.deleted_on "post.deleted_on", + post.is_del "post.is_del", + post.user_id "post.user_id", + post.comment_count "post.comment_count", + post.collection_count "post.collection_count", + post.share_count "post.share_count", + post.upvote_count "post.upvote_count", + post.visibility "post.visibility", + post.is_top "post.is_top", + post.is_essence "post.is_essence", + post.is_lock "post.is_lock", + post.latest_replied_on "post.latest_replied_on", + post.tags "post.tags", + post.attachment_price "post.attachment_price", + post.ip "post.ip", + post.ip_loc "post.ip_loc" +FROM + @post_star star + JOIN @post post ON star.post_id = post.ID +WHERE star.is_del=0 AND star.user_id=? AND (post.visibility=0 OR post.visibility=2) +ORDER BY post.latest_replied_on DESC +LIMIT ? OFFSET ?; + +-- name: user_star_tweets_count_by_friend@tweet +-- prepare: stmt +SELECT count(*) +FROM + @post_star star + JOIN @post post ON star.post_id = post.ID +WHERE star.is_del=0 AND star.user_id=? AND (post.visibility=0 OR post.visibility=2); + +-- name: user_star_tweets_by_self@tweet +-- prepare: stmt +SELECT + star.*, + post.ID "post.id", + post.created_on "post.created_on", + post.modified_on "post.modified_on", + post.deleted_on "post.deleted_on", + post.is_del "post.is_del", + post.user_id "post.user_id", + post.comment_count "post.comment_count", + post.collection_count "post.collection_count", + post.share_count "post.share_count", + post.upvote_count "post.upvote_count", + post.visibility "post.visibility", + post.is_top "post.is_top", + post.is_essence "post.is_essence", + post.is_lock "post.is_lock", + post.latest_replied_on "post.latest_replied_on", + post.tags "post.tags", + post.attachment_price "post.attachment_price", + post.ip "post.ip", + post.ip_loc "post.ip_loc" +FROM + @post_star star + JOIN @post post ON star.post_id = post.ID +WHERE star.is_del=0 AND star.user_id=? AND (post.visibility<>0 (post.visibility=0 AND post.user_id=?)) +ORDER BY post.latest_replied_on DESC; +LIMIT ? OFFSET ?; + +-- name: user_star_tweets_count_by_self@tweet +-- prepare: stmt +SELECT count(*) +FROM + @post_star star + JOIN @post post ON star.post_id = post.ID +WHERE star.is_del=0 AND star.user_id=? AND (post.visibility<>0 (post.visibility=0 AND post.user_id=?)); + +-- name: user_star_tweets_by_admin@tweet +-- prepare: stmt +SELECT + star.*, + post.ID "post.id", + post.created_on "post.created_on", + post.modified_on "post.modified_on", + post.deleted_on "post.deleted_on", + post.is_del "post.is_del", + post.user_id "post.user_id", + post.comment_count "post.comment_count", + post.collection_count "post.collection_count", + post.share_count "post.share_count", + post.upvote_count "post.upvote_count", + post.visibility "post.visibility", + post.is_top "post.is_top", + post.is_essence "post.is_essence", + post.is_lock "post.is_lock", + post.latest_replied_on "post.latest_replied_on", + post.tags "post.tags", + post.attachment_price "post.attachment_price", + post.ip "post.ip", + post.ip_loc "post.ip_loc" +FROM + @post_star star + JOIN @post post ON star.post_id = post.ID +WHERE star.is_del=0 AND star.user_id=? +ORDER BY post.latest_replied_on DESC; +LIMIT ? OFFSET ?; + +-- name: user_star_tweets_count_by_admin@tweet +-- prepare: stmt +SELECT count(*) +FROM + @post_star star + JOIN @post post ON star.post_id = post.ID +WHERE star.is_del=0 AND star.user_id=?; + +-------------------------------------------------------------------------------- +-- tweet_manage sql dml +-------------------------------------------------------------------------------- + +-- name: add_post@tweet_manage +-- prepare: named_stmt +INSERT INTO @post (user_id, tags, ip, ip_loc, attachment_price, visibility, latest_replies_on, created_on) +VALUES (:user_id, :tags, :ip, :ip_loc, :attachment_price, :visibility, :latest_replies_on, :created_on); + +-- name: media_content_by_post_id@tweet_manage +-- prepare stmt +SELECT content FROM post_content WHERE post_id=? AND is_del=0 AND type IN (3, 4, 5, 7, 8); + +-- name: del_post_by_id@tweet_manage +-- prepare: stmt +UPDATE @post SET is_del=1, deleted_on=? WHERE id=? AND is_del=0; + +-- name: lock_post@tweet_manage +-- prepare: stmt +UPDATE @post SET is_lock=1-is_lock, modified_on=? WHERE id=? AND is_del=0; + +-- name: stick_post@tweet_manage +-- prepare: stmt +UPDATE @post SET is_top=1-is_top, modified_on=? WHERE id=? AND is_del=0; + +-- name: visible_post@tweet_manage +-- prepare: stmt +UPDATE @post SET visibility=?, is_top=?, modified_on=? WHERE id=? AND is_del=0; + +-- name: highlight_post@tweet_manage +-- prepare: stmt +UPDATE @post SET is_essence=1-is_essence WHERE id=? AND is_del=0; + +-- name: post_highlight_status@tweet_manage +-- prepare: stmt +SELECT user_id, is_essence FROM @post WHERE id=? AND is_del=0; + +-- name: update_post@tweet_manage +-- prepare: named_stmt +UPDATE @post SET comment_count=:comment_count, + upvote_count=:upvote_count, + collection_count=:collection_count, + latest_replies_on=:latest_replies_on, + modified_on=:modified_on +WHERE id=:id AND is_del=0; + +-- name: add_post_star@tweet_manage +-- prepare: stmt +INSERT INTO @post_star (post_id, user_id, created_on) +VALUES (?, ?, ?); + +-- name: del_post_star@tweet_manage +-- prepare: stmt +UPDATE @post_star SET is_del=1, deleted_on=? WHERE id=? AND is_del=0; + +-- name: add_post_collection@tweet_manage +-- prepare: stmt +INSERT INTO @post_collection (post_id, user_id, created_on) +VALUES (?, ?, ?); + +-- name: del_post_collection@tweet_manage +-- prepare: stmt +UPDATE @post_collection SET is_del=1, deleted_on=? WHERE id=? AND is_del=0; + +-- name: add_post_content@tweet_manage +-- prepare: named_stmt +INSERT INTO @post_content (post_id, user_id, content, type, sort, created_on) +VALUES (:post_id, :user_id, :content, :type, :sort, :created_on); + +-- name: add_attachment@tweet_manage +-- prepare: stmt +INSERT INTO @attachment (user_id, file_size, img_width, img_height, type, content, created_on) +VALUES (?, ?, ?, ?, ?, ?, ?); + +-- name: comment_ids_by_post_id@tweet_manage +-- prepare: stmt +SELECT id FROM @comment WHERE post_id=? AND is_del=0; + +-- name: comment_media_from_comment_ids@tweet_manage +-- prepare: raw +-- clause: in +SELECT content FROM @comment_content WHERE comment_id IN (?) AND type=3 AND is_del=0; + +-- name: del_comment_by_post_id@tweet_manage +-- prepare: stmt +UPDATE @comment SET deleted_on=?, is_del=1 WHERE post_id=? AND is_del=0; + +-- name: del_comment_content_by_comment_ids@tweet_manage +-- prepare: raw +-- clause: in +UPDATE @comment_content SET deleted_on=?, is_del=1 WHERE comment_id IN (?) AND is_del=0; + +-- name: del_reply_by_comment_ids@tweet_manage +-- prepare: raw +-- clause: in +UPDATE @comment_reply SET deleted_on=?, is_del=1 WHERE comment_id IN (?) AND is_del=0; + +-------------------------------------------------------------------------------- +-- tweet_help sql dml +-------------------------------------------------------------------------------- + +-- name: get_post_content_by_ids@tweet_help +-- prepare: raw +-- clause: in +SELECT id, post_id, content, type, sort +FROM @post_content +WHERE post_id IN (?) AND is_del=0; + +-- name: get_users_by_ids@tweet_help +-- prepare: raw +-- clause: in +SELECT id, username, nickname, status, avatar, is_admin +FROM @user +WHERE id IN (?) AND is_del=0; + +-------------------------------------------------------------------------------- +-- user_manage sql dml +-------------------------------------------------------------------------------- + +-- name: get_user_by_id@user_manage +-- prepare: stmt +SELECT * FROM @user WHERE id=? AND is_del=0; + +-- name: get_user_by_username@user_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? AND is_del=0; + +-- name: get_user_by_phone@user_manage +-- prepare: stmt +SELECT * FROM @user WHERE phone=? AND is_del=0; + +-- name: get_users_by_ids@user_manage +-- prepare: raw +-- clause: in +SELECT * FROM @user WHERE id IN (?) AND is_del=0; + +-- name: get_users_by_keyword@user_manage +-- prepare: stmt +SELECT * FROM @user WHERE username LIKE ? AND is_del=0 limit 6; + +-- name: get_any_users@user_manage +-- prepare: stmt +SELECT * FROM @user WHERE is_del=0 ORDER BY id ASC limit 6; + +-- name: create_user@user_manage +-- prepare: named_stmt +INSERT INTO @user (username, nickname, password, salt, avatar, status, created_on) +VALUES (:username, :nickname, :password, :salt, :avatar, :status, :created_on); + +-- name: update_user@user_manage +-- prepare: named_stmt +UPDATE @user +SET username=:username, + nickname=:nickname, + phone=:phone, + password=:password, + salt=:salt, + status=:status, + avatar=:avatar, + balance=:balance, + is_admin=:is_admin, + modified_on=:modified_on +WHERE id=? AND is_del=0; + +-------------------------------------------------------------------------------- +-- wallet sql dml +-------------------------------------------------------------------------------- + +-- name: get_user_wallet_bills@wallet +-- prepare: stmt +SELECT * +FROM @wallet_statement +WHERE user_id=? AND is_del=0 +ORDER BY id DESC +LIMIT ? OFFSET ?; + +-- name: get_user_wallet_bill_count@wallet +-- prepare: stmt +SELECT count(*) FROM @wallet_statement WHERE user_id=? AND is_del=0; + +-- name: get_recharge_by_id@wallet +-- prepare: stmt +SELECT * FROM @wallet_recharge WHERE id=? AND is_del=?; + +-- name: create_recharge@wallet +-- prepare: stmt +INSERT INTO @wallet_recharge (user_id, amount, created_on) VALUES (?, ?, ?); + +-- name: get_user_by_uid@wallet +-- prepare: stmt +SELECT * FROM @user WHERE id=? AND is_del=0; + +-- name: add_user_balance@wallet +-- prepare: stmt +UPDATE @user SET balance=balance+?, modified_on=? WHERE id=? AND is_del=0; + +-- name: minus_user_balance@wallet +-- prepare: stmt +UPDATE @user SET balance=balance-?, modified_on=? WHERE id=? AND is_del=0; + +-- name: create_wallet_statement@wallet +-- prepare: stmt +INSERT INTO @wallet_statement (user_id, change_amount, balance_snapshot, reason, created_on) +VALUES (?, ?, ?, ?, ?); + +-- name: get_user_balance@wallet +-- prepare: stmt +SELECT balance FROM @user WHERE id=? AND is_del=0; + +-- name: mark_success_recharge@wallet +-- prepare: stmt +UPDATE @wallet_recharge +SET trade_no=?, trade_status='TRADE_SUCCESS', modified_on=? +WHERE id=? AND is_del=0; + +-- name: new_post_attachment_bill@wallet +-- prepare: stmt +INSERT INTO @post_attachment_bill (post_id, user_id, paid_amount, created_on) +VALUES (?, ?, ?, ?); + +-- name: new_post_bill@wallet +-- prepare: stmt +INSERT INTO @wallet_statement (post_id, user_id, change_amount, balance_snapshot, reason, created_on) +VALUES (?, ?, ?, ?, ?, ?);