merge from x/sqlx branch

r/paopao-ce-xtra
Michael Li 2 years ago
commit 3998e22ed1
No known key found for this signature in database

@ -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.1.6
github.com/alimy/yesql v1.5.0
github.com/aliyun/aliyun-oss-go-sdk v2.2.8+incompatible
github.com/allegro/bigcache/v3 v3.1.0
github.com/bufbuild/connect-go v1.10.0

@ -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.1.6 h1:4on8osVaTpecfzf7gXM/1okyHMIaDKEkjHGdoqiZBQs=
github.com/alimy/yesql v1.1.6/go.mod h1:Y0FdRIwIbJyTv56wSX+MpaIHiAW1PyKTDYO6K/er4JY=
github.com/alimy/yesql v1.5.0 h1:Xmx+yBQCWA4f5xsraypbMnY7id8bckjUr8zxynteDBE=
github.com/alimy/yesql v1.5.0/go.mod h1:Y0FdRIwIbJyTv56wSX+MpaIHiAW1PyKTDYO6K/er4JY=
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=

@ -7,8 +7,11 @@ package sakila
import (
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/internal/core/ms"
"github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc"
"github.com/rocboss/paopao-ce/pkg/debug"
"github.com/rocboss/paopao-ce/pkg/types"
"github.com/sirupsen/logrus"
)
var (
@ -20,33 +23,51 @@ type authorizationManageSrv struct {
q *cc.AuthorizationManage
}
func (s *authorizationManageSrv) IsAllow(user *core.User, action *core.Action) bool {
// TODO
debug.NotImplemented()
return false
func (s *authorizationManageSrv) IsAllow(user *ms.User, action *ms.Action) bool {
// user is activation if had bind phone
isActivation := (len(user.Phone) != 0)
isFriend := s.isFriend(user.ID, action.UserId)
// TODO: just use defaut act authorization chek rule now
return action.Act.IsAllow(user, action.UserId, isFriend, isActivation)
}
func (s *authorizationManageSrv) MyFriendSet(userId int64) core.FriendSet {
// TODO
debug.NotImplemented()
return nil
func (s *authorizationManageSrv) MyFriendSet(userId int64) ms.FriendSet {
var ids []string
if err := s.q.MyFriendSet.Get(&ids, userId); err != nil {
logrus.Warnf("get my FriendSet error: %s", err)
return ms.FriendSet{}
}
resp := make(ms.FriendSet, len(ids))
for _, id := range ids {
resp[id] = types.Empty{}
}
return resp
}
func (s *authorizationManageSrv) BeFriendFilter(userId int64) core.FriendFilter {
// TODO
debug.NotImplemented()
return nil
func (s *authorizationManageSrv) BeFriendFilter(userId int64) ms.FriendFilter {
var ids []int64
if err := s.q.BeFriendIds.Get(&ids, userId); err != nil {
logrus.Warnf("get my BeFriendFilter error: %s", err)
return ms.FriendFilter{}
}
resp := make(ms.FriendFilter, len(ids))
for _, id := range ids {
resp[id] = types.Empty{}
}
return resp
}
func (s *authorizationManageSrv) BeFriendIds(userId int64) ([]int64, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *authorizationManageSrv) BeFriendIds(userId int64) (res []int64, err error) {
err = s.q.BeFriendIds.Get(&res, userId)
return
}
func (s *authorizationManageSrv) isFriend(userId int64, friendId int64) bool {
// TODO
debug.NotImplemented()
var status int8
err := s.q.IsFriend.Get(&status, userId, friendId)
if err == nil || status == cs.ContactStatusAgree {
return true
}
return false
}

@ -5,11 +5,16 @@
package sakila
import (
"strings"
"time"
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/internal/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/pkg/types"
)
var (
@ -27,95 +32,343 @@ type commentManageSrv struct {
q *cc.CommentManage
}
func (s *commentSrv) GetComments(conditions *core.ConditionsT, offset, limit int) ([]*core.Comment, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *commentSrv) GetComments(r *ms.ConditionsT, offset, limit int) (res []*ms.Comment, err error) {
order := (*r)["ORDER"].(string)
postId := (*r)["post_id"]
stmt := strings.Replace(s.q.GetComments, "%order%", order, 1)
err = s.db.Select(&res, stmt, postId, limit, offset)
return
}
func (s *commentSrv) GetCommentByID(id int64) (*core.Comment, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *commentSrv) GetCommentByID(id int64) (res *ms.Comment, err error) {
err = s.q.GetCommentById.Get(res, id)
return
}
func (s *commentSrv) GetCommentReplyByID(id int64) (*core.CommentReply, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *commentSrv) GetCommentReplyByID(id int64) (res *ms.CommentReply, err error) {
err = s.q.GetCommentReplyById.Get(res, id)
return
}
func (s *commentSrv) GetCommentCount(conditions *core.ConditionsT) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
func (s *commentSrv) GetCommentCount(r *ms.ConditionsT) (res int64, err error) {
err = s.q.GetCommentCount.Get(&res, r)
return
}
func (s *commentSrv) GetCommentContentsByIDs(ids []int64) ([]*core.CommentContent, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *commentSrv) GetCommentContentsByIDs(ids []int64) (res []*ms.CommentContent, err error) {
err = s.inSelect(&res, s.q.GetCommentContentsByIds, ids)
return res, err
}
func (s *commentSrv) GetCommentThumbsMap(userId int64, tweetId int64) (cs.CommentThumbsMap, cs.CommentThumbsMap, error) {
// TODO
return nil, nil, debug.ErrNotImplemented
if userId < 0 {
return nil, nil, nil
}
commentThumbsList := cs.CommentThumbsList{}
err := s.q.GetCommentThumbs.Select(&commentThumbsList, userId, tweetId)
if err != nil {
return nil, nil, err
}
commentThumbs, replyThumbs := make(cs.CommentThumbsMap), make(cs.CommentThumbsMap)
for _, thumbs := range commentThumbsList {
if thumbs.CommentType == 0 {
commentThumbs[thumbs.CommentID] = thumbs
} else {
replyThumbs[thumbs.ReplyID] = thumbs
}
}
return commentThumbs, replyThumbs, nil
}
func (s *commentSrv) GetCommentRepliesByID(ids []int64) ([]*core.CommentReplyFormated, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *commentSrv) GetCommentRepliesByID(ids []int64) ([]*ms.CommentReplyFormated, error) {
replies := []*ms.CommentReply{}
err := s.inSelect(&replies, s.q.GetCommmentRepliesByIds, ids)
if err != nil {
return nil, err
}
userIds := []int64{}
for _, reply := range replies {
userIds = append(userIds, reply.UserID, reply.AtUserID)
}
users := []*ms.UserFormated{}
if err = s.inSelect(&users, s.q.GetUsersByIds, userIds); err != nil {
return nil, err
}
repliesFormated := []*ms.CommentReplyFormated{}
for _, reply := range replies {
replyFormated := reply.Format()
for _, user := range users {
if reply.UserID == user.ID {
replyFormated.User = user
}
if reply.AtUserID == user.ID {
replyFormated.AtUser = user
}
}
repliesFormated = append(repliesFormated, replyFormated)
}
return repliesFormated, nil
}
func (s *commentManageSrv) DeleteComment(comment *core.Comment) error {
// TODO
debug.NotImplemented()
return nil
// DeleteComment delete comment
// TODO: need delete related replies and update tweet comment count and comment content?
func (s *commentManageSrv) DeleteComment(r *ms.Comment) error {
return s.with(func(tx *sqlx.Tx) error {
now := time.Now().Unix()
if _, err := tx.Stmtx(s.q.DeleteComment).Exec(now, r.ID); err != nil {
return err
}
_, err := tx.Stmtx(s.q.DeleteCommentThumbs).Exec(now, r.UserID, r.PostID, r.ID)
return err
})
}
func (s *commentManageSrv) CreateComment(comment *core.Comment) (*core.Comment, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *commentManageSrv) CreateComment(r *ms.Comment) (*ms.Comment, error) {
res, err := s.q.CreateComment.Exec(r.PostID, r.UserID, r.IP, r.IPLoc, time.Now().Unix())
if err != nil {
return nil, err
}
id, err := res.LastInsertId()
if err != nil {
return nil, err
}
r.Model = &dbr.Model{
ID: id,
}
return r, nil
}
func (s *commentManageSrv) CreateCommentReply(reply *core.CommentReply) (*core.CommentReply, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *commentManageSrv) CreateCommentReply(r *ms.CommentReply) (*ms.CommentReply, error) {
res, err := s.q.CreateCommentReply.Exec(r.CommentID, r.UserID, r.Content,
r.AtUserID, r.IP, r.IPLoc, time.Now().Unix())
if err != nil {
return nil, err
}
id, err := res.LastInsertId()
if err != nil {
return nil, err
}
r.Model = &dbr.Model{ID: id}
return r, nil
}
func (s *commentManageSrv) DeleteCommentReply(reply *core.CommentReply) error {
// TODO
debug.NotImplemented()
return nil
func (s *commentManageSrv) DeleteCommentReply(r *ms.CommentReply) error {
return s.with(func(tx *sqlx.Tx) error {
now := time.Now().Unix()
if _, err := tx.Stmtx(s.q.DeleteCommentReply).Exec(now, r.ID); err != nil {
return err
}
_, err := tx.Stmtx(s.q.DeleteCommentThumbs).Exec(now, r.UserID, r.CommentID, r.ID)
return err
})
}
func (s *commentManageSrv) CreateCommentContent(content *core.CommentContent) (*core.CommentContent, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *commentManageSrv) CreateCommentContent(r *ms.CommentContent) (*ms.CommentContent, error) {
res, err := s.q.CreateCommentContent.Exec(r.CommentID, r.UserID, r.Content, r.Type, r.Sort, time.Now().Unix())
if err != nil {
return nil, err
}
id, err := res.LastInsertId()
if err != nil {
return nil, err
}
r.Model = &dbr.Model{ID: id}
return r, nil
}
func (s *commentManageSrv) ThumbsUpComment(userId int64, tweetId, commentId int64) error {
// TODO
return debug.ErrNotImplemented
return s.with(func(tx *sqlx.Tx) error {
var (
thumbsUpCount int32 = 0
thumbsDownCount int32 = 0
)
now := time.Now().Unix()
commentThumbs := &dbr.TweetCommentThumbs{}
// 检查thumbs状态
err := tx.Stmtx(s.q.GetTweetCommentThumb).Get(commentThumbs, userId, tweetId, commentId)
if err == nil {
switch {
case commentThumbs.IsThumbsUp == types.Yes && commentThumbs.IsThumbsDown == types.No:
thumbsUpCount, thumbsDownCount = -1, 0
case commentThumbs.IsThumbsUp == types.No && commentThumbs.IsThumbsDown == types.No:
thumbsUpCount, thumbsDownCount = 1, 0
default:
thumbsUpCount, thumbsDownCount = 1, -1
commentThumbs.IsThumbsDown = types.No
}
commentThumbs.IsThumbsUp = 1 - commentThumbs.IsThumbsUp
commentThumbs.ModifiedOn = now
if _, err := tx.Stmtx(s.q.UpdateThumbsUpdownComment).Exec(commentThumbs); err != nil {
return err
}
} else {
commentThumbs = &dbr.TweetCommentThumbs{
UserID: userId,
TweetID: tweetId,
CommentID: commentId,
IsThumbsUp: types.Yes,
IsThumbsDown: types.No,
CommentType: 0,
Model: &dbr.Model{
CreatedOn: now,
},
}
thumbsUpCount, thumbsDownCount = 1, 0
if _, err := tx.NamedStmt(s.q.CreateThumbsUpdownComment).Exec(commentThumbs); err != nil {
return err
}
}
// 更新comment thumbsUpCount
_, err = tx.Stmtx(s.q.UpdateCommentThumbsCount).Exec(thumbsUpCount, thumbsDownCount, now, commentId)
return err
})
}
func (s *commentManageSrv) ThumbsDownComment(userId int64, tweetId, commentId int64) error {
// TODO
return debug.ErrNotImplemented
return s.with(func(tx *sqlx.Tx) error {
var (
thumbsUpCount int32 = 0
thumbsDownCount int32 = 0
)
now := time.Now().Unix()
commentThumbs := &dbr.TweetCommentThumbs{}
// 检查thumbs状态
err := tx.Stmtx(s.q.GetTweetCommentThumb).Get(commentThumbs, userId, tweetId, commentId)
if err == nil {
switch {
case commentThumbs.IsThumbsDown == types.Yes:
thumbsUpCount, thumbsDownCount = 0, -1
case commentThumbs.IsThumbsDown == types.No && commentThumbs.IsThumbsUp == types.No:
thumbsUpCount, thumbsDownCount = 0, 1
default:
thumbsUpCount, thumbsDownCount = -1, 1
commentThumbs.IsThumbsUp = types.No
}
commentThumbs.IsThumbsDown = 1 - commentThumbs.IsThumbsDown
commentThumbs.ModifiedOn = now
if _, err := tx.NamedStmt(s.q.UpdateThumbsUpdownComment).Exec(commentThumbs); err != nil {
return err
}
} else {
commentThumbs = &dbr.TweetCommentThumbs{
UserID: userId,
TweetID: tweetId,
CommentID: commentId,
IsThumbsUp: types.No,
IsThumbsDown: types.Yes,
CommentType: 0,
Model: &dbr.Model{
CreatedOn: now,
},
}
thumbsUpCount, thumbsDownCount = 0, 1
if _, err := tx.NamedStmt(s.q.CreateThumbsUpdownComment).Exec(commentThumbs); err != nil {
return err
}
}
// 更新comment thumbsUpCount
_, err = tx.Stmtx(s.q.UpdateCommentThumbsCount).Exec(thumbsUpCount, thumbsDownCount, now, commentId)
return err
})
}
func (s *commentManageSrv) ThumbsUpReply(userId int64, tweetId, commentId, replyId int64) error {
// TODO
return debug.ErrNotImplemented
return s.with(func(tx *sqlx.Tx) error {
var (
thumbsUpCount int32 = 0
thumbsDownCount int32 = 0
)
now := time.Now().Unix()
commentThumbs := &dbr.TweetCommentThumbs{}
// 检查thumbs状态
err := tx.Stmtx(s.q.GetCommentReplyThumb).Get(commentThumbs, userId, tweetId, commentId, replyId)
if err == nil {
switch {
case commentThumbs.IsThumbsUp == types.Yes:
thumbsUpCount, thumbsDownCount = -1, 0
case commentThumbs.IsThumbsUp == types.No && commentThumbs.IsThumbsDown == types.No:
thumbsUpCount, thumbsDownCount = 1, 0
default:
thumbsUpCount, thumbsDownCount = 1, -1
commentThumbs.IsThumbsDown = types.No
}
commentThumbs.IsThumbsUp = 1 - commentThumbs.IsThumbsUp
commentThumbs.ModifiedOn = now
if _, err := tx.NamedStmt(s.q.UpdateThumbsUpdownComment).Exec(commentThumbs); err != nil {
return err
}
} else {
commentThumbs = &dbr.TweetCommentThumbs{
UserID: userId,
TweetID: tweetId,
CommentID: commentId,
ReplyID: replyId,
IsThumbsUp: types.Yes,
IsThumbsDown: types.No,
CommentType: 1,
Model: &dbr.Model{
CreatedOn: now,
},
}
thumbsUpCount, thumbsDownCount = 1, 0
if _, err := tx.NamedStmt(s.q.CreateThumbsUpdownComment).Exec(commentThumbs); err != nil {
return err
}
}
// 更新comment_reply thumbsUpCount
_, err = tx.Stmtx(s.q.UpdateReplyThumbsCount).Exec(thumbsUpCount, thumbsDownCount, now, replyId)
return err
})
}
func (s *commentManageSrv) ThumbsDownReply(userId int64, tweetId, commentId, replyId int64) error {
// TODO
return debug.ErrNotImplemented
return s.with(func(tx *sqlx.Tx) error {
var (
thumbsUpCount int32 = 0
thumbsDownCount int32 = 0
)
now := time.Now().Unix()
commentThumbs := &dbr.TweetCommentThumbs{}
// 检查thumbs状态
err := tx.Stmtx(s.q.GetCommentReplyThumb).Get(commentThumbs, userId, tweetId, commentId, replyId)
if err == nil {
switch {
case commentThumbs.IsThumbsDown == types.Yes:
thumbsUpCount, thumbsDownCount = 0, -1
case commentThumbs.IsThumbsUp == types.No && commentThumbs.IsThumbsDown == types.No:
thumbsUpCount, thumbsDownCount = 0, 1
default:
thumbsUpCount, thumbsDownCount = -1, 1
commentThumbs.IsThumbsUp = types.No
}
commentThumbs.IsThumbsDown = 1 - commentThumbs.IsThumbsDown
commentThumbs.ModifiedOn = now
if _, err := tx.NamedStmt(s.q.UpdateThumbsUpdownComment).Exec(commentThumbs); err != nil {
return err
}
} else {
commentThumbs = &dbr.TweetCommentThumbs{
UserID: userId,
TweetID: tweetId,
CommentID: commentId,
ReplyID: replyId,
IsThumbsUp: types.No,
IsThumbsDown: types.Yes,
CommentType: 1,
Model: &dbr.Model{
CreatedOn: now,
},
}
thumbsUpCount, thumbsDownCount = 0, 1
if _, err := tx.NamedStmt(s.q.CreateThumbsUpdownComment).Exec(commentThumbs); err != nil {
return err
}
}
// 更新comment_reply thumbsUpCount
_, err = tx.Stmtx(s.q.UpdateReplyThumbsCount).Exec(thumbsUpCount, thumbsDownCount, now, replyId)
return err
})
}
func newCommentService(db *sqlx.DB) core.CommentService {

@ -5,55 +5,186 @@
package sakila
import (
"time"
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/internal/core/ms"
"github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc"
"github.com/rocboss/paopao-ce/pkg/debug"
"github.com/sirupsen/logrus"
)
var (
_ core.ContactManageService = (*contactManageSrv)(nil)
)
type contact struct {
UserId int64 `db:"user_id" json:"user_id"`
FriendId int64 `db:"friend_id" json:"friend_id"`
Status int8 `json:"status"` // 1请求好友, 2已同意好友, 3已拒绝好友, 4已删除好友
IsBlack int8 `json:"is_black"`
NoticeEnable int8 `json:"notice_enable"`
}
type contactManageSrv struct {
*sqlxSrv
q *cc.ContactManager
}
func (s *contactManageSrv) RequestingFriend(userId int64, friendId int64, greetings string) (err error) {
// TODO
debug.NotImplemented()
return nil
func (s *contactManageSrv) RequestingFriend(userId int64, friendId int64, greetings string) error {
return s.with(func(tx *sqlx.Tx) error {
contact, err := s.fetchOrNewContact(tx, userId, friendId, cs.ContactStatusRequesting)
if err != nil {
return err
}
now := time.Now().Unix()
// 如果已经好友,啥也不干
if contact.Status == cs.ContactStatusAgree {
return nil
} else if contact.Status == cs.ContactStatusReject || contact.Status == cs.ContactStatusDeleted {
contact.Status = cs.ContactStatusRequesting
contact.IsDel = 0 // remove deleted flag if needed
args := []any{cs.ContactStatusRequesting, now, contact.ID}
if _, err = tx.Stmtx(s.q.FreshContactStatus).Exec(args...); err != nil {
return err
}
}
msg := &ms.Message{
SenderUserID: userId,
ReceiverUserID: friendId,
Type: ms.MsgTypeRequestingFriend,
Brief: "请求添加好友,并附言:",
Content: greetings,
ReplyID: int64(cs.ContactStatusRequesting),
Model: &ms.Model{
CreatedOn: now,
},
}
if _, err = tx.NamedStmt(s.q.CreateMessage).Exec(msg); err != nil {
logrus.Errorf("contactManageSrv.RequestingFriend create message err:%s", err)
return err
}
return nil
})
}
func (s *contactManageSrv) AddFriend(userId int64, friendId int64) (err error) {
// TODO
debug.NotImplemented()
return nil
func (s *contactManageSrv) AddFriend(userId int64, friendId int64) error {
return s.with(func(tx *sqlx.Tx) error {
contact := &cs.Contact{}
err := tx.Stmtx(s.q.GetUserFriend).Get(contact, userId, friendId)
if err != nil {
return err
}
// 如果还不是请求好友,啥也不干
if contact.Status != cs.ContactStatusRequesting {
logrus.Debugf("contactManageSrv.AddFriend not reuesting status now so skip")
return nil
}
now := time.Now().Unix()
args := []any{cs.ContactStatusAgree, now, contact.ID}
if _, err = tx.Stmtx(s.q.FreshContactStatus).Exec(args...); err != nil {
return err
}
contact, err = s.fetchOrNewContact(tx, userId, friendId, cs.ContactStatusAgree)
if err != nil {
return err
}
// 如果已经好友,啥也不干
if contact.Status != cs.ContactStatusAgree {
args = []any{cs.ContactStatusAgree, now, contact.ID}
if _, err = tx.Stmtx(s.q.FreshContactStatus).Exec(args); err != nil {
return err
}
}
args = []any{cs.ContactStatusAgree, now, userId, friendId, friendId, userId, ms.MsgTypeRequestingFriend, cs.ContactStatusRequesting}
if _, err = tx.Stmtx(s.q.AddFriendMsgsUpdate).Exec(args...); err != nil {
return err
}
return nil
})
}
func (s *contactManageSrv) RejectFriend(userId int64, friendId int64) (err error) {
// TODO
debug.NotImplemented()
return nil
func (s *contactManageSrv) RejectFriend(userId int64, friendId int64) error {
return s.with(func(tx *sqlx.Tx) error {
contact := &cs.Contact{}
err := tx.Stmtx(s.q.GetUserFriend).Get(contact, userId, friendId)
if err != nil {
return err
}
// 如果还不是请求好友,啥也不干
if contact.Status != cs.ContactStatusRequesting {
return nil
}
now := time.Now().Unix()
args := []any{cs.ContactStatusReject, now, contact.ID}
if _, err = tx.Stmtx(s.q.FreshContactStatus).Exec(args...); err != nil {
return err
}
args = []any{cs.ContactStatusReject, now, friendId, userId, ms.MsgTypeRequestingFriend, cs.ContactStatusRequesting}
if _, err = tx.Stmtx(s.q.RejectFriendMsgsUpdate).Exec(args...); err != nil {
return err
}
return nil
})
}
func (s *contactManageSrv) DeleteFriend(userId int64, friendId int64) (err error) {
// TODO
debug.NotImplemented()
return nil
func (s *contactManageSrv) DeleteFriend(userId int64, friendId int64) error {
return s.with(func(tx *sqlx.Tx) error {
var contacts []cs.Contact
err := tx.Stmtx(s.q.GetContacts).Select(&contacts, userId, friendId, friendId, userId)
if err != nil {
return err
}
for _, contact := range contacts {
// 如果还不是好友,啥也不干
if contact.Status != cs.ContactStatusAgree {
continue
}
if _, err = tx.Stmtx(s.q.DelFriend).Exec(time.Now().Unix(), contact.ID); err != nil {
return err
}
}
return nil
})
}
func (s *contactManageSrv) GetContacts(userId int64, offset int, limit int) (*core.ContactList, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *contactManageSrv) GetContacts(userId int64, offset int, limit int) (res *ms.ContactList, err error) {
res = &ms.ContactList{
Contacts: []ms.ContactItem{},
}
if err = s.q.ListFriend.Select(&res.Contacts, userId, limit, offset); err != nil {
return
}
if err = s.q.TotalFriendsById.Get(&res.Total, userId); err != nil {
return
}
return
}
func (s *contactManageSrv) IsFriend(userId int64, friendId int64) bool {
// TODO
debug.NotImplemented()
return false
func (s *contactManageSrv) IsFriend(userId int64, friendId int64) (res bool) {
s.q.IsFriend.Get(&res, userId, friendId)
return
}
func (s *contactManageSrv) fetchOrNewContact(tx *sqlx.Tx, userId int64, friendId int64, status int8) (res *cs.Contact, err error) {
if err = tx.Stmtx(s.q.GetContact).Get(res, userId, friendId); err == nil {
return
}
result, xerr := tx.Stmtx(s.q.CreateContact).Exec(userId, friendId, status, time.Now().Unix())
if xerr != nil {
return nil, xerr
}
id, xerr := result.LastInsertId()
if xerr != nil {
return nil, xerr
}
return &cs.Contact{
ID: id,
UserId: userId,
FriendId: friendId,
Status: status,
}, nil
}
func newContactManageService(db *sqlx.DB) core.ContactManageService {

@ -5,10 +5,13 @@
package sakila
import (
"time"
"github.com/jmoiron/sqlx"
"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/pkg/debug"
)
var (
@ -20,40 +23,53 @@ type messageSrv struct {
q *cc.Message
}
func (s *messageSrv) CreateMessage(msg *core.Message) (*core.Message, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *messageSrv) CreateMessage(r *ms.Message) (*ms.Message, error) {
r.Model = &dbr.Model{
CreatedOn: time.Now().Unix(),
}
res, err := s.q.CreateMessage.Exec(r)
if err != nil {
return nil, err
}
r.ID, err = res.LastInsertId()
if err != nil {
return nil, err
}
return r, nil
}
func (s *messageSrv) GetUnreadCount(userID int64) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
func (s *messageSrv) GetUnreadCount(userID int64) (res int64, err error) {
err = s.q.GetUnreadCount.Get(&res)
return
}
func (s *messageSrv) GetMessageByID(id int64) (*core.Message, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *messageSrv) GetMessageByID(id int64) (res *ms.Message, err error) {
err = s.q.GetMessageById.Get(res, id)
return
}
func (s *messageSrv) ReadMessage(message *core.Message) error {
// TODO
debug.NotImplemented()
return nil
func (s *messageSrv) ReadMessage(r *ms.Message) (err error) {
_, err = s.q.ReadMessage.Exec(time.Now().Unix(), r.ID)
return
}
func (s *messageSrv) GetMessages(conditions *core.ConditionsT, offset, limit int) ([]*core.MessageFormated, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *messageSrv) GetMessages(r *ms.ConditionsT, offset, limit int) ([]*ms.MessageFormated, error) {
var messages []*ms.Message
(*r)["limit"], (*r)["offset"] = limit, offset
if err := s.q.GetMessages.Select(&messages, r); err != nil {
return nil, err
}
mfs := make([]*dbr.MessageFormated, 0, len(messages))
for _, message := range messages {
mf := message.Format()
mfs = append(mfs, mf)
}
return mfs, nil
}
func (s *messageSrv) GetMessageCount(conditions *core.ConditionsT) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
func (s *messageSrv) GetMessageCount(r *ms.ConditionsT) (res int64, err error) {
err = s.q.GetMessageCount.Get(&res, r)
return
}
func newMessageService(db *sqlx.DB) core.MessageService {

@ -5,10 +5,15 @@
package sakila
import (
"math/rand"
"strconv"
"time"
"github.com/jmoiron/sqlx"
"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/pkg/debug"
)
var (
@ -17,33 +22,49 @@ var (
type securitySrv struct {
*sqlxSrv
q *cc.Security
q *cc.Security
rand *rand.Rand
phoneVerify core.PhoneVerifyService
}
// GetLatestPhoneCaptcha 获取最新短信验证码
func (s *securitySrv) GetLatestPhoneCaptcha(phone string) (*core.Captcha, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *securitySrv) GetLatestPhoneCaptcha(phone string) (res *ms.Captcha, err error) {
err = s.q.GetLatestPhoneCaptcha.Get(res, phone)
return
}
// UsePhoneCaptcha 更新短信验证码
func (s *securitySrv) UsePhoneCaptcha(captcha *core.Captcha) error {
// TODO
debug.NotImplemented()
return nil
func (s *securitySrv) UsePhoneCaptcha(r *ms.Captcha) error {
_, err := s.q.UsePhoneCaptcha.Exec(time.Now().Unix(), r.ID)
return err
}
// SendPhoneCaptcha 发送短信验证码
func (s *securitySrv) SendPhoneCaptcha(phone string) error {
// TODO
debug.NotImplemented()
return nil
expire := time.Duration(5)
// 发送验证码
captcha := strconv.Itoa(s.rand.Intn(900000) + 100000)
if err := s.phoneVerify.SendPhoneCaptcha(phone, captcha, expire); err != nil {
return err
}
// 写入表
phoneCaptcha := &dbr.Captcha{
Model: &ms.Model{
CreatedOn: time.Now().Unix(),
},
Phone: phone,
Captcha: captcha,
ExpiredOn: time.Now().Add(expire * time.Minute).Unix(),
}
_, err := s.q.CreatePhoneCaptcha.Exec(phoneCaptcha)
return err
}
func newSecurityService(db *sqlx.DB, phoneVerify core.PhoneVerifyService) core.SecurityService {
return &securitySrv{
sqlxSrv: newSqlxSrv(db),
q: mustBuild(db, cc.BuildSecurity),
sqlxSrv: newSqlxSrv(db),
q: mustBuild(db, cc.BuildSecurity),
rand: rand.New(rand.NewSource(time.Now().UnixNano())),
phoneVerify: phoneVerify,
}
}

@ -13,6 +13,7 @@ import (
"github.com/alimy/yesql"
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/conf"
"github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc"
"github.com/sirupsen/logrus"
)
@ -23,6 +24,7 @@ var (
type sqlxSrv struct {
db *sqlx.DB
y *cc.Yesql
}
func (s *sqlxSrv) with(handle func(tx *sqlx.Tx) error) error {
@ -57,7 +59,32 @@ func (s *sqlxSrv) in(query string, args ...any) (string, []any, error) {
return s.db.Rebind(q), params, nil
}
func (s *sqlxSrv) inExec(execer sqlx.Execer, query string, args ...any) (sql.Result, error) {
func (s *sqlxSrv) inExec(query string, args ...any) (sql.Result, error) {
q, params, err := sqlx.In(query, args...)
if err != nil {
return nil, err
}
return s.db.Exec(s.db.Rebind(q), params...)
}
func (s *sqlxSrv) inSelect(dest any, query string, args ...any) error {
q, params, err := sqlx.In(query, args...)
if err != nil {
return err
}
return sqlx.Select(s.db, dest, s.db.Rebind(q), params...)
}
func (s *sqlxSrv) inGet(dest any, query string, args ...any) error {
q, params, err := sqlx.In(query, args...)
if err != nil {
return err
}
return sqlx.Get(s.db, dest, s.db.Rebind(q), params...)
}
// inExecx execute for in clause with Transcation
func (s *sqlxSrv) inExecx(execer sqlx.Execer, query string, args ...any) (sql.Result, error) {
q, params, err := sqlx.In(query, args...)
if err != nil {
return nil, err
@ -65,7 +92,8 @@ func (s *sqlxSrv) inExec(execer sqlx.Execer, query string, args ...any) (sql.Res
return execer.Exec(s.db.Rebind(q), params...)
}
func (s *sqlxSrv) inSelect(queryer sqlx.Queryer, dest any, query string, args ...any) error {
// inSelectx select for in clause with Transcation
func (s *sqlxSrv) inSelectx(queryer sqlx.Queryer, dest any, query string, args ...any) error {
q, params, err := sqlx.In(query, args...)
if err != nil {
return err
@ -73,7 +101,8 @@ func (s *sqlxSrv) inSelect(queryer sqlx.Queryer, dest any, query string, args ..
return sqlx.Select(queryer, dest, s.db.Rebind(q), params...)
}
func (s *sqlxSrv) inGet(queryer sqlx.Queryer, dest any, query string, args ...any) error {
// inGetx get for in clause with Transcation
func (s *sqlxSrv) inGetx(queryer sqlx.Queryer, dest any, query string, args ...any) error {
q, params, err := sqlx.In(query, args...)
if err != nil {
return err
@ -84,6 +113,7 @@ func (s *sqlxSrv) inGet(queryer sqlx.Queryer, dest any, query string, args ...an
func newSqlxSrv(db *sqlx.DB) *sqlxSrv {
return &sqlxSrv{
db: db,
y: mustBuild(db, cc.BuildYesql),
}
}
@ -151,6 +181,15 @@ func mustBuild[T any](db *sqlx.DB, fn func(yesql.PreparexBuilder, ...context.Con
return obj
}
func mustBuildFn[T any](db *sqlx.DB, fn func(yesql.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 initSqlxDB() {
_db = conf.MustSqlxDB()
_tablePrefix = conf.DatabaseSetting.TablePrefix

@ -8,6 +8,7 @@ import (
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/internal/core/ms"
"github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc"
"github.com/rocboss/paopao-ce/pkg/debug"
)
@ -75,49 +76,49 @@ type simpleIndexPostsSrvA struct {
}
// IndexPosts 根据userId查询广场推文列表简单做到不同用户的主页都是不同的
func (s *friendIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
func (s *friendIndexSrv) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
// IndexPosts 根据userId查询广场推文列表简单做到不同用户的主页都是不同的
func (s *followIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
func (s *followIndexSrv) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
// IndexPosts 根据userId查询广场推文列表简单做到不同用户的主页都是不同的
func (s *lightIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
func (s *lightIndexSrv) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
// simpleCacheIndexGetPosts simpleCacheIndex 专属获取广场推文列表函数
func (s *simpleIndexPostsSrv) IndexPosts(_user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
func (s *simpleIndexPostsSrv) IndexPosts(_user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
// IndexPosts 根据userId查询广场推文列表简单做到不同用户的主页都是不同的
func (s *friendIndexSrvA) IndexPosts(user *core.User, limit int, offset int) (*cs.TweetBox, error) {
func (s *friendIndexSrvA) IndexPosts(user *ms.User, limit int, offset int) (*cs.TweetBox, error) {
// TODO
return nil, debug.ErrNotImplemented
}
// IndexPosts 根据userId查询广场推文列表简单做到不同用户的主页都是不同的
func (s *followIndexSrvA) IndexPosts(user *core.User, limit int, offset int) (*cs.TweetBox, error) {
func (s *followIndexSrvA) IndexPosts(user *ms.User, limit int, offset int) (*cs.TweetBox, error) {
// TODO
return nil, debug.ErrNotImplemented
}
// IndexPosts 根据userId查询广场推文列表简单做到不同用户的主页都是不同的
func (s *lightIndexSrvA) IndexPosts(user *core.User, limit int, offset int) (*cs.TweetBox, error) {
func (s *lightIndexSrvA) IndexPosts(user *ms.User, limit int, offset int) (*cs.TweetBox, error) {
// TODO
return nil, debug.ErrNotImplemented
}
// IndexPosts simpleCacheIndex 专属获取广场推文列表函数
func (s *simpleIndexPostsSrvA) IndexPosts(_user *core.User, limit int, offset int) (*cs.TweetBox, error) {
func (s *simpleIndexPostsSrvA) IndexPosts(_user *ms.User, limit int, offset int) (*cs.TweetBox, error) {
// TODO
return nil, debug.ErrNotImplemented
}

@ -31,7 +31,7 @@ func (s *topicSrvA) UpsertTags(userId int64, tags []string) (res cs.TagInfoList,
}
xerr = s.with(func(tx *sqlx.Tx) error {
var upTags cs.TagInfoList
if err := s.inSelect(tx, &upTags, s.q.TagsForIncr, tags); err != nil {
if err := s.inSelectx(tx, &upTags, s.q.TagsForIncr, tags); err != nil {
return err
}
now := time.Now().Unix()
@ -51,7 +51,7 @@ func (s *topicSrvA) UpsertTags(userId int64, tags []string) (res cs.TagInfoList,
}
}
}
if _, err := s.inExec(tx, s.q.IncrTagsById, now, ids); err != nil {
if _, err := s.inExecx(tx, s.q.IncrTagsById, now, ids); err != nil {
return err
}
res = append(res, upTags...)
@ -73,7 +73,7 @@ func (s *topicSrvA) UpsertTags(userId int64, tags []string) (res cs.TagInfoList,
ids = append(ids, id)
}
var newTags cs.TagInfoList
if err := s.inSelect(tx, &newTags, s.q.TagsByIdB, ids); err != nil {
if err := s.inSelectx(tx, &newTags, s.q.TagsByIdB, ids); err != nil {
return err
}
res = append(res, newTags...)
@ -85,11 +85,11 @@ func (s *topicSrvA) UpsertTags(userId int64, tags []string) (res cs.TagInfoList,
func (s *topicSrvA) DecrTagsById(ids []int64) error {
return s.with(func(tx *sqlx.Tx) error {
var ids []int64
err := s.inSelect(tx, &ids, s.q.TagsByIdA, ids)
err := s.inSelectx(tx, &ids, s.q.TagsByIdA, ids)
if err != nil {
return err
}
_, err = s.inExec(tx, s.q.DecrTagsById, time.Now().Unix(), ids)
_, err = s.inExecx(tx, s.q.DecrTagsById, time.Now().Unix(), ids)
return err
})
}

@ -5,9 +5,13 @@
package sakila
import (
"strings"
"time"
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/internal/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"
@ -56,224 +60,400 @@ type tweetHelpSrvA struct {
}
// MergePosts post数据整合
func (s *tweetHelpSrv) MergePosts(posts []*core.Post) ([]*core.PostFormated, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *tweetHelpSrv) MergePosts(posts []*ms.Post) ([]*ms.PostFormated, error) {
postIds := make([]int64, 0, len(posts))
userIds := make([]int64, 0, len(posts))
for _, post := range posts {
postIds = append(postIds, post.ID)
userIds = append(userIds, post.UserID)
}
postContents, err := s.getPostContentsByIDs(postIds)
if err != nil {
return nil, err
}
users, err := s.getUsersByIDs(userIds)
if err != nil {
return nil, err
}
userMap := make(map[int64]*dbr.UserFormated, len(users))
for _, user := range users {
userMap[user.ID] = user
}
contentMap := make(map[int64][]*dbr.PostContentFormated, len(postContents))
for _, content := range postContents {
contentMap[content.PostID] = append(contentMap[content.PostID], content)
}
// 数据整合
postsFormated := make([]*dbr.PostFormated, 0, len(posts))
for _, post := range posts {
postFormated := post.Format()
postFormated.User = userMap[post.UserID]
postFormated.Contents = contentMap[post.ID]
postsFormated = append(postsFormated, postFormated)
}
return postsFormated, nil
}
// RevampPosts post数据整形修复
func (s *tweetHelpSrv) RevampPosts(posts []*core.PostFormated) ([]*core.PostFormated, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetHelpSrv) getPostContentsByIDs(ids []int64) ([]*dbr.PostContent, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetHelpSrv) getUsersByIDs(ids []int64) ([]*dbr.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetManageSrv) CreatePostCollection(postID, userID int64) (*core.PostCollection, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *tweetHelpSrv) RevampPosts(posts []*ms.PostFormated) ([]*ms.PostFormated, error) {
postIds := make([]int64, 0, len(posts))
userIds := make([]int64, 0, len(posts))
for _, post := range posts {
postIds = append(postIds, post.ID)
userIds = append(userIds, post.UserID)
}
postContents, err := s.getPostContentsByIDs(postIds)
if err != nil {
return nil, err
}
users, err := s.getUsersByIDs(userIds)
if err != nil {
return nil, err
}
userMap := make(map[int64]*dbr.UserFormated, len(users))
for _, user := range users {
userMap[user.ID] = user
}
contentMap := make(map[int64][]*dbr.PostContentFormated, len(postContents))
for _, content := range postContents {
contentMap[content.PostID] = append(contentMap[content.PostID], content)
}
// 数据整合
for _, post := range posts {
post.User = userMap[post.UserID]
post.Contents = contentMap[post.ID]
}
return posts, nil
}
func (s *tweetManageSrv) DeletePostCollection(p *core.PostCollection) error {
// TODO
debug.NotImplemented()
return nil
func (s *tweetHelpSrv) getPostContentsByIDs(ids []int64) (res []*dbr.PostContentFormated, err error) {
err = s.inSelect(&res, s.q.GetPostContentByIds, ids)
return
}
func (s *tweetManageSrv) CreatePostContent(content *core.PostContent) (*core.PostContent, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *tweetHelpSrv) getUsersByIDs(ids []int64) (res []*dbr.UserFormated, err error) {
err = s.inSelect(&res, s.q.GetUsersByIds, ids)
return
}
func (s *tweetManageSrv) CreateAttachment(obj *cs.Attachment) (int64, error) {
// TODO
return 0, debug.ErrNotImplemented
func (s *tweetManageSrv) CreatePostCollection(postID, userID int64) (*ms.PostCollection, error) {
now := time.Now().Unix()
res, err := s.q.AddPostCollection.Exec(postID, userID, now)
if err != nil {
return nil, err
}
id, err := res.LastInsertId()
if err != nil {
return nil, err
}
return &ms.PostCollection{
Model: &dbr.Model{
ID: id,
CreatedOn: now,
},
PostID: postID,
UserID: userID,
}, nil
}
func (s *tweetManageSrv) DeletePostCollection(r *ms.PostCollection) error {
_, err := s.q.DelPostCollection.Exec(time.Now().Unix(), r.ID)
return err
}
func (s *tweetManageSrv) CreatePostContent(r *ms.PostContent) (*ms.PostContent, error) {
r.Model = &ms.Model{CreatedOn: time.Now().Unix()}
res, err := s.q.AddPostContent.Exec(r)
if err != nil {
return nil, err
}
r.ID, err = res.LastInsertId()
if err != nil {
return nil, err
}
return r, nil
}
func (s *tweetManageSrv) CreatePost(post *core.Post) (*core.Post, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *tweetManageSrv) CreateAttachment(r *ms.Attachment) (int64, error) {
args := []any{r.UserID, r.FileSize, r.ImgWidth, r.ImgHeight, r.Type, r.Content, time.Now().Unix()}
res, err := s.q.AddAttachment.Exec(args...)
if err != nil {
return 0, err
}
return res.LastInsertId()
}
func (s *tweetManageSrv) DeletePost(post *core.Post) ([]string, error) {
func (s *tweetManageSrv) CreatePost(r *ms.Post) (*ms.Post, error) {
now := time.Now().Unix()
r.Model = &dbr.Model{CreatedOn: now}
r.LatestRepliedOn = now
res, err := s.q.AddPost.Exec(r)
if err != nil {
return nil, err
}
if r.ID, err = res.LastInsertId(); err != nil {
return nil, err
}
s.cis.SendAction(core.IdxActCreatePost, r)
return r, nil
}
func (s *tweetManageSrv) DeletePost(post *ms.Post) (mediaContents []string, err error) {
s.with(func(tx *sqlx.Tx) error {
// 获取多媒体内容
if err = tx.Stmtx(s.q.MediaContentByPostId).Get(&mediaContents, post.ID); err != nil {
return err
}
// 删推文
now := time.Now().Unix()
if _, err = tx.Stmtx(s.q.DelPostById).Exec(now, post.ID); err != nil {
return err
}
// 删评论
contents, err := s.deleteCommentByPostId(tx, post.ID)
if err != nil {
return err
}
mediaContents = append(mediaContents, contents...)
if tags := strings.Split(post.Tags, ","); len(tags) > 0 {
// 删tag宽松处理错误有错误不会回滚
s.deleteTags(tx, tags)
}
return nil
})
s.cis.SendAction(core.IdxActDeletePost, post)
return
}
func (s *tweetManageSrv) deleteCommentByPostId(tx *sqlx.Tx, postId int64) ([]string, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetManageSrv) LockPost(post *core.Post) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *tweetManageSrv) StickPost(post *core.Post) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *tweetManageSrv) VisiblePost(post *core.Post, visibility core.PostVisibleT) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *tweetManageSrv) UpdatePost(post *core.Post) error {
// TODO
debug.NotImplemented()
return nil
func (s *tweetManageSrv) LockPost(r *ms.Post) error {
_, err := s.q.LockPost.Exec(time.Now().Unix(), r.ID)
return err
}
func (s *tweetManageSrv) CreatePostStar(postID, userID int64) (*core.PostStar, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *tweetManageSrv) StickPost(r *ms.Post) error {
_, err := s.q.StickPost.Exec(time.Now().Unix(), r.ID)
return err
}
func (s *tweetManageSrv) DeletePostStar(p *core.PostStar) error {
// TODO
debug.NotImplemented()
func (s *tweetManageSrv) VisiblePost(post *ms.Post, visibility core.PostVisibleT) (err error) {
oldVisibility := post.Visibility
post.Visibility = visibility
// TODO: 这个判断是否可以不要呢
if oldVisibility == visibility {
return nil
}
// 私密推文 特殊处理
if visibility == ms.PostVisitPrivate {
// 强制取消置顶
// TODO: 置顶推文用户是否有权设置成私密? 后续完善
post.IsTop = 0
}
s.with(func(tx *sqlx.Tx) error {
_, err = s.q.VisiblePost.Exec(visibility, post.IsTop, time.Now().Unix(), post.ID)
// tag处理
tags := strings.Split(post.Tags, ",")
// TODO: 暂时宽松不处理错误,这里或许可以有优化,后续完善
if oldVisibility == dbr.PostVisitPrivate {
// 从私密转为非私密才需要重新创建tag
s.createTags(tx, post.UserID, tags)
} else if visibility == dbr.PostVisitPrivate {
// 从非私密转为私密才需要删除tag
s.deleteTags(tx, tags)
}
return nil
})
s.cis.SendAction(core.IdxActVisiblePost, post)
return
}
func (s *tweetManageSrv) UpdatePost(r *ms.Post) error {
r.ModifiedOn = time.Now().Unix()
if _, err := s.q.UpdatePost.Exec(r); err != nil {
return err
}
s.cis.SendAction(core.IdxActUpdatePost, r)
return nil
}
func (s *tweetSrv) GetPostByID(id int64) (*core.Post, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *tweetManageSrv) CreatePostStar(postID, userID int64) (*ms.PostStar, error) {
now := time.Now().Unix()
res, err := s.q.AddPostStar.Exec(postID, userID, now)
if err != nil {
return nil, err
}
id, err := res.LastInsertId()
if err != nil {
return nil, err
}
return &ms.PostStar{
Model: &dbr.Model{
ID: id,
CreatedOn: now,
},
PostID: postID,
UserID: userID,
}, nil
}
func (s *tweetSrv) GetPosts(conditions *core.ConditionsT, offset, limit int) ([]*core.Post, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *tweetManageSrv) DeletePostStar(r *ms.PostStar) error {
_, err := s.q.DelPostStar.Exec(time.Now().Unix(), r.ID)
return err
}
func (s *tweetSrv) GetPostCount(conditions *core.ConditionsT) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
func (s *tweetSrv) GetPostByID(id int64) (res *ms.Post, err error) {
err = s.q.GetPostById.Get(res, id)
return
}
func (s *tweetSrv) GetUserPostStar(postID, userID int64) (*core.PostStar, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *tweetSrv) GetPosts(c ms.ConditionsT, offset, limit int) (res []*ms.Post, err error) {
userId, exist := c["user_id"]
visibility := c["visibility IN ?"]
if exist {
err = s.inSelect(&res, s.q.GetUserPosts, userId, visibility, limit, offset)
} else {
err = s.inSelect(&res, s.q.GetAnyPosts, visibility, limit, offset)
}
return
}
func (s *tweetSrv) GetUserPostStars(userID int64, offset, limit int) ([]*core.PostStar, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *tweetSrv) GetPostCount(c ms.ConditionsT) (res int64, err error) {
userId, exist := c["user_id"]
visibility := c["visibility IN ?"]
if exist {
err = s.inGet(&res, s.q.GetUserPostCount, userId, visibility)
} else {
err = s.inGet(&res, s.q.GetAnyPostCount, visibility)
}
return
}
func (s *tweetSrv) GetUserPostStarCount(userID int64) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
func (s *tweetSrv) GetUserPostStar(postID, userID int64) (*ms.PostStar, error) {
res := &ms.PostStar{}
err := s.q.GetUserPostStar.Get(res, postID, userID)
return res, err
}
func (s *tweetSrv) GetUserPostCollection(postID, userID int64) (*core.PostCollection, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *tweetSrv) GetUserPostStars(userID int64, offset, limit int) ([]*ms.PostStar, error) {
res := []*ms.PostStar{}
err := s.q.GetUserPostStar.Select(&res, userID, limit, offset)
return res, err
}
func (s *tweetSrv) GetUserPostCollections(userID int64, offset, limit int) ([]*core.PostCollection, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *tweetSrv) GetUserPostStarCount(userID int64) (res int64, err error) {
err = s.q.GetUserPostStarCount.Get(&res, userID)
return
}
func (s *tweetSrv) GetUserPostCollectionCount(userID int64) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
func (s *tweetSrv) GetUserPostCollection(postID, userID int64) (*ms.PostCollection, error) {
res := &ms.PostCollection{}
err := s.q.GetUserPostCollection.Get(res, postID, userID)
return res, err
}
func (s *tweetSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *tweetSrv) GetUserPostCollections(userID int64, offset, limit int) ([]*ms.PostCollection, error) {
res := []*ms.PostCollection{}
err := s.q.GetUserPostCollections.Select(&res, userID, limit, offset)
return res, err
}
func (s *tweetSrv) GetUserWalletBillCount(userID int64) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
func (s *tweetSrv) GetUserPostCollectionCount(userID int64) (res int64, err error) {
err = s.q.GetUserPostCollectionCount.Get(&res)
return
}
func (s *tweetSrv) GetPostAttatchmentBill(postID, userID int64) (*core.PostAttachmentBill, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *tweetSrv) GetPostAttatchmentBill(postID, userID int64) (*ms.PostAttachmentBill, error) {
res := &ms.PostAttachmentBill{}
err := s.q.GetPostAttachmentBill.Get(res, postID, userID)
return res, err
}
func (s *tweetSrv) GetPostContentsByIDs(ids []int64) ([]*core.PostContent, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *tweetSrv) GetPostContentsByIDs(ids []int64) (res []*ms.PostContent, err error) {
err = s.inSelect(&res, s.q.GetPostContentsByIds, ids)
return
}
func (s *tweetSrv) GetPostContentByID(id int64) (*core.PostContent, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *tweetSrv) GetPostContentByID(id int64) (*ms.PostContent, error) {
res := &ms.PostContent{}
err := s.q.GetPostContentById.Get(res, id)
return res, err
}
func (s *tweetSrvA) TweetInfoById(id int64) (*cs.TweetInfo, error) {
// TODO
return nil, debug.ErrNotImplemented
res := &cs.TweetInfo{}
err := s.q.TweetInfoById.Get(res, id)
return res, err
}
func (s *tweetSrvA) TweetItemById(id int64) (*cs.TweetItem, error) {
// TODO
return nil, debug.ErrNotImplemented
res := &cs.TweetItem{}
err := s.q.TweetItemById.Get(res, id)
if err != nil {
return nil, err
}
// TODO need add contents info to res
return res, nil
}
func (s *tweetSrvA) UserTweets(visitorId, userId int64) (res cs.TweetList, err error) {
res = cs.TweetList{}
switch s.checkRelationBy(visitorId, userId) {
case 0: // admin
err = s.q.UserTweetsByAdmin.Select(&res, userId)
case 1: // self
err = s.q.UserTweetsBySelf.Select(&res, userId)
case 2: // friend
err = s.q.UserTweetsByFriend.Select(&res, userId)
case 3: // follower
fallthrough
default: // guest
err = s.q.UserTweetsByGuest.Select(&res, userId)
}
if err != nil {
return nil, err
}
// TODO need add contents info to res
return res, nil
}
func (s *tweetSrvA) UserTweets(visitorId, userId int64) (cs.TweetList, error) {
// checkRelationBy check the relation of visitor with user
func (s *tweetSrvA) checkRelationBy(visitorId, userId int64) uint {
// TODO
return nil, debug.ErrNotImplemented
return 0
}
func (s *tweetSrvA) ReactionByTweetId(userId int64, tweetId int64) (*cs.ReactionItem, error) {
// TODO
return nil, debug.ErrNotImplemented
res := &cs.ReactionItem{}
err := s.q.ReactionByTweetId.Get(res, userId, tweetId)
return res, err
}
func (s *tweetSrvA) UserReactions(userId int64, limit int, offset int) (cs.ReactionList, error) {
// TODO
return nil, debug.ErrNotImplemented
res := cs.ReactionList{}
err := s.q.UserReactions.Select(&res, userId)
return res, err
}
func (s *tweetSrvA) FavoriteByTweetId(userId int64, tweetId int64) (*cs.FavoriteItem, error) {
// TODO
return nil, debug.ErrNotImplemented
res := &cs.FavoriteItem{}
err := s.q.FavoriteByTweetId.Get(res, userId, tweetId)
return res, err
}
func (s *tweetSrvA) UserFavorites(userId int64, limit int, offset int) (cs.FavoriteList, error) {
// TODO
return nil, debug.ErrNotImplemented
res := cs.FavoriteList{}
err := s.q.UserFavorites.Select(&res, userId)
return res, err
}
func (s *tweetSrvA) AttachmentByTweetId(userId int64, tweetId int64) (*cs.AttachmentBill, error) {
// TODO
return nil, debug.ErrNotImplemented
res := &cs.AttachmentBill{}
err := s.q.AttachmentByTweetId.Get(res, userId, tweetId)
return res, err
}
func (s *tweetManageSrvA) CreateAttachment(obj *cs.Attachment) (int64, error) {
@ -354,7 +534,7 @@ func newTweetManageService(db *sqlx.DB, cacheIndex core.CacheIndexService) core.
func newTweetHelpService(db *sqlx.DB) core.TweetHelpService {
return &tweetHelpSrv{
sqlxSrv: newSqlxSrv(db),
q: mustBuild(db, cc.BuildTweetHelp),
q: mustBuildFn(db, cc.BuildTweetHelp),
}
}

@ -5,10 +5,13 @@
package sakila
import (
"strings"
"time"
"github.com/jmoiron/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/pkg/debug"
)
var (
@ -20,46 +23,51 @@ type userManageSrv struct {
q *cc.UserManage
}
func (s *userManageSrv) GetUserByID(id int64) (*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *userManageSrv) GetUserByID(id int64) (res *ms.User, err error) {
err = s.q.GetUserById.Get(res, id)
return
}
func (s *userManageSrv) GetUserByUsername(username string) (*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *userManageSrv) GetUserByUsername(username string) (res *ms.User, err error) {
err = s.q.GetUserByUsername.Get(res, username)
return
}
func (s *userManageSrv) GetUserByPhone(phone string) (*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *userManageSrv) GetUserByPhone(phone string) (res *ms.User, err error) {
err = s.q.GetUserByPhone.Get(res, phone)
return
}
func (s *userManageSrv) GetUsersByIDs(ids []int64) ([]*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *userManageSrv) GetUsersByIDs(ids []int64) (res []*ms.User, err error) {
err = s.inSelect(&res, s.q.GetUsersByIds, ids)
return
}
func (s *userManageSrv) GetUsersByKeyword(keyword string) ([]*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *userManageSrv) GetUsersByKeyword(keyword string) (res []*ms.User, err error) {
keyword = strings.Trim(keyword, " ") + "%"
if keyword == "%" {
err = s.q.GetAnyUsers.Get(&res)
} else {
err = s.q.GetUsersByKeyword.Select(&res, keyword)
}
return
}
func (s *userManageSrv) CreateUser(user *core.User) (*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *userManageSrv) CreateUser(r *ms.User) (*ms.User, error) {
r.Model = &ms.Model{
CreatedOn: time.Now().Unix(),
}
res, err := s.q.CreateUser.Exec(r)
if err != nil {
return nil, err
}
r.ID, err = res.LastInsertId()
return r, err
}
func (s *userManageSrv) UpdateUser(user *core.User) error {
// TODO
debug.NotImplemented()
return nil
func (s *userManageSrv) UpdateUser(r *ms.User) error {
_, err := s.q.UpdateUser.Exec(r)
return err
}
func newUserManageService(db *sqlx.DB) core.UserManageService {

@ -0,0 +1,55 @@
// 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 (
"time"
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/core/cs"
)
func (s *sqlxSrv) deleteTags(tx *sqlx.Tx, tags []string) (err error) {
var tagInfos []cs.TagInfo
if err = tx.Stmtx(s.y.TagsFromNames).Select(&tagInfos, tags); err != nil {
return
}
now := time.Now().Unix()
for _, tag := range tagInfos {
tag.QuoteNum--
if _, err = tx.Stmtx(s.y.UpdateTagQuote).Exec(tag.QuoteNum, now, tag.ID); err != nil {
return
}
}
return
}
func (s *sqlxSrv) createTags(tx *sqlx.Tx, userId int64, tags []string) (res cs.TagInfoList, err error) {
// for _, name := range tags {
// tag := &dbr.Tag{Tag: name}
// if tag, err = tag.Get(db); err == nil {
// // 更新
// tag.QuoteNum++
// if err = tag.Update(db); err != nil {
// return
// }
// } else {
// if tag, err = (&dbr.Tag{
// UserID: userId,
// QuoteNum: 1,
// Tag: name,
// }).Create(db); err != nil {
// return
// }
// }
// res = append(res, &cs.TagInfo{
// ID: tag.ID,
// UserID: tag.UserID,
// Tag: tag.Tag,
// QuoteNum: tag.QuoteNum,
// })
// }
return
}

@ -5,10 +5,14 @@
package sakila
import (
"time"
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/conf"
"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/pkg/debug"
)
var (
@ -20,39 +24,103 @@ type walletSrv struct {
q *cc.Wallet
}
func (s *walletSrv) GetRechargeByID(id int64) (*core.WalletRecharge, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *walletSrv) GetRechargeByID(id int64) (res *ms.WalletRecharge, err error) {
err = s.q.GetRechargeById.Get(res, id)
return
}
func (s *walletSrv) CreateRecharge(userId, amount int64) (*core.WalletRecharge, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *walletSrv) CreateRecharge(userId, amount int64) (*ms.WalletRecharge, error) {
now := time.Now().Unix()
res, err := s.q.CreateRecharge.Exec(userId, amount, now)
if err != nil {
return nil, err
}
id, err := res.LastInsertId()
if err != nil {
return nil, err
}
return &ms.WalletRecharge{
Model: &dbr.Model{
ID: id,
CreatedOn: now,
},
UserID: userId,
Amount: amount,
}, nil
}
func (s *walletSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) {
// TODO
debug.NotImplemented()
return nil, nil
func (s *walletSrv) GetUserWalletBills(userID int64, offset, limit int) (res []*ms.WalletStatement, err error) {
err = s.q.GetUserWalletBills.Select(&res, userID, limit, offset)
return
}
func (s *walletSrv) GetUserWalletBillCount(userID int64) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
func (s *walletSrv) GetUserWalletBillCount(userID int64) (res int64, err error) {
err = s.q.GetUserWalletBillCount.Get(&res, userID)
return
}
func (s *walletSrv) HandleRechargeSuccess(recharge *core.WalletRecharge, tradeNo string) error {
// TODO
debug.NotImplemented()
return nil
func (s *walletSrv) HandleRechargeSuccess(r *ms.WalletRecharge, tradeNo string) error {
return s.with(func(tx *sqlx.Tx) error {
var oldBalance int64
// 获取当前金额
err := tx.Stmtx(s.q.GetUserBalance).Get(&oldBalance, r.UserID)
if err != nil {
return err
}
now := time.Now().Unix()
// 更新金额
if _, err := tx.Stmtx(s.q.AddUserBalance).Exec(r.Amount, now, r.UserID); err != nil {
return err
}
// 新增账单
args := []any{r.UserID, r.Amount, oldBalance + r.Amount, "用户充值", now}
if _, err = tx.Stmtx(s.q.CreateWalletStatement).Exec(args...); err != nil {
return err
}
// 标记为已付款
if _, err = tx.Stmtx(s.q.MarkSuccessRecharge).Exec(tradeNo, now, r.ID); err != nil {
return err
}
return nil
})
}
func (s *walletSrv) HandlePostAttachmentBought(post *core.Post, user *core.User) error {
// TODO
debug.NotImplemented()
return nil
func (s *walletSrv) HandlePostAttachmentBought(post *ms.Post, user *ms.User) error {
return s.with(func(tx *sqlx.Tx) error {
now := time.Now().Unix()
// 扣除金额
_, err := tx.Stmtx(s.q.MinusUserBalance).Exec(post.AttachmentPrice, now, user.ID)
if err != nil {
return err
}
// 新增账单
args := []any{post.ID, user.ID, -post.AttachmentPrice, user.Balance - post.AttachmentPrice, "购买附件支出", now}
if _, err = tx.Stmtx(s.q.NewPostBill).Exec(args...); err != nil {
return err
}
// 新增附件购买记录
args = []any{post.ID, user.ID, post.AttachmentPrice, now}
if _, err = tx.Stmtx(s.q.NewPostAttachmentBill).Exec(args...); err != nil {
return err
}
// 对附件主新增账单
income := int64(float64(post.AttachmentPrice) * conf.AppSetting.AttachmentIncomeRate)
if income > 0 {
var oldBalance int64
if err = tx.Stmtx(s.q.GetUserBalance).Get(&oldBalance, post.UserID); err != nil {
return err
}
if _, err = tx.Stmtx(s.q.AddUserBalance).Exec(income, now, post.UserID); err != nil {
return err
}
// 新增账单
args = []any{post.ID, post.UserID, income, oldBalance + income, "出售附件收入", now}
if _, err = tx.Stmtx(s.q.NewPostBill).Exec(args...); err != nil {
return err
}
}
return nil
})
}
func newWalletService(db *sqlx.DB) core.WalletService {

@ -1,6 +1,6 @@
// Code generated by Yesql. DO NOT EDIT.
// versions:
// - Yesql v1.1.6
// - Yesql v1.5.0
package cc
@ -12,58 +12,191 @@ import (
)
const (
_UserInfo_AuthorizationManage = `SELECT * FROM @user WHERE username=?`
_UserInfo_CommentManage = `SELECT * FROM @user WHERE username=?`
_UserInfo_Comment = `SELECT * FROM @user WHERE username=?`
_UserInfo_ContactManager = `SELECT * FROM @user WHERE username=?`
_UserInfo_FollowIndexA = `SELECT * FROM @user WHERE username=?`
_UserInfo_FollowIndex = `SELECT * FROM @user WHERE username=?`
_UserInfo_FriendIndexA = `SELECT * FROM @user WHERE username=?`
_UserInfo_FriendIndex = `SELECT * FROM @user WHERE username=?`
_UserInfo_LightIndexA = `SELECT * FROM @user WHERE username=?`
_UserInfo_LightIndex = `SELECT * FROM @user WHERE username=?`
_UserInfo_Message = `SELECT * FROM @user WHERE username=?`
_UserInfo_Security = `SELECT * FROM @user WHERE username=?`
_UserInfo_SimpleIndexA = `SELECT * FROM @user WHERE username=?`
_UserInfo_SimpleIndex = `SELECT * FROM @user WHERE username=?`
_DecrTagsById_TopicA = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)`
_HotTags_TopicA = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.quote_num DESC LIMIT ? OFFSET ?`
_IncrTagsById_TopicA = `UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)`
_InsertTag_TopicA = `INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)`
_NewestTags_TopicA = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.id DESC LIMIT ? OFFSET ?`
_TagsByIdA_TopicA = `SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0`
_TagsByIdB_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)`
_TagsByKeywordA_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6`
_TagsByKeywordB_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6`
_TagsForIncr_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)`
_UserInfo_TweetA = `SELECT * FROM @user WHERE username=?`
_UserInfo_TweetHelpA = `SELECT * FROM @user WHERE username=?`
_UserInfo_TweetHelp = `SELECT * FROM @user WHERE username=?`
_UserInfo_TweetManageA = `SELECT * FROM @user WHERE username=?`
_UserInfo_TweetManage = `SELECT * FROM @user WHERE username=?`
_UserInfo_Tweet = `SELECT * FROM @user WHERE username=?`
_UserInfo_UserManage = `SELECT * FROM @user WHERE username=?`
_UserInfo_Wallet = `SELECT * FROM @user WHERE username=?`
_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`
_Comment_GetCommentById = `SELECT * FROM @comment WHERE id=? AND is_del=0`
_Comment_GetCommentContentsByIds = `SELECT * FROM @comment_content WHERE comment_id IN (?)`
_Comment_GetCommentCount = `SELECT count(*) FROM @comment WHERE post_id=:post_id AND is_del=0`
_Comment_GetCommentReplyById = `SELECT * FROM @comment_reply WHERE id=? AND is_del=0`
_Comment_GetCommentThumbs = `SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=?`
_Comment_GetComments = `SELECT * FROM @comment WHERE post_id=? AND is_del=0 ORDER BY %order% LIMIT ? OFFSET ?`
_Comment_GetCommmentRepliesByIds = `SELECT * FROM @comment_reply WHERE comment_id IN (?) ORDER BY id ASC`
_Comment_GetUsersByIds = `SELECT id, nickname, username, status, avatar, is_admin FROM @user WHERE id IN (?)`
_CommentManage_CreateComment = `INSERT INTO @comment (post_id, user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?)`
_CommentManage_CreateCommentContent = `INSERT INTO @comment_content (comment_id, user_id, content, type, sort, created_on) VALUES (?, ?, ?, ?, ?, ?)`
_CommentManage_CreateCommentReply = `INSERT INTO @comment_reply (comment_id, user_id, content, at_user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?, ?, ?)`
_CommentManage_CreateThumbsUpdownComment = `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)`
_CommentManage_DeleteComment = `UPDATE @comment SET deleted_on=?, is_del=1 WHERE id=? AND is_del=0`
_CommentManage_DeleteCommentReply = `UPDATE @comment_reply SET deleted_on=?, is_del=1 WHERE id=? AND is_del=0`
_CommentManage_DeleteCommentThumbs = `UPDATE @tweet_comment_thumbs SET deleted_on=?, is_del=1 WHERE user_id=? AND tweet_id=? AND comment_id=? AND is_del=0`
_CommentManage_DeleteReplyThumbs = `UPDATE @tweet_comment_thumbs SET deleted_on=?, is_del=1 WHERE user_id=? AND comment_id=? AND reply_id=? AND is_del=0`
_CommentManage_GetCommentReplyThumb = `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`
_CommentManage_GetTweetCommentThumb = `SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=? AND comment_id=? AND comment_type=0 AND is_del=0`
_CommentManage_UpdateCommentThumbsCount = `UPDATE @comment SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? WHERE id=? AND is_del=0`
_CommentManage_UpdateReplyThumbsCount = `UPDATE @comment_reply SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? WHERE id=? AND is_del=0`
_CommentManage_UpdateThumbsUpdownComment = `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`
_ContactManager_AddFriendMsgsUpdate = `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 = ?`
_ContactManager_CreateContact = `INSERT INTO @contact (user_id, friend_id, status, created_on) VALUES (?, ?, ?, ?)`
_ContactManager_CreateMessage = `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)`
_ContactManager_DelFriend = `UPDATE @contact SET status=4, is_del=1, deleted_on=? WHERE id=?`
_ContactManager_FreshContactStatus = `UPDATE @contact SET status=?, modified_on=?, is_del=0 WHERE id=?`
_ContactManager_GetContact = `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=?`
_ContactManager_GetContacts = `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=?)`
_ContactManager_GetUserFriend = `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`
_ContactManager_IsFriend = `SELECT true FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0 AND status=2`
_ContactManager_ListFriend = `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 ?`
_ContactManager_RejectFriendMsgsUpdate = `UPDATE @message SET reply_id=?, modified_on=? WHERE sender_user_id = ? AND receiver_user_id = ? AND type = ? AND reply_id = ?`
_ContactManager_TotalFriendsById = `SELECT count(*) FROM @contact WHERE user_id=? AND status=2 AND is_del=0`
_FollowIndexA_UserInfo = `SELECT * FROM @user WHERE username=?`
_FollowIndex_UserInfo = `SELECT * FROM @user WHERE username=?`
_FriendIndexA_UserInfo = `SELECT * FROM @user WHERE username=?`
_FriendIndex_UserInfo = `SELECT * FROM @user WHERE username=?`
_LightIndexA_UserInfo = `SELECT * FROM @user WHERE username=?`
_LightIndex_UserInfo = `SELECT * FROM @user WHERE username=?`
_Message_CreateMessage = `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)`
_Message_GetMessageById = `SELECT * FROM @message WHERE id=? AND is_del=0`
_Message_GetMessageCount = `SELECT count(*) FROM @message WHERE receiver_user_id=:recerver_user_id AND is_del=0`
_Message_GetMessages = `SELECT * FROM @message WHERE receiver_user_id=:recerver_user_id AND is_del=0 ORDER BY id DESC LIMIT :limit OFFSET :offset`
_Message_GetUnreadCount = `SELECT count(*) FROM @message WHERE receiver_user_id=? AND is_read=0 AND is_del=0`
_Message_ReadMessage = `UPDATE @message SET is_read=1, modified_on=? WHERE id=?`
_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`
_SimpleIndexA_UserInfo = `SELECT * FROM @user WHERE username=?`
_SimpleIndex_UserInfo = `SELECT * FROM @user WHERE username=?`
_TopicA_DecrTagsById = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)`
_TopicA_HotTags = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.quote_num DESC LIMIT ? OFFSET ?`
_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.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.id DESC LIMIT ? OFFSET ?`
_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 (?)`
_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 @user WHERE username=?`
_Tweet_GetPostById = `SELECT * FROM @post WHERE id=? AND is_del=0`
_Tweet_GetPostContentById = `SELECT * FROM @user WHERE username=?`
_Tweet_GetPostContentsByIds = `SELECT * FROM @post_content WHERE post_id IN (?) AND is_del=0`
_Tweet_GetUserPostCollection = `SELECT * FROM @user WHERE username=?`
_Tweet_GetUserPostCollectionCount = `SELECT * FROM @user WHERE username=?`
_Tweet_GetUserPostCollections = `SELECT * FROM @user WHERE username=?`
_Tweet_GetUserPostCount = `SELECT count(*) FROM @post WHERE user_id=? AND visibility IN (?)`
_Tweet_GetUserPostStar = `SELECT * FROM @user WHERE username=?`
_Tweet_GetUserPostStarCount = `SELECT * FROM @user WHERE username=?`
_Tweet_GetUserPostStars = `SELECT * FROM @user WHERE username=?`
_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 (?, ?, ?)`
_TweetManage_AddPostContent = `INSERT INTO @post_content (post_id, user_id, content, type, sort, created_on) VALUES (:post_id, :user_id, :content, :type, :sort, :created_on)`
_TweetManage_AddPostStar = `INSERT INTO @post_star (post_id, user_id, created_on) VALUES (?, ?, ?)`
_TweetManage_DelPostById = `UPDATE @post SET is_del=1, deleted_on=? WHERE id=? AND is_del=0`
_TweetManage_DelPostCollection = `UPDATE @post_collection SET is_del=1, deleted_on=? WHERE id=? AND is_del=0`
_TweetManage_DelPostStar = `UPDATE @post_star SET is_del=1, deleted_on=? WHERE id=? AND is_del=0`
_TweetManage_LockPost = `UPDATE @post SET is_lock=1-is_lock, modified_on=? WHERE id=? AND is_del=0`
_TweetManage_MediaContentByPostId = `SELECT content FROM post_content WHERE post_id=? AND is_del=0 AND type IN (3, 4, 5, 7, 8)`
_TweetManage_StickPost = `UPDATE @post SET is_top=1-is_top, modified_on=? WHERE id=? AND is_del=0`
_TweetManage_UpdatePost = `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`
_TweetManage_VisiblePost = `UPDATE @post SET visibility=?, is_top=?, modified_on=? WHERE id=? AND is_del=0`
_UserManage_CreateUser = `INSERT INTO @user (username, nickname, password, salt, avatar, status, created_on) VALUES (:username, :nickname, :password, :salt, :avatar, :status, :created_on)`
_UserManage_GetAnyUsers = `SELECT * FROM @user WHERE is_del=0 ORDER BY id ASC limit 6`
_UserManage_GetUserById = `SELECT * FROM @user WHERE id=? AND is_del=0`
_UserManage_GetUserByPhone = `SELECT * FROM @user WHERE phone=? AND is_del=0`
_UserManage_GetUserByUsername = `SELECT * FROM @user WHERE username=? AND is_del=0`
_UserManage_GetUsersByIds = `SELECT * FROM @user WHERE id IN (?) AND is_del=0`
_UserManage_GetUsersByKeyword = `SELECT * FROM @user WHERE username LIKE ? AND is_del=0 limit 6`
_UserManage_UpdateUser = `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_AddUserBalance = `UPDATE @user SET balance=balance+?, modified_on=? WHERE id=? AND is_del=0`
_Wallet_CreateRecharge = `INSERT INTO @wallet_recharge (user_id, amount, created_on) VALUES (?, ?, ?)`
_Wallet_CreateWalletStatement = `INSERT INTO @wallet_statement (user_id, change_amount, balance_snapshot, reason, created_on) VALUES (?, ?, ?, ?, ?)`
_Wallet_GetRechargeById = `SELECT * FROM @wallet_recharge WHERE id=? AND is_del=?`
_Wallet_GetUserBalance = `SELECT balance FROM @user WHERE id=? AND is_del=0`
_Wallet_GetUserByUid = `SELECT * FROM @user WHERE id=? AND is_del=0`
_Wallet_GetUserWalletBillCount = `SELECT count(*) FROM @wallet_statement WHERE user_id=? AND is_del=0`
_Wallet_GetUserWalletBills = `SELECT * FROM @wallet_statement WHERE user_id=? AND is_del=0 ORDER BY id DESC LIMIT ? OFFSET ?`
_Wallet_MarkSuccessRecharge = `UPDATE @wallet_recharge SET trade_no=?, trade_status='TRADE_SUCCESS', modified_on=? WHERE id=? AND is_del=0`
_Wallet_MinusUserBalance = `UPDATE @user SET balance=balance-?, modified_on=? WHERE id=? AND is_del=0`
_Wallet_NewPostAttachmentBill = `INSERT INTO @post_attachment_bill (post_id, user_id, paid_amount, created_on) VALUES (?, ?, ?, ?)`
_Wallet_NewPostBill = `INSERT INTO @wallet_statement (post_id, user_id, change_amount, balance_snapshot, reason, created_on) VALUES (?, ?, ?, ?, ?, ?)`
)
type Yesql struct {
TagsFromNames string `yesql:"tags_from_names"`
UpdateTagQuote *sqlx.Stmt `yesql:"update_tag_quote"`
}
type AuthorizationManage struct {
yesql.Namespace `yesql:"authorization_manage"`
UserInfo *sqlx.Stmt `yesql:"user_info"`
BeFriendIds *sqlx.Stmt `yesql:"be_friend_ids"`
IsFriend *sqlx.Stmt `yesql:"is_friend"`
MyFriendSet *sqlx.Stmt `yesql:"my_friend_set"`
}
type Comment struct {
yesql.Namespace `yesql:"comment"`
UserInfo *sqlx.Stmt `yesql:"user_info"`
yesql.Namespace `yesql:"comment"`
GetCommentContentsByIds string `yesql:"get_comment_contents_by_ids"`
GetComments string `yesql:"get_comments"`
GetCommmentRepliesByIds string `yesql:"get_commment_replies_by_ids"`
GetUsersByIds string `yesql:"get_users_by_ids"`
GetCommentById *sqlx.Stmt `yesql:"get_comment_by_id"`
GetCommentReplyById *sqlx.Stmt `yesql:"get_comment_reply_by_id"`
GetCommentThumbs *sqlx.Stmt `yesql:"get_comment_thumbs"`
GetCommentCount *sqlx.NamedStmt `yesql:"get_comment_count"`
}
type CommentManage struct {
yesql.Namespace `yesql:"comment_manage"`
UserInfo *sqlx.Stmt `yesql:"user_info"`
yesql.Namespace `yesql:"comment_manage"`
CreateComment *sqlx.Stmt `yesql:"create_comment"`
CreateCommentContent *sqlx.Stmt `yesql:"create_comment_content"`
CreateCommentReply *sqlx.Stmt `yesql:"create_comment_reply"`
DeleteComment *sqlx.Stmt `yesql:"delete_comment"`
DeleteCommentReply *sqlx.Stmt `yesql:"delete_comment_reply"`
DeleteCommentThumbs *sqlx.Stmt `yesql:"delete_comment_thumbs"`
DeleteReplyThumbs *sqlx.Stmt `yesql:"delete_reply_thumbs"`
GetCommentReplyThumb *sqlx.Stmt `yesql:"get_comment_reply_thumb"`
GetTweetCommentThumb *sqlx.Stmt `yesql:"get_tweet_comment_thumb"`
UpdateCommentThumbsCount *sqlx.Stmt `yesql:"update_comment_thumbs_count"`
UpdateReplyThumbsCount *sqlx.Stmt `yesql:"update_reply_thumbs_count"`
CreateThumbsUpdownComment *sqlx.NamedStmt `yesql:"create_thumbs_updown_comment"`
UpdateThumbsUpdownComment *sqlx.NamedStmt `yesql:"update_thumbs_updown_comment"`
}
type ContactManager struct {
yesql.Namespace `yesql:"contact_manager"`
UserInfo *sqlx.Stmt `yesql:"user_info"`
yesql.Namespace `yesql:"contact_manager"`
AddFriendMsgsUpdate *sqlx.Stmt `yesql:"add_friend_msgs_update"`
CreateContact *sqlx.Stmt `yesql:"create_contact"`
DelFriend *sqlx.Stmt `yesql:"del_friend"`
FreshContactStatus *sqlx.Stmt `yesql:"fresh_contact_status"`
GetContact *sqlx.Stmt `yesql:"get_contact"`
GetContacts *sqlx.Stmt `yesql:"get_contacts"`
GetUserFriend *sqlx.Stmt `yesql:"get_user_friend"`
IsFriend *sqlx.Stmt `yesql:"is_friend"`
ListFriend *sqlx.Stmt `yesql:"list_friend"`
RejectFriendMsgsUpdate *sqlx.Stmt `yesql:"reject_friend_msgs_update"`
TotalFriendsById *sqlx.Stmt `yesql:"total_friends_by_id"`
CreateMessage *sqlx.NamedStmt `yesql:"create_message"`
}
type FollowIndex struct {
@ -98,12 +231,19 @@ type LightIndexA struct {
type Message struct {
yesql.Namespace `yesql:"message"`
UserInfo *sqlx.Stmt `yesql:"user_info"`
GetMessageById *sqlx.Stmt `yesql:"get_message_by_id"`
GetUnreadCount *sqlx.Stmt `yesql:"get_unread_count"`
ReadMessage *sqlx.Stmt `yesql:"read_message"`
CreateMessage *sqlx.NamedStmt `yesql:"create_message"`
GetMessageCount *sqlx.NamedStmt `yesql:"get_message_count"`
GetMessages *sqlx.NamedStmt `yesql:"get_messages"`
}
type Security struct {
yesql.Namespace `yesql:"security"`
UserInfo *sqlx.Stmt `yesql:"user_info"`
yesql.Namespace `yesql:"security"`
GetLatestPhoneCaptcha *sqlx.Stmt `yesql:"get_latest_phone_captcha"`
UsePhoneCaptcha *sqlx.Stmt `yesql:"use_phone_captcha"`
CreatePhoneCaptcha *sqlx.NamedStmt `yesql:"create_phone_captcha"`
}
type SimpleIndex struct {
@ -131,18 +271,43 @@ type TopicA struct {
}
type Tweet struct {
yesql.Namespace `yesql:"tweet"`
UserInfo *sqlx.Stmt `yesql:"user_info"`
yesql.Namespace `yesql:"tweet"`
GetAnyPostCount string `yesql:"get_any_post_count"`
GetAnyPosts string `yesql:"get_any_posts"`
GetPostContentsByIds string `yesql:"get_post_contents_by_ids"`
GetUserPostCount string `yesql:"get_user_post_count"`
GetUserPosts string `yesql:"get_user_posts"`
GetPostAttachmentBill *sqlx.Stmt `yesql:"get_post_attachment_bill"`
GetPostById *sqlx.Stmt `yesql:"get_post_by_id"`
GetPostContentById *sqlx.Stmt `yesql:"get_post_content_by_id"`
GetUserPostCollection *sqlx.Stmt `yesql:"get_user_post_collection"`
GetUserPostCollectionCount *sqlx.Stmt `yesql:"get_user_post_collection_count"`
GetUserPostCollections *sqlx.Stmt `yesql:"get_user_post_collections"`
GetUserPostStar *sqlx.Stmt `yesql:"get_user_post_star"`
GetUserPostStarCount *sqlx.Stmt `yesql:"get_user_post_star_count"`
GetUserPostStars *sqlx.Stmt `yesql:"get_user_post_stars"`
}
type TweetA struct {
yesql.Namespace `yesql:"tweet_a"`
UserInfo *sqlx.Stmt `yesql:"user_info"`
yesql.Namespace `yesql:"tweet_a"`
AttachmentByTweetId *sqlx.Stmt `yesql:"attachment_by_tweet_id"`
FavoriteByTweetId *sqlx.Stmt `yesql:"favorite_by_tweet_id"`
ReactionByTweetId *sqlx.Stmt `yesql:"reaction_by_tweet_id"`
TweetInfoById *sqlx.Stmt `yesql:"tweet_info_by_id"`
TweetItemById *sqlx.Stmt `yesql:"tweet_item_by_id"`
UserFavorites *sqlx.Stmt `yesql:"user_favorites"`
UserInfo *sqlx.Stmt `yesql:"user_info"`
UserReactions *sqlx.Stmt `yesql:"user_reactions"`
UserTweetsByAdmin *sqlx.Stmt `yesql:"user_tweets_by_admin"`
UserTweetsByFriend *sqlx.Stmt `yesql:"user_tweets_by_friend"`
UserTweetsByGuest *sqlx.Stmt `yesql:"user_tweets_by_guest"`
UserTweetsBySelf *sqlx.Stmt `yesql:"user_tweets_by_self"`
}
type TweetHelp struct {
yesql.Namespace `yesql:"tweet_help"`
UserInfo *sqlx.Stmt `yesql:"user_info"`
yesql.Namespace `yesql:"tweet_help"`
GetPostContentByIds string `yesql:"get_post_content_by_ids"`
GetUsersByIds string `yesql:"get_users_by_ids"`
}
type TweetHelpA struct {
@ -151,8 +316,20 @@ type TweetHelpA struct {
}
type TweetManage struct {
yesql.Namespace `yesql:"tweet_manage"`
UserInfo *sqlx.Stmt `yesql:"user_info"`
yesql.Namespace `yesql:"tweet_manage"`
AddAttachment *sqlx.Stmt `yesql:"add_attachment"`
AddPostCollection *sqlx.Stmt `yesql:"add_post_collection"`
AddPostStar *sqlx.Stmt `yesql:"add_post_star"`
DelPostById *sqlx.Stmt `yesql:"del_post_by_id"`
DelPostCollection *sqlx.Stmt `yesql:"del_post_collection"`
DelPostStar *sqlx.Stmt `yesql:"del_post_star"`
LockPost *sqlx.Stmt `yesql:"lock_post"`
MediaContentByPostId *sqlx.Stmt `yesql:"media_content_by_post_id"`
StickPost *sqlx.Stmt `yesql:"stick_post"`
VisiblePost *sqlx.Stmt `yesql:"visible_post"`
AddPost *sqlx.NamedStmt `yesql:"add_post"`
AddPostContent *sqlx.NamedStmt `yesql:"add_post_content"`
UpdatePost *sqlx.NamedStmt `yesql:"update_post"`
}
type TweetManageA struct {
@ -161,13 +338,47 @@ type TweetManageA struct {
}
type UserManage struct {
yesql.Namespace `yesql:"user_manage"`
UserInfo *sqlx.Stmt `yesql:"user_info"`
yesql.Namespace `yesql:"user_manage"`
GetUsersByIds string `yesql:"get_users_by_ids"`
GetAnyUsers *sqlx.Stmt `yesql:"get_any_users"`
GetUserById *sqlx.Stmt `yesql:"get_user_by_id"`
GetUserByPhone *sqlx.Stmt `yesql:"get_user_by_phone"`
GetUserByUsername *sqlx.Stmt `yesql:"get_user_by_username"`
GetUsersByKeyword *sqlx.Stmt `yesql:"get_users_by_keyword"`
CreateUser *sqlx.NamedStmt `yesql:"create_user"`
UpdateUser *sqlx.NamedStmt `yesql:"update_user"`
}
type Wallet struct {
yesql.Namespace `yesql:"wallet"`
UserInfo *sqlx.Stmt `yesql:"user_info"`
yesql.Namespace `yesql:"wallet"`
AddUserBalance *sqlx.Stmt `yesql:"add_user_balance"`
CreateRecharge *sqlx.Stmt `yesql:"create_recharge"`
CreateWalletStatement *sqlx.Stmt `yesql:"create_wallet_statement"`
GetRechargeById *sqlx.Stmt `yesql:"get_recharge_by_id"`
GetUserBalance *sqlx.Stmt `yesql:"get_user_balance"`
GetUserByUid *sqlx.Stmt `yesql:"get_user_by_uid"`
GetUserWalletBillCount *sqlx.Stmt `yesql:"get_user_wallet_bill_count"`
GetUserWalletBills *sqlx.Stmt `yesql:"get_user_wallet_bills"`
MarkSuccessRecharge *sqlx.Stmt `yesql:"mark_success_recharge"`
MinusUserBalance *sqlx.Stmt `yesql:"minus_user_balance"`
NewPostAttachmentBill *sqlx.Stmt `yesql:"new_post_attachment_bill"`
NewPostBill *sqlx.Stmt `yesql:"new_post_bill"`
}
func BuildYesql(p yesql.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 yesql.PreparexBuilder, ctx ...context.Context) (obj *AuthorizationManage, err error) {
@ -178,7 +389,13 @@ func BuildAuthorizationManage(p yesql.PreparexBuilder, ctx ...context.Context) (
c = context.Background()
}
obj = &AuthorizationManage{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_AuthorizationManage))); err != nil {
if obj.BeFriendIds, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AuthorizationManage_BeFriendIds))); err != nil {
return
}
if obj.IsFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AuthorizationManage_IsFriend))); err != nil {
return
}
if obj.MyFriendSet, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AuthorizationManage_MyFriendSet))); err != nil {
return
}
return
@ -191,8 +408,22 @@ func BuildComment(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Comment
} else {
c = context.Background()
}
obj = &Comment{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_Comment))); err != nil {
obj = &Comment{
GetCommentContentsByIds: p.QueryHook(_Comment_GetCommentContentsByIds),
GetComments: p.QueryHook(_Comment_GetComments),
GetCommmentRepliesByIds: p.QueryHook(_Comment_GetCommmentRepliesByIds),
GetUsersByIds: p.QueryHook(_Comment_GetUsersByIds),
}
if obj.GetCommentById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Comment_GetCommentById))); err != nil {
return
}
if obj.GetCommentReplyById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Comment_GetCommentReplyById))); err != nil {
return
}
if obj.GetCommentThumbs, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Comment_GetCommentThumbs))); err != nil {
return
}
if obj.GetCommentCount, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_Comment_GetCommentCount))); err != nil {
return
}
return
@ -206,7 +437,43 @@ func BuildCommentManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *C
c = context.Background()
}
obj = &CommentManage{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_CommentManage))); err != nil {
if obj.CreateComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_CreateComment))); err != nil {
return
}
if obj.CreateCommentContent, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_CreateCommentContent))); err != nil {
return
}
if obj.CreateCommentReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_CreateCommentReply))); err != nil {
return
}
if obj.DeleteComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DeleteComment))); err != nil {
return
}
if obj.DeleteCommentReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DeleteCommentReply))); err != nil {
return
}
if obj.DeleteCommentThumbs, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DeleteCommentThumbs))); err != nil {
return
}
if obj.DeleteReplyThumbs, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DeleteReplyThumbs))); err != nil {
return
}
if obj.GetCommentReplyThumb, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_GetCommentReplyThumb))); err != nil {
return
}
if obj.GetTweetCommentThumb, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_GetTweetCommentThumb))); err != nil {
return
}
if obj.UpdateCommentThumbsCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_UpdateCommentThumbsCount))); err != nil {
return
}
if obj.UpdateReplyThumbsCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_UpdateReplyThumbsCount))); err != nil {
return
}
if obj.CreateThumbsUpdownComment, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CommentManage_CreateThumbsUpdownComment))); err != nil {
return
}
if obj.UpdateThumbsUpdownComment, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CommentManage_UpdateThumbsUpdownComment))); err != nil {
return
}
return
@ -220,7 +487,40 @@ func BuildContactManager(p yesql.PreparexBuilder, ctx ...context.Context) (obj *
c = context.Background()
}
obj = &ContactManager{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_ContactManager))); err != nil {
if obj.AddFriendMsgsUpdate, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_AddFriendMsgsUpdate))); err != nil {
return
}
if obj.CreateContact, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_CreateContact))); err != nil {
return
}
if obj.DelFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_DelFriend))); err != nil {
return
}
if obj.FreshContactStatus, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_FreshContactStatus))); err != nil {
return
}
if obj.GetContact, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_GetContact))); err != nil {
return
}
if obj.GetContacts, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_GetContacts))); err != nil {
return
}
if obj.GetUserFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_GetUserFriend))); err != nil {
return
}
if obj.IsFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_IsFriend))); err != nil {
return
}
if obj.ListFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_ListFriend))); err != nil {
return
}
if obj.RejectFriendMsgsUpdate, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_RejectFriendMsgsUpdate))); err != nil {
return
}
if obj.TotalFriendsById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_TotalFriendsById))); err != nil {
return
}
if obj.CreateMessage, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_ContactManager_CreateMessage))); err != nil {
return
}
return
@ -234,7 +534,7 @@ func BuildFollowIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Fol
c = context.Background()
}
obj = &FollowIndex{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_FollowIndex))); err != nil {
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_FollowIndex_UserInfo))); err != nil {
return
}
return
@ -248,7 +548,7 @@ func BuildFollowIndexA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Fo
c = context.Background()
}
obj = &FollowIndexA{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_FollowIndexA))); err != nil {
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_FollowIndexA_UserInfo))); err != nil {
return
}
return
@ -262,7 +562,7 @@ func BuildFriendIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Fri
c = context.Background()
}
obj = &FriendIndex{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_FriendIndex))); err != nil {
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_FriendIndex_UserInfo))); err != nil {
return
}
return
@ -276,7 +576,7 @@ func BuildFriendIndexA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Fr
c = context.Background()
}
obj = &FriendIndexA{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_FriendIndexA))); err != nil {
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_FriendIndexA_UserInfo))); err != nil {
return
}
return
@ -290,7 +590,7 @@ func BuildLightIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Ligh
c = context.Background()
}
obj = &LightIndex{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_LightIndex))); err != nil {
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_LightIndex_UserInfo))); err != nil {
return
}
return
@ -304,7 +604,7 @@ func BuildLightIndexA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Lig
c = context.Background()
}
obj = &LightIndexA{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_LightIndexA))); err != nil {
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_LightIndexA_UserInfo))); err != nil {
return
}
return
@ -318,7 +618,22 @@ func BuildMessage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Message
c = context.Background()
}
obj = &Message{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_Message))); err != nil {
if obj.GetMessageById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_GetMessageById))); err != nil {
return
}
if obj.GetUnreadCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_GetUnreadCount))); err != nil {
return
}
if obj.ReadMessage, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_ReadMessage))); err != nil {
return
}
if obj.CreateMessage, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_Message_CreateMessage))); err != nil {
return
}
if obj.GetMessageCount, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_Message_GetMessageCount))); err != nil {
return
}
if obj.GetMessages, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_Message_GetMessages))); err != nil {
return
}
return
@ -332,7 +647,13 @@ func BuildSecurity(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Securi
c = context.Background()
}
obj = &Security{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_Security))); err != nil {
if obj.GetLatestPhoneCaptcha, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Security_GetLatestPhoneCaptcha))); err != nil {
return
}
if obj.UsePhoneCaptcha, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Security_UsePhoneCaptcha))); err != nil {
return
}
if obj.CreatePhoneCaptcha, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_Security_CreatePhoneCaptcha))); err != nil {
return
}
return
@ -346,7 +667,7 @@ func BuildSimpleIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Sim
c = context.Background()
}
obj = &SimpleIndex{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_SimpleIndex))); err != nil {
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_SimpleIndex_UserInfo))); err != nil {
return
}
return
@ -360,7 +681,7 @@ func BuildSimpleIndexA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Si
c = context.Background()
}
obj = &SimpleIndexA{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_SimpleIndexA))); err != nil {
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_SimpleIndexA_UserInfo))); err != nil {
return
}
return
@ -374,25 +695,25 @@ func BuildTopicA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *TopicA,
c = context.Background()
}
obj = &TopicA{
DecrTagsById: p.QueryHook(_DecrTagsById_TopicA),
IncrTagsById: p.QueryHook(_IncrTagsById_TopicA),
TagsByIdA: p.QueryHook(_TagsByIdA_TopicA),
TagsByIdB: p.QueryHook(_TagsByIdB_TopicA),
TagsForIncr: p.QueryHook(_TagsForIncr_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),
}
if obj.HotTags, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_HotTags_TopicA))); err != nil {
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(_InsertTag_TopicA))); err != nil {
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(_NewestTags_TopicA))); err != nil {
if obj.NewestTags, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_NewestTags))); err != nil {
return
}
if obj.TagsByKeywordA, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TagsByKeywordA_TopicA))); err != nil {
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(_TagsByKeywordB_TopicA))); err != nil {
if obj.TagsByKeywordB, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_TagsByKeywordB))); err != nil {
return
}
return
@ -405,8 +726,38 @@ func BuildTweet(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Tweet, er
} else {
c = context.Background()
}
obj = &Tweet{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_Tweet))); err != nil {
obj = &Tweet{
GetAnyPostCount: p.QueryHook(_Tweet_GetAnyPostCount),
GetAnyPosts: p.QueryHook(_Tweet_GetAnyPosts),
GetPostContentsByIds: p.QueryHook(_Tweet_GetPostContentsByIds),
GetUserPostCount: p.QueryHook(_Tweet_GetUserPostCount),
GetUserPosts: p.QueryHook(_Tweet_GetUserPosts),
}
if obj.GetPostAttachmentBill, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetPostAttachmentBill))); err != nil {
return
}
if obj.GetPostById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetPostById))); err != nil {
return
}
if obj.GetPostContentById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetPostContentById))); err != nil {
return
}
if obj.GetUserPostCollection, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetUserPostCollection))); err != nil {
return
}
if obj.GetUserPostCollectionCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetUserPostCollectionCount))); err != nil {
return
}
if obj.GetUserPostCollections, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetUserPostCollections))); err != nil {
return
}
if obj.GetUserPostStar, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetUserPostStar))); err != nil {
return
}
if obj.GetUserPostStarCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetUserPostStarCount))); err != nil {
return
}
if obj.GetUserPostStars, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetUserPostStars))); err != nil {
return
}
return
@ -420,22 +771,49 @@ func BuildTweetA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *TweetA,
c = context.Background()
}
obj = &TweetA{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_TweetA))); err != nil {
if obj.AttachmentByTweetId, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_AttachmentByTweetId))); err != nil {
return
}
if obj.FavoriteByTweetId, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_FavoriteByTweetId))); err != nil {
return
}
if obj.ReactionByTweetId, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_ReactionByTweetId))); err != nil {
return
}
if obj.TweetInfoById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_TweetInfoById))); err != nil {
return
}
if obj.TweetItemById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_TweetItemById))); err != nil {
return
}
if obj.UserFavorites, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_UserFavorites))); err != nil {
return
}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_UserInfo))); err != nil {
return
}
if obj.UserReactions, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_UserReactions))); err != nil {
return
}
if obj.UserTweetsByAdmin, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_UserTweetsByAdmin))); err != nil {
return
}
if obj.UserTweetsByFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_UserTweetsByFriend))); err != nil {
return
}
if obj.UserTweetsByGuest, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_UserTweetsByGuest))); err != nil {
return
}
if obj.UserTweetsBySelf, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_UserTweetsBySelf))); err != nil {
return
}
return
}
func BuildTweetHelp(p yesql.PreparexBuilder, ctx ...context.Context) (obj *TweetHelp, err error) {
var c context.Context
if len(ctx) > 0 && ctx[0] != nil {
c = ctx[0]
} else {
c = context.Background()
}
obj = &TweetHelp{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_TweetHelp))); err != nil {
return
func BuildTweetHelp(p yesql.PreparexBuilder) (obj *TweetHelp, err error) {
obj = &TweetHelp{
GetPostContentByIds: p.QueryHook(_TweetHelp_GetPostContentByIds),
GetUsersByIds: p.QueryHook(_TweetHelp_GetUsersByIds),
}
return
}
@ -448,7 +826,7 @@ func BuildTweetHelpA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Twee
c = context.Background()
}
obj = &TweetHelpA{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_TweetHelpA))); err != nil {
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetHelpA_UserInfo))); err != nil {
return
}
return
@ -462,7 +840,43 @@ func BuildTweetManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Twe
c = context.Background()
}
obj = &TweetManage{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_TweetManage))); err != nil {
if obj.AddAttachment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_AddAttachment))); err != nil {
return
}
if obj.AddPostCollection, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_AddPostCollection))); err != nil {
return
}
if obj.AddPostStar, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_AddPostStar))); err != nil {
return
}
if obj.DelPostById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_DelPostById))); err != nil {
return
}
if obj.DelPostCollection, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_DelPostCollection))); err != nil {
return
}
if obj.DelPostStar, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_DelPostStar))); err != nil {
return
}
if obj.LockPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_LockPost))); err != nil {
return
}
if obj.MediaContentByPostId, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_MediaContentByPostId))); err != nil {
return
}
if obj.StickPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_StickPost))); err != nil {
return
}
if obj.VisiblePost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_VisiblePost))); err != nil {
return
}
if obj.AddPost, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_TweetManage_AddPost))); err != nil {
return
}
if obj.AddPostContent, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_TweetManage_AddPostContent))); err != nil {
return
}
if obj.UpdatePost, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_TweetManage_UpdatePost))); err != nil {
return
}
return
@ -476,7 +890,7 @@ func BuildTweetManageA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Tw
c = context.Background()
}
obj = &TweetManageA{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_TweetManageA))); err != nil {
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManageA_UserInfo))); err != nil {
return
}
return
@ -489,8 +903,28 @@ func BuildUserManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *User
} else {
c = context.Background()
}
obj = &UserManage{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_UserManage))); err != nil {
obj = &UserManage{
GetUsersByIds: p.QueryHook(_UserManage_GetUsersByIds),
}
if obj.GetAnyUsers, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserManage_GetAnyUsers))); err != nil {
return
}
if obj.GetUserById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserManage_GetUserById))); err != nil {
return
}
if obj.GetUserByPhone, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserManage_GetUserByPhone))); err != nil {
return
}
if obj.GetUserByUsername, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserManage_GetUserByUsername))); err != nil {
return
}
if obj.GetUsersByKeyword, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserManage_GetUsersByKeyword))); err != nil {
return
}
if obj.CreateUser, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_UserManage_CreateUser))); err != nil {
return
}
if obj.UpdateUser, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_UserManage_UpdateUser))); err != nil {
return
}
return
@ -504,7 +938,40 @@ func BuildWallet(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Wallet,
c = context.Background()
}
obj = &Wallet{}
if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_Wallet))); err != nil {
if obj.AddUserBalance, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_AddUserBalance))); err != nil {
return
}
if obj.CreateRecharge, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_CreateRecharge))); err != nil {
return
}
if obj.CreateWalletStatement, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_CreateWalletStatement))); err != nil {
return
}
if obj.GetRechargeById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_GetRechargeById))); err != nil {
return
}
if obj.GetUserBalance, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_GetUserBalance))); err != nil {
return
}
if obj.GetUserByUid, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_GetUserByUid))); err != nil {
return
}
if obj.GetUserWalletBillCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_GetUserWalletBillCount))); err != nil {
return
}
if obj.GetUserWalletBills, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_GetUserWalletBills))); err != nil {
return
}
if obj.MarkSuccessRecharge, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_MarkSuccessRecharge))); err != nil {
return
}
if obj.MinusUserBalance, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_MinusUserBalance))); err != nil {
return
}
if obj.NewPostAttachmentBill, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_NewPostAttachmentBill))); err != nil {
return
}
if obj.NewPostBill, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_NewPostBill))); err != nil {
return
}
return

@ -1,3 +1,10 @@
// 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.
//go:build generate
// +build generate
package main
import (

@ -1,50 +1,265 @@
--------------------------------------------------------------------------------
-- global sql dml
--------------------------------------------------------------------------------
-- name: tags_from_names
-- prepare: raw
-- clause: in
SELECT * FROM @tag WHERE tag IN (?) AND is_del=0;
-- name: update_tag_quote
-- prepare: stmt
UPDATE @tag SET quote_num=?, modified_on=?
WHERE id=? AND is_del=0;
--------------------------------------------------------------------------------
-- authorization_manage sql dml
--------------------------------------------------------------------------------
-- name: user_info@authorization_manage
-- name: be_friend_ids@authorization_manage
-- prepare: stmt
SELECT * FROM @user WHERE username=?
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: user_info@comment
-- 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 @user WHERE username=?
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: user_info@comment_manage
-- name: delete_comment@comment_manage
-- prepare: stmt
SELECT * FROM @user WHERE username=?
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;
--------------------------------------------------------------------------------
-- contact_manager sql dml
--------------------------------------------------------------------------------
-- name: user_info@contact_manager
-- name: create_contact@contact_manager
-- prepare: stmt
SELECT * FROM @user WHERE username=?
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: user_info@message
-- 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 * FROM @user WHERE username=?
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: user_info@security
-- name: get_latest_phone_captcha@security
-- prepare: stmt
SELECT * FROM @user WHERE username=?
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);
--------------------------------------------------------------------------------
-- friend_index sql dml
@ -114,7 +329,68 @@ SELECT * FROM @user WHERE username=?
-- tweet sql dml
--------------------------------------------------------------------------------
-- name: user_info@tweet
-- 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 * FROM @user WHERE username=?
-- name: get_user_post_stars@tweet
-- prepare: stmt
SELECT * FROM @user WHERE username=?
-- name: get_user_post_star_count@tweet
-- prepare: stmt
SELECT * FROM @user WHERE username=?
-- name: get_user_post_collection@tweet
-- prepare: stmt
SELECT * FROM @user WHERE username=?
-- name: get_user_post_collections@tweet
-- prepare: stmt
SELECT * FROM @user WHERE username=?
-- name: get_user_post_collection_count@tweet
-- prepare: stmt
SELECT * FROM @user WHERE username=?
-- name: get_post_attachment_bill@tweet
-- prepare: stmt
SELECT * FROM @user WHERE username=?
-- 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 @user WHERE username=?
@ -122,17 +398,85 @@ SELECT * FROM @user WHERE username=?
-- tweet_manage sql dml
--------------------------------------------------------------------------------
-- name: user_info@tweet_manage
-- 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
SELECT * FROM @user WHERE username=?
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: 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 (?, ?, ?, ?, ?, ?, ?);
--------------------------------------------------------------------------------
-- tweet_help sql dml
--------------------------------------------------------------------------------
-- name: user_info@tweet_help
-- prepare: stmt
SELECT * FROM @user WHERE username=?
-- 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
@ -142,6 +486,50 @@ SELECT * FROM @user WHERE username=?
-- prepare: stmt
SELECT * FROM @user WHERE username=?
-- name: tweet_info_by_id@tweet_a
-- prepare: stmt
SELECT * FROM @user WHERE username=?
-- name: tweet_item_by_id@tweet_a
-- prepare: stmt
SELECT * FROM @user WHERE username=?
-- name: user_tweets_by_admin@tweet_a
-- prepare: stmt
SELECT * FROM @user WHERE username=?
-- name: user_tweets_by_self@tweet_a
-- prepare: stmt
SELECT * FROM @user WHERE username=?
-- name: user_tweets_by_friend@tweet_a
-- prepare: stmt
SELECT * FROM @user WHERE username=?
-- name: user_tweets_by_guest@tweet_a
-- prepare: stmt
SELECT * FROM @user WHERE username=?
-- name: reaction_by_tweet_id@tweet_a
-- prepare: stmt
SELECT * FROM @user WHERE username=?
-- name: user_reactions@tweet_a
-- prepare: stmt
SELECT * FROM @user WHERE username=?
-- name: favorite_by_tweet_id@tweet_a
-- prepare: stmt
SELECT * FROM @user WHERE username=?
-- name: user_favorites@tweet_a
-- prepare: stmt
SELECT * FROM @user WHERE username=?
-- name: attachment_by_tweet_id@tweet_a
-- prepare: stmt
SELECT * FROM @user WHERE username=?
--------------------------------------------------------------------------------
-- tweet_manage_a sql dml
--------------------------------------------------------------------------------
@ -184,13 +572,21 @@ LIMIT ? OFFSET ?;
-- 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;
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;
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);
INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num)
VALUES (?, ?, ?, ?, 1);
-- name: tags_by_id_a@topic_a
-- prepare: raw
@ -221,14 +617,108 @@ UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?);
-- user_manage sql dml
--------------------------------------------------------------------------------
-- name: user_info@user_manage
-- name: get_user_by_id@user_manage
-- prepare: stmt
SELECT * FROM @user WHERE username=?
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: user_info@wallet
-- name: get_user_wallet_bills@wallet
-- prepare: stmt
SELECT * FROM @user WHERE username=?
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 (?, ?, ?, ?, ?, ?);

Loading…
Cancel
Save