sqlc: add base sql query

r/paopao-ce-pro
Michael Li 2 years ago
parent 0141aff7e1
commit ba66ad922f
No known key found for this signature in database

@ -46,6 +46,8 @@ type PComment struct {
IsDel int16 IsDel int16
ThumbsUpCount int32 ThumbsUpCount int32
ThumbsDownCount int32 ThumbsDownCount int32
IsEssence int16
ReplyCount int32
} }
type PCommentContent struct { type PCommentContent struct {
@ -61,6 +63,19 @@ type PCommentContent struct {
IsDel int16 IsDel int16
} }
type PCommentMetric struct {
ID int64
CommentID int64
RankScore int64
IncentiveScore int32
DecayFactor int32
MotivationFactor int32
IsDel int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
}
type PCommentReply struct { type PCommentReply struct {
ID int64 ID int64
CommentID int64 CommentID int64
@ -231,6 +246,19 @@ type PPostContent struct {
IsDel int16 IsDel int16
} }
type PPostMetric struct {
ID int64
PostID int64
RankScore int64
IncentiveScore int32
DecayFactor int32
MotivationFactor int32
IsDel int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
}
type PPostStar struct { type PPostStar struct {
ID int64 ID int64
PostID int64 PostID int64
@ -300,6 +328,17 @@ type PUser struct {
IsDel int16 IsDel int16
} }
type PUserMetric struct {
ID int64
UserID int64
TweetsCount int32
LatestTrendsOn int64
IsDel int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
}
type PWalletRecharge struct { type PWalletRecharge struct {
ID int64 ID int64
UserID int64 UserID int64

@ -28,7 +28,7 @@ func (q *Queries) DeleteComment(ctx context.Context, arg *DeleteCommentParams) e
} }
const getDefaultComments = `-- name: GetDefaultComments :many const getDefaultComments = `-- name: GetDefaultComments :many
SELECT id, post_id, user_id, ip, ip_loc, created_on, modified_on, deleted_on, is_del, thumbs_up_count, thumbs_down_count FROM p_comment WHERE post_id=$1 AND is_del=0 ORDER BY id ASC LIMIT $2 OFFSET $3 SELECT id, post_id, user_id, ip, ip_loc, created_on, modified_on, deleted_on, is_del, thumbs_up_count, thumbs_down_count, is_essence, reply_count FROM p_comment WHERE post_id=$1 AND is_del=0 ORDER BY id ASC LIMIT $2 OFFSET $3
` `
type GetDefaultCommentsParams struct { type GetDefaultCommentsParams struct {
@ -58,6 +58,8 @@ func (q *Queries) GetDefaultComments(ctx context.Context, arg *GetDefaultComment
&i.IsDel, &i.IsDel,
&i.ThumbsUpCount, &i.ThumbsUpCount,
&i.ThumbsDownCount, &i.ThumbsDownCount,
&i.IsEssence,
&i.ReplyCount,
); err != nil { ); err != nil {
return nil, err return nil, err
} }
@ -71,7 +73,7 @@ func (q *Queries) GetDefaultComments(ctx context.Context, arg *GetDefaultComment
const getNewestComments = `-- name: GetNewestComments :many const getNewestComments = `-- name: GetNewestComments :many
SELECT id, post_id, user_id, ip, ip_loc, created_on, modified_on, deleted_on, is_del, thumbs_up_count, thumbs_down_count FROM p_comment WHERE post_id=$1 AND is_del=0 ORDER BY id DESC LIMIT $2 OFFSET $3 SELECT id, post_id, user_id, ip, ip_loc, created_on, modified_on, deleted_on, is_del, thumbs_up_count, thumbs_down_count, is_essence, reply_count FROM p_comment WHERE post_id=$1 AND is_del=0 ORDER BY id DESC LIMIT $2 OFFSET $3
` `
type GetNewestCommentsParams struct { type GetNewestCommentsParams struct {
@ -104,6 +106,8 @@ func (q *Queries) GetNewestComments(ctx context.Context, arg *GetNewestCommentsP
&i.IsDel, &i.IsDel,
&i.ThumbsUpCount, &i.ThumbsUpCount,
&i.ThumbsDownCount, &i.ThumbsDownCount,
&i.IsEssence,
&i.ReplyCount,
); err != nil { ); err != nil {
return nil, err return nil, err
} }

@ -46,6 +46,8 @@ type PComment struct {
IsDel int16 IsDel int16
ThumbsUpCount int32 ThumbsUpCount int32
ThumbsDownCount int32 ThumbsDownCount int32
IsEssence int16
ReplyCount int32
} }
type PCommentContent struct { type PCommentContent struct {
@ -61,6 +63,19 @@ type PCommentContent struct {
IsDel int16 IsDel int16
} }
type PCommentMetric struct {
ID int64
CommentID int64
RankScore int64
IncentiveScore int32
DecayFactor int32
MotivationFactor int32
IsDel int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
}
type PCommentReply struct { type PCommentReply struct {
ID int64 ID int64
CommentID int64 CommentID int64
@ -231,6 +246,19 @@ type PPostContent struct {
IsDel int16 IsDel int16
} }
type PPostMetric struct {
ID int64
PostID int64
RankScore int64
IncentiveScore int32
DecayFactor int32
MotivationFactor int32
IsDel int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
}
type PPostStar struct { type PPostStar struct {
ID int64 ID int64
PostID int64 PostID int64
@ -300,6 +328,17 @@ type PUser struct {
IsDel int16 IsDel int16
} }
type PUserMetric struct {
ID int64
UserID int64
TweetsCount int32
LatestTrendsOn int64
IsDel int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
}
type PWalletRecharge struct { type PWalletRecharge struct {
ID int64 ID int64
UserID int64 UserID int64

@ -37,22 +37,6 @@ func (q *Queries) BeFriendIds(ctx context.Context, friendID int64) ([]int64, err
return items, nil return items, nil
} }
const isFriend = `-- name: IsFriend :one
SELECT status FROM p_contact WHERE user_id=$1 AND friend_id=$2 AND is_del=0
`
type IsFriendParams struct {
UserID int64
FriendID int64
}
func (q *Queries) IsFriend(ctx context.Context, arg *IsFriendParams) (int16, error) {
row := q.db.QueryRow(ctx, isFriend, arg.UserID, arg.FriendID)
var status int16
err := row.Scan(&status)
return status, err
}
const myFriendSet = `-- name: MyFriendSet :many const myFriendSet = `-- name: MyFriendSet :many
SELECT friend_id FROM p_contact WHERE user_id=$1 AND status=2 AND is_del=0 SELECT friend_id FROM p_contact WHERE user_id=$1 AND status=2 AND is_del=0
` `

@ -7,8 +7,148 @@ package pgc
import ( import (
"context" "context"
"github.com/jackc/pgx/v5/pgtype"
) )
const createComment = `-- name: CreateComment :one
INSERT INTO p_comment (post_id, user_id, ip, ip_loc, created_on)
VALUES ($1, $2, $3, $4, $5)
RETURNING id
`
type CreateCommentParams struct {
PostID int64
UserID int64
Ip string
IpLoc string
CreatedOn int64
}
func (q *Queries) CreateComment(ctx context.Context, arg *CreateCommentParams) (int64, error) {
row := q.db.QueryRow(ctx, createComment,
arg.PostID,
arg.UserID,
arg.Ip,
arg.IpLoc,
arg.CreatedOn,
)
var id int64
err := row.Scan(&id)
return id, err
}
const createCommentContent = `-- name: CreateCommentContent :one
INSERT INTO p_comment_content (comment_id, user_id, content, type, sort, created_on)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id
`
type CreateCommentContentParams struct {
CommentID int64
UserID int64
Content string
Type int16
Sort int64
CreatedOn int64
}
func (q *Queries) CreateCommentContent(ctx context.Context, arg *CreateCommentContentParams) (int64, error) {
row := q.db.QueryRow(ctx, createCommentContent,
arg.CommentID,
arg.UserID,
arg.Content,
arg.Type,
arg.Sort,
arg.CreatedOn,
)
var id int64
err := row.Scan(&id)
return id, err
}
const createCommentReply = `-- name: CreateCommentReply :one
INSERT INTO p_comment_reply (comment_id, user_id, content, at_user_id, ip, ip_loc, created_on)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id
`
type CreateCommentReplyParams struct {
CommentID int64
UserID int64
Content string
AtUserID int64
Ip string
IpLoc string
CreatedOn int64
}
func (q *Queries) CreateCommentReply(ctx context.Context, arg *CreateCommentReplyParams) (int64, error) {
row := q.db.QueryRow(ctx, createCommentReply,
arg.CommentID,
arg.UserID,
arg.Content,
arg.AtUserID,
arg.Ip,
arg.IpLoc,
arg.CreatedOn,
)
var id int64
err := row.Scan(&id)
return id, err
}
const createThumbsUpDownComment = `-- name: CreateThumbsUpDownComment :one
INSERT INTO p_tweet_comment_thumbs (user_id, tweet_id, comment_id,
reply_id, is_thumbs_up, is_thumbs_down, comment_type, created_on)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING id
`
type CreateThumbsUpDownCommentParams struct {
UserID int64
TweetID int64
CommentID int64
ReplyID pgtype.Int8
IsThumbsUp int16
IsThumbsDown int16
CommentType int16
CreatedOn int64
}
func (q *Queries) CreateThumbsUpDownComment(ctx context.Context, arg *CreateThumbsUpDownCommentParams) (int64, error) {
row := q.db.QueryRow(ctx, createThumbsUpDownComment,
arg.UserID,
arg.TweetID,
arg.CommentID,
arg.ReplyID,
arg.IsThumbsUp,
arg.IsThumbsDown,
arg.CommentType,
arg.CreatedOn,
)
var id int64
err := row.Scan(&id)
return id, err
}
const decrCommentReplyCount = `-- name: DecrCommentReplyCount :exec
UPDATE p_comment
SET reply_count=reply_count-1,
modified_on=$1
WHERE id=$2 AND is_del=0
`
type DecrCommentReplyCountParams struct {
ModifiedOn int64
ID int64
}
func (q *Queries) DecrCommentReplyCount(ctx context.Context, arg *DecrCommentReplyCountParams) error {
_, err := q.db.Exec(ctx, decrCommentReplyCount, arg.ModifiedOn, arg.ID)
return err
}
const deleteComment = `-- name: DeleteComment :exec const deleteComment = `-- name: DeleteComment :exec
UPDATE p_comment SET deleted_on=$1, is_del=1 WHERE id=$2 AND is_del=0 UPDATE p_comment SET deleted_on=$1, is_del=1 WHERE id=$2 AND is_del=0
@ -27,8 +167,302 @@ func (q *Queries) DeleteComment(ctx context.Context, arg *DeleteCommentParams) e
return err return err
} }
const deleteCommentReply = `-- name: DeleteCommentReply :exec
UPDATE p_comment_reply SET deleted_on=$1, is_del=1 WHERE id=$2 AND is_del=0
`
type DeleteCommentReplyParams struct {
DeletedOn int64
ID int64
}
func (q *Queries) DeleteCommentReply(ctx context.Context, arg *DeleteCommentReplyParams) error {
_, err := q.db.Exec(ctx, deleteCommentReply, arg.DeletedOn, arg.ID)
return err
}
const deleteCommentThumbs = `-- name: DeleteCommentThumbs :exec
UPDATE p_tweet_comment_thumbs
SET deleted_on=$1, is_del=1
WHERE user_id=$2 AND tweet_id=$3 AND comment_id=$4 AND is_del=0
`
type DeleteCommentThumbsParams struct {
DeletedOn int64
UserID int64
TweetID int64
CommentID int64
}
func (q *Queries) DeleteCommentThumbs(ctx context.Context, arg *DeleteCommentThumbsParams) error {
_, err := q.db.Exec(ctx, deleteCommentThumbs,
arg.DeletedOn,
arg.UserID,
arg.TweetID,
arg.CommentID,
)
return err
}
const deleteReplyThumbs = `-- name: DeleteReplyThumbs :exec
UPDATE p_tweet_comment_thumbs
SET deleted_on=$1, is_del=1
WHERE user_id=$2 AND comment_id=$3 AND reply_id=$4 AND is_del=0
`
type DeleteReplyThumbsParams struct {
DeletedOn int64
UserID int64
CommentID int64
ReplyID pgtype.Int8
}
func (q *Queries) DeleteReplyThumbs(ctx context.Context, arg *DeleteReplyThumbsParams) error {
_, err := q.db.Exec(ctx, deleteReplyThumbs,
arg.DeletedOn,
arg.UserID,
arg.CommentID,
arg.ReplyID,
)
return err
}
const getCommentById = `-- name: GetCommentById :one
SELECT id, post_id, user_id, ip, ip_loc, created_on, modified_on, deleted_on, is_del, thumbs_up_count, thumbs_down_count, is_essence, reply_count FROM p_comment WHERE id=$1 AND is_del=0
`
func (q *Queries) GetCommentById(ctx context.Context, id int64) (*PComment, error) {
row := q.db.QueryRow(ctx, getCommentById, id)
var i PComment
err := row.Scan(
&i.ID,
&i.PostID,
&i.UserID,
&i.Ip,
&i.IpLoc,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
&i.ThumbsUpCount,
&i.ThumbsDownCount,
&i.IsEssence,
&i.ReplyCount,
)
return &i, err
}
const getCommentContentsByIds = `-- name: GetCommentContentsByIds :many
SELECT id, comment_id, user_id, content, type, sort, created_on, modified_on, deleted_on, is_del FROM p_comment_content WHERE comment_id = ANY($1::BIGINT[])
`
func (q *Queries) GetCommentContentsByIds(ctx context.Context, ids []int64) ([]*PCommentContent, error) {
rows, err := q.db.Query(ctx, getCommentContentsByIds, ids)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*PCommentContent
for rows.Next() {
var i PCommentContent
if err := rows.Scan(
&i.ID,
&i.CommentID,
&i.UserID,
&i.Content,
&i.Type,
&i.Sort,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getCommentCount = `-- name: GetCommentCount :one
SELECT count(*) FROM p_comment WHERE post_id=$1 AND is_del=0
`
func (q *Queries) GetCommentCount(ctx context.Context, postID int64) (int64, error) {
row := q.db.QueryRow(ctx, getCommentCount, postID)
var count int64
err := row.Scan(&count)
return count, err
}
const getCommentRepliesByIds = `-- name: GetCommentRepliesByIds :many
SELECT id, comment_id, user_id, at_user_id, content, ip, ip_loc, created_on, modified_on, deleted_on, is_del, thumbs_up_count, thumbs_down_count
FROM p_comment_reply
WHERE comment_id = ANY($1::BIGINT[])
ORDER BY id ASC
`
func (q *Queries) GetCommentRepliesByIds(ctx context.Context, ids []int64) ([]*PCommentReply, error) {
rows, err := q.db.Query(ctx, getCommentRepliesByIds, ids)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*PCommentReply
for rows.Next() {
var i PCommentReply
if err := rows.Scan(
&i.ID,
&i.CommentID,
&i.UserID,
&i.AtUserID,
&i.Content,
&i.Ip,
&i.IpLoc,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
&i.ThumbsUpCount,
&i.ThumbsDownCount,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getCommentReplyById = `-- name: GetCommentReplyById :one
SELECT id, comment_id, user_id, at_user_id, content, ip, ip_loc, created_on, modified_on, deleted_on, is_del, thumbs_up_count, thumbs_down_count FROM p_comment_reply WHERE id=$1 AND is_del=0
`
func (q *Queries) GetCommentReplyById(ctx context.Context, id int64) (*PCommentReply, error) {
row := q.db.QueryRow(ctx, getCommentReplyById, id)
var i PCommentReply
err := row.Scan(
&i.ID,
&i.CommentID,
&i.UserID,
&i.AtUserID,
&i.Content,
&i.Ip,
&i.IpLoc,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
&i.ThumbsUpCount,
&i.ThumbsDownCount,
)
return &i, err
}
const getCommentReplyThumb = `-- name: GetCommentReplyThumb :one
SELECT id, user_id, tweet_id, comment_id, reply_id, comment_type, is_thumbs_up, is_thumbs_down, created_on, modified_on, deleted_on, is_del
FROM p_tweet_comment_thumbs
WHERE user_id=$1 AND tweet_id=$2 AND comment_id=$3 AND reply_id=$4 AND comment_type=1 AND is_del=0
`
type GetCommentReplyThumbParams struct {
UserID int64
TweetID int64
CommentID int64
ReplyID pgtype.Int8
}
func (q *Queries) GetCommentReplyThumb(ctx context.Context, arg *GetCommentReplyThumbParams) (*PTweetCommentThumb, error) {
row := q.db.QueryRow(ctx, getCommentReplyThumb,
arg.UserID,
arg.TweetID,
arg.CommentID,
arg.ReplyID,
)
var i PTweetCommentThumb
err := row.Scan(
&i.ID,
&i.UserID,
&i.TweetID,
&i.CommentID,
&i.ReplyID,
&i.CommentType,
&i.IsThumbsUp,
&i.IsThumbsDown,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
)
return &i, err
}
const getCommentThumbs = `-- name: GetCommentThumbs :many
SELECT user_id,
tweet_id,
comment_id,
reply_id,
comment_type,
is_thumbs_up,
is_thumbs_down
FROM p_tweet_comment_thumbs
WHERE user_id=$1 AND tweet_id=$2
`
type GetCommentThumbsParams struct {
UserID int64
TweetID int64
}
type GetCommentThumbsRow struct {
UserID int64
TweetID int64
CommentID int64
ReplyID pgtype.Int8
CommentType int16
IsThumbsUp int16
IsThumbsDown int16
}
func (q *Queries) GetCommentThumbs(ctx context.Context, arg *GetCommentThumbsParams) ([]*GetCommentThumbsRow, error) {
rows, err := q.db.Query(ctx, getCommentThumbs, arg.UserID, arg.TweetID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*GetCommentThumbsRow
for rows.Next() {
var i GetCommentThumbsRow
if err := rows.Scan(
&i.UserID,
&i.TweetID,
&i.CommentID,
&i.ReplyID,
&i.CommentType,
&i.IsThumbsUp,
&i.IsThumbsDown,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getDefaultComments = `-- name: GetDefaultComments :many const getDefaultComments = `-- name: GetDefaultComments :many
SELECT id, post_id, user_id, ip, ip_loc, created_on, modified_on, deleted_on, is_del, thumbs_up_count, thumbs_down_count FROM p_comment WHERE post_id=$1 AND is_del=0 ORDER BY id ASC LIMIT $2 OFFSET $3 SELECT id, post_id, user_id, ip, ip_loc, created_on, modified_on, deleted_on, is_del, thumbs_up_count, thumbs_down_count, is_essence, reply_count
FROM p_comment
WHERE post_id=$1 AND is_del=0
ORDER BY is_essence DESC, id ASC
LIMIT $2 OFFSET $3
` `
type GetDefaultCommentsParams struct { type GetDefaultCommentsParams struct {
@ -58,6 +492,58 @@ func (q *Queries) GetDefaultComments(ctx context.Context, arg *GetDefaultComment
&i.IsDel, &i.IsDel,
&i.ThumbsUpCount, &i.ThumbsUpCount,
&i.ThumbsDownCount, &i.ThumbsDownCount,
&i.IsEssence,
&i.ReplyCount,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getHotsComments = `-- name: GetHotsComments :many
SELECT c.id, c.post_id, c.user_id, c.ip, c.ip_loc, c.created_on, c.modified_on, c.deleted_on, c.is_del, c.thumbs_up_count, c.thumbs_down_count, c.is_essence, c.reply_count
FROM p_comment c
LEFT JOIN p_comment_metric m
ON c.id=m.comment_id
WHERE c.post_id=$1 AND c.is_del=0 AND m.is_del=0
ORDER BY is_essence DESC, m.rank_score DESC, c.id DESC
LIMIT $2 OFFSET $3
`
type GetHotsCommentsParams struct {
PostID int64
Limit int32
Offset int32
}
func (q *Queries) GetHotsComments(ctx context.Context, arg *GetHotsCommentsParams) ([]*PComment, error) {
rows, err := q.db.Query(ctx, getHotsComments, arg.PostID, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*PComment
for rows.Next() {
var i PComment
if err := rows.Scan(
&i.ID,
&i.PostID,
&i.UserID,
&i.Ip,
&i.IpLoc,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
&i.ThumbsUpCount,
&i.ThumbsDownCount,
&i.IsEssence,
&i.ReplyCount,
); err != nil { ); err != nil {
return nil, err return nil, err
} }
@ -71,7 +557,11 @@ func (q *Queries) GetDefaultComments(ctx context.Context, arg *GetDefaultComment
const getNewestComments = `-- name: GetNewestComments :many const getNewestComments = `-- name: GetNewestComments :many
SELECT id, post_id, user_id, ip, ip_loc, created_on, modified_on, deleted_on, is_del, thumbs_up_count, thumbs_down_count FROM p_comment WHERE post_id=$1 AND is_del=0 ORDER BY id DESC LIMIT $2 OFFSET $3 SELECT id, post_id, user_id, ip, ip_loc, created_on, modified_on, deleted_on, is_del, thumbs_up_count, thumbs_down_count, is_essence, reply_count
FROM p_comment
WHERE post_id=$1 AND is_del=0
ORDER BY is_essence DESC, id DESC
LIMIT $2 OFFSET $3
` `
type GetNewestCommentsParams struct { type GetNewestCommentsParams struct {
@ -104,6 +594,8 @@ func (q *Queries) GetNewestComments(ctx context.Context, arg *GetNewestCommentsP
&i.IsDel, &i.IsDel,
&i.ThumbsUpCount, &i.ThumbsUpCount,
&i.ThumbsDownCount, &i.ThumbsDownCount,
&i.IsEssence,
&i.ReplyCount,
); err != nil { ); err != nil {
return nil, err return nil, err
} }
@ -114,3 +606,123 @@ func (q *Queries) GetNewestComments(ctx context.Context, arg *GetNewestCommentsP
} }
return items, nil return items, nil
} }
const getTweetCommentThumb = `-- name: GetTweetCommentThumb :one
SELECT id, user_id, tweet_id, comment_id, reply_id, comment_type, is_thumbs_up, is_thumbs_down, created_on, modified_on, deleted_on, is_del
FROM p_tweet_comment_thumbs
WHERE user_id=$1 AND tweet_id=$2 AND comment_id=$3 AND comment_type=0 AND is_del=0
`
type GetTweetCommentThumbParams struct {
UserID int64
TweetID int64
CommentID int64
}
func (q *Queries) GetTweetCommentThumb(ctx context.Context, arg *GetTweetCommentThumbParams) (*PTweetCommentThumb, error) {
row := q.db.QueryRow(ctx, getTweetCommentThumb, arg.UserID, arg.TweetID, arg.CommentID)
var i PTweetCommentThumb
err := row.Scan(
&i.ID,
&i.UserID,
&i.TweetID,
&i.CommentID,
&i.ReplyID,
&i.CommentType,
&i.IsThumbsUp,
&i.IsThumbsDown,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
)
return &i, err
}
const incrCommentReplyCount = `-- name: IncrCommentReplyCount :exec
UPDATE p_comment
SET reply_count=reply_count+1,
modified_on=$1
WHERE id=$2 AND is_del=0
`
type IncrCommentReplyCountParams struct {
ModifiedOn int64
ID int64
}
func (q *Queries) IncrCommentReplyCount(ctx context.Context, arg *IncrCommentReplyCountParams) error {
_, err := q.db.Exec(ctx, incrCommentReplyCount, arg.ModifiedOn, arg.ID)
return err
}
const updateCommentThumbsCount = `-- name: UpdateCommentThumbsCount :exec
UPDATE p_comment
SET thumbs_up_count=$1, Thumbs_down_count=$2, modified_on=$3
WHERE id=$4 AND is_del=0
`
type UpdateCommentThumbsCountParams struct {
ThumbsUpCount int32
ThumbsDownCount int32
ModifiedOn int64
ID int64
}
func (q *Queries) UpdateCommentThumbsCount(ctx context.Context, arg *UpdateCommentThumbsCountParams) error {
_, err := q.db.Exec(ctx, updateCommentThumbsCount,
arg.ThumbsUpCount,
arg.ThumbsDownCount,
arg.ModifiedOn,
arg.ID,
)
return err
}
const updateReplyThumbsCount = `-- name: UpdateReplyThumbsCount :exec
UPDATE p_comment_reply
SET thumbs_up_count=$1, thumbs_down_count=$2, modified_on=$3
WHERE id=$4 AND is_del=0
`
type UpdateReplyThumbsCountParams struct {
ThumbsUpCount int32
ThumbsDownCount int32
ModifiedOn int64
ID int64
}
func (q *Queries) UpdateReplyThumbsCount(ctx context.Context, arg *UpdateReplyThumbsCountParams) error {
_, err := q.db.Exec(ctx, updateReplyThumbsCount,
arg.ThumbsUpCount,
arg.ThumbsDownCount,
arg.ModifiedOn,
arg.ID,
)
return err
}
const updateThumbsUpDownComment = `-- name: UpdateThumbsUpDownComment :exec
UPDATE p_tweet_comment_thumbs
SET is_thumbs_up=$1,
is_thumbs_down=$2,
modified_on=$3
WHERE id=$4 AND is_del=0
`
type UpdateThumbsUpDownCommentParams struct {
IsThumbsUp int16
IsThumbsDown int16
ModifiedOn int64
ID int64
}
func (q *Queries) UpdateThumbsUpDownComment(ctx context.Context, arg *UpdateThumbsUpDownCommentParams) error {
_, err := q.db.Exec(ctx, updateThumbsUpDownComment,
arg.IsThumbsUp,
arg.IsThumbsDown,
arg.ModifiedOn,
arg.ID,
)
return err
}

@ -9,6 +9,46 @@ import (
"context" "context"
) )
const addFriendMsgsUpdate = `-- name: AddFriendMsgsUpdate :exec
UPDATE p_message
SET reply_id=$1, modified_on=$2
WHERE ((sender_user_id = $3 AND receiver_user_id = $4) OR
(sender_user_id = $4 AND receiver_user_id = $3)) AND
type = $5 AND reply_id = $6
`
type AddFriendMsgsUpdateParams struct {
ReplyID int64
ModifiedOn int64
SenderUserID int64
ReceiverUserID int64
Type int16
ReplyID_2 int64
}
func (q *Queries) AddFriendMsgsUpdate(ctx context.Context, arg *AddFriendMsgsUpdateParams) error {
_, err := q.db.Exec(ctx, addFriendMsgsUpdate,
arg.ReplyID,
arg.ModifiedOn,
arg.SenderUserID,
arg.ReceiverUserID,
arg.Type,
arg.ReplyID_2,
)
return err
}
const countFriendsById = `-- name: CountFriendsById :one
SELECT count(*) FROM p_contact WHERE user_id=$1 AND status=2 AND is_del=0
`
func (q *Queries) CountFriendsById(ctx context.Context, userID int64) (int64, error) {
row := q.db.QueryRow(ctx, countFriendsById, userID)
var count int64
err := row.Scan(&count)
return count, err
}
const createContact = `-- name: CreateContact :exec const createContact = `-- name: CreateContact :exec
INSERT INTO p_contact (user_id, friend_id, status, created_on) VALUES ($1, $2, $3, $4) INSERT INTO p_contact (user_id, friend_id, status, created_on) VALUES ($1, $2, $3, $4)
@ -33,3 +73,306 @@ func (q *Queries) CreateContact(ctx context.Context, arg *CreateContactParams) e
) )
return err return err
} }
const createMessage = `-- name: CreateMessage :one
INSERT INTO p_message (sender_user_id, receiver_user_id, type, brief, content, reply_id, created_on)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id
`
type CreateMessageParams struct {
SenderUserID int64
ReceiverUserID int64
Type int16
Brief string
Content string
ReplyID int64
CreatedOn int64
}
func (q *Queries) CreateMessage(ctx context.Context, arg *CreateMessageParams) (int64, error) {
row := q.db.QueryRow(ctx, createMessage,
arg.SenderUserID,
arg.ReceiverUserID,
arg.Type,
arg.Brief,
arg.Content,
arg.ReplyID,
arg.CreatedOn,
)
var id int64
err := row.Scan(&id)
return id, err
}
const deleteFriend = `-- name: DeleteFriend :exec
UPDATE p_contact SET status=4, is_del=1, deleted_on=$1 WHERE id=$2
`
type DeleteFriendParams struct {
DeletedOn int64
ID int64
}
func (q *Queries) DeleteFriend(ctx context.Context, arg *DeleteFriendParams) error {
_, err := q.db.Exec(ctx, deleteFriend, arg.DeletedOn, arg.ID)
return err
}
const freshContactStatus = `-- name: FreshContactStatus :exec
UPDATE p_contact SET status=$1, modified_on=$2, is_del=0 WHERE id=$3
`
type FreshContactStatusParams struct {
Status int16
ModifiedOn int64
ID int64
}
func (q *Queries) FreshContactStatus(ctx context.Context, arg *FreshContactStatusParams) error {
_, err := q.db.Exec(ctx, freshContactStatus, arg.Status, arg.ModifiedOn, arg.ID)
return err
}
const getContact = `-- name: GetContact :one
SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del
FROM p_contact
WHERE user_id=$1 AND friend_id=$2
`
type GetContactParams struct {
UserID int64
FriendID int64
}
type GetContactRow struct {
ID int64
UserID int64
FriendID int64
GroupID int64
Remark string
Status int16
IsTop int16
IsBlack int16
NoticeEnable int16
IsDel int16
}
func (q *Queries) GetContact(ctx context.Context, arg *GetContactParams) (*GetContactRow, error) {
row := q.db.QueryRow(ctx, getContact, arg.UserID, arg.FriendID)
var i GetContactRow
err := row.Scan(
&i.ID,
&i.UserID,
&i.FriendID,
&i.GroupID,
&i.Remark,
&i.Status,
&i.IsTop,
&i.IsBlack,
&i.NoticeEnable,
&i.IsDel,
)
return &i, err
}
const getContacts = `-- name: GetContacts :many
SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del
FROM p_contact
WHERE (user_id=$1 AND friend_id=$2) OR (user_id=$3 AND friend_id=$4)
`
type GetContactsParams struct {
UserID int64
FriendID int64
UserID_2 int64
FriendID_2 int64
}
type GetContactsRow struct {
ID int64
UserID int64
FriendID int64
GroupID int64
Remark string
Status int16
IsTop int16
IsBlack int16
NoticeEnable int16
IsDel int16
}
func (q *Queries) GetContacts(ctx context.Context, arg *GetContactsParams) ([]*GetContactsRow, error) {
rows, err := q.db.Query(ctx, getContacts,
arg.UserID,
arg.FriendID,
arg.UserID_2,
arg.FriendID_2,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*GetContactsRow
for rows.Next() {
var i GetContactsRow
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.FriendID,
&i.GroupID,
&i.Remark,
&i.Status,
&i.IsTop,
&i.IsBlack,
&i.NoticeEnable,
&i.IsDel,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getUserFriend = `-- name: GetUserFriend :one
SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del
FROM p_contact
WHERE user_id=$1 AND friend_id=$2 AND is_del=0
`
type GetUserFriendParams struct {
UserID int64
FriendID int64
}
type GetUserFriendRow struct {
ID int64
UserID int64
FriendID int64
GroupID int64
Remark string
Status int16
IsTop int16
IsBlack int16
NoticeEnable int16
IsDel int16
}
func (q *Queries) GetUserFriend(ctx context.Context, arg *GetUserFriendParams) (*GetUserFriendRow, error) {
row := q.db.QueryRow(ctx, getUserFriend, arg.UserID, arg.FriendID)
var i GetUserFriendRow
err := row.Scan(
&i.ID,
&i.UserID,
&i.FriendID,
&i.GroupID,
&i.Remark,
&i.Status,
&i.IsTop,
&i.IsBlack,
&i.NoticeEnable,
&i.IsDel,
)
return &i, err
}
const isFriend = `-- name: IsFriend :one
SELECT true FROM p_contact WHERE user_id=$1 AND friend_id=$2 AND is_del=0 AND status=2
`
type IsFriendParams struct {
UserID int64
FriendID int64
}
func (q *Queries) IsFriend(ctx context.Context, arg *IsFriendParams) (bool, error) {
row := q.db.QueryRow(ctx, isFriend, arg.UserID, arg.FriendID)
var column_1 bool
err := row.Scan(&column_1)
return column_1, err
}
const listFriend = `-- name: ListFriend :many
SELECT c.friend_id user_id,
u.username username,
u.nickname nickname,
u.avatar avatar,
u.phone phone
FROM p_contact c
JOIN p_user u
ON c.friend_id=u.id
WHERE c.user_id=$1 AND c.status=2 AND c.is_del=0
ORDER BY u.nickname ASC
LIMIT $2 OFFSET $3
`
type ListFriendParams struct {
UserID int64
Limit int32
Offset int32
}
type ListFriendRow struct {
UserID int64
Username string
Nickname string
Avatar string
Phone string
}
func (q *Queries) ListFriend(ctx context.Context, arg *ListFriendParams) ([]*ListFriendRow, error) {
rows, err := q.db.Query(ctx, listFriend, arg.UserID, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*ListFriendRow
for rows.Next() {
var i ListFriendRow
if err := rows.Scan(
&i.UserID,
&i.Username,
&i.Nickname,
&i.Avatar,
&i.Phone,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const rejectFriendMsgsUpdate = `-- name: RejectFriendMsgsUpdate :exec
UPDATE p_message
SET reply_id=$1, modified_on=$2
WHERE sender_user_id=$3 AND receiver_user_id=$4 AND type=$5 AND reply_id=$6
`
type RejectFriendMsgsUpdateParams struct {
ReplyID int64
ModifiedOn int64
SenderUserID int64
ReceiverUserID int64
Type int16
ReplyID_2 int64
}
func (q *Queries) RejectFriendMsgsUpdate(ctx context.Context, arg *RejectFriendMsgsUpdateParams) error {
_, err := q.db.Exec(ctx, rejectFriendMsgsUpdate,
arg.ReplyID,
arg.ModifiedOn,
arg.SenderUserID,
arg.ReceiverUserID,
arg.Type,
arg.ReplyID_2,
)
return err
}

@ -9,9 +9,33 @@ import (
"context" "context"
) )
const countFollowings = `-- name: CountFollowings :one
SELECT count(*) FROM p_following WHERE follow_id=$1 AND is_del=0
`
func (q *Queries) CountFollowings(ctx context.Context, followID int64) (int64, error) {
row := q.db.QueryRow(ctx, countFollowings, followID)
var count int64
err := row.Scan(&count)
return count, err
}
const countFollows = `-- name: CountFollows :one
SELECT count(*) FROM p_following WHERE user_id=$1 AND is_del=0
`
func (q *Queries) CountFollows(ctx context.Context, userID int64) (int64, error) {
row := q.db.QueryRow(ctx, countFollows, userID)
var count int64
err := row.Scan(&count)
return count, err
}
const createFollowing = `-- name: CreateFollowing :exec const createFollowing = `-- name: CreateFollowing :exec
INSERT INTO p_following (user_id, follow_id, created_on) VALUES ($1, $2, $3) INSERT INTO p_following (user_id, follow_id, created_on)
VALUES ($1, $2, $3)
RETURNING id
` `
type CreateFollowingParams struct { type CreateFollowingParams struct {
@ -27,3 +51,140 @@ func (q *Queries) CreateFollowing(ctx context.Context, arg *CreateFollowingParam
_, err := q.db.Exec(ctx, createFollowing, arg.UserID, arg.FollowID, arg.CreatedOn) _, err := q.db.Exec(ctx, createFollowing, arg.UserID, arg.FollowID, arg.CreatedOn)
return err return err
} }
const deleteFollowing = `-- name: DeleteFollowing :exec
UPDATE p_following
SET is_del=1, deleted_on=$1
WHERE user_id=$2 AND follow_id=$3 AND is_del=0
`
type DeleteFollowingParams struct {
DeletedOn int64
UserID int64
FollowID int64
}
func (q *Queries) DeleteFollowing(ctx context.Context, arg *DeleteFollowingParams) error {
_, err := q.db.Exec(ctx, deleteFollowing, arg.DeletedOn, arg.UserID, arg.FollowID)
return err
}
const existFollowing = `-- name: ExistFollowing :one
SELECT 1 FROM p_following WHERE user_id=$1 AND follow_id=$2 AND is_del=0
`
type ExistFollowingParams struct {
UserID int64
FollowID int64
}
func (q *Queries) ExistFollowing(ctx context.Context, arg *ExistFollowingParams) (int32, error) {
row := q.db.QueryRow(ctx, existFollowing, arg.UserID, arg.FollowID)
var column_1 int32
err := row.Scan(&column_1)
return column_1, err
}
const listFollowings = `-- name: ListFollowings :many
SELECT u.id user_id,
u.username username,
u.nickname nickname,
u.avatar avatar,
u.created_on created_on
FROM p_following f JOIN p_user u ON f.user_id=u.id
WHERE f.follow_id=$1 AND f.is_del=0
ORDER BY u.nickname ASC
LIMIT $2 OFFSET $3
`
type ListFollowingsParams struct {
FollowID int64
Limit int32
Offset int32
}
type ListFollowingsRow struct {
UserID int64
Username string
Nickname string
Avatar string
CreatedOn int64
}
func (q *Queries) ListFollowings(ctx context.Context, arg *ListFollowingsParams) ([]*ListFollowingsRow, error) {
rows, err := q.db.Query(ctx, listFollowings, arg.FollowID, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*ListFollowingsRow
for rows.Next() {
var i ListFollowingsRow
if err := rows.Scan(
&i.UserID,
&i.Username,
&i.Nickname,
&i.Avatar,
&i.CreatedOn,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listFollows = `-- name: ListFollows :many
SELECT u.id user_id,
u.username username,
u.nickname nickname,
u.avatar avatar,
u.created_on created_on
FROM p_following f JOIN p_user u ON f.follow_id=u.id
WHERE f.user_id=$1 AND f.is_del=0
ORDER BY u.nickname ASC
LIMIT $2 OFFSET $3
`
type ListFollowsParams struct {
UserID int64
Limit int32
Offset int32
}
type ListFollowsRow struct {
UserID int64
Username string
Nickname string
Avatar string
CreatedOn int64
}
func (q *Queries) ListFollows(ctx context.Context, arg *ListFollowsParams) ([]*ListFollowsRow, error) {
rows, err := q.db.Query(ctx, listFollows, arg.UserID, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*ListFollowsRow
for rows.Next() {
var i ListFollowsRow
if err := rows.Scan(
&i.UserID,
&i.Username,
&i.Nickname,
&i.Avatar,
&i.CreatedOn,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}

@ -9,6 +9,260 @@ import (
"context" "context"
) )
const countAllMessages = `-- name: CountAllMessages :one
SELECT count(*)
FROM p_message
WHERE (receiver_user_id=$1 OR (sender_user_id=$2 AND type=4)) AND is_del=0
`
type CountAllMessagesParams struct {
ReceiverUserID int64
SenderUserID int64
}
func (q *Queries) CountAllMessages(ctx context.Context, arg *CountAllMessagesParams) (int64, error) {
row := q.db.QueryRow(ctx, countAllMessages, arg.ReceiverUserID, arg.SenderUserID)
var count int64
err := row.Scan(&count)
return count, err
}
const countRequestingMessages = `-- name: CountRequestingMessages :one
SELECT count(*)
FROM p_message
WHERE receiver_user_id=$1 AND type=5 AND is_del=0
`
func (q *Queries) CountRequestingMessages(ctx context.Context, receiverUserID int64) (int64, error) {
row := q.db.QueryRow(ctx, countRequestingMessages, receiverUserID)
var count int64
err := row.Scan(&count)
return count, err
}
const countSystemMessages = `-- name: CountSystemMessages :one
SELECT count(*)
FROM p_message
WHERE receiver_user_id=$1 AND type IN (1, 2, 3, 99) AND is_del=0
`
func (q *Queries) CountSystemMessages(ctx context.Context, receiverUserID int64) (int64, error) {
row := q.db.QueryRow(ctx, countSystemMessages, receiverUserID)
var count int64
err := row.Scan(&count)
return count, err
}
const countUnreadMessages = `-- name: CountUnreadMessages :one
SELECT count(*)
FROM p_message
WHERE receiver_user_id=$1 AND is_read=0 AND is_del=0
`
func (q *Queries) CountUnreadMessages(ctx context.Context, receiverUserID int64) (int64, error) {
row := q.db.QueryRow(ctx, countUnreadMessages, receiverUserID)
var count int64
err := row.Scan(&count)
return count, err
}
const countWhisperMessages = `-- name: CountWhisperMessages :one
SELECT count(*)
FROM p_message
WHERE ((receiver_user_id=$1 OR sender_user_id=$2) AND type=4) AND is_del=0
`
type CountWhisperMessagesParams struct {
ReceiverUserID int64
SenderUserID int64
}
func (q *Queries) CountWhisperMessages(ctx context.Context, arg *CountWhisperMessagesParams) (int64, error) {
row := q.db.QueryRow(ctx, countWhisperMessages, arg.ReceiverUserID, arg.SenderUserID)
var count int64
err := row.Scan(&count)
return count, err
}
const getAllMessages = `-- name: GetAllMessages :many
SELECT id, sender_user_id, receiver_user_id, type, brief, content, post_id, comment_id, reply_id, is_read, created_on, modified_on, deleted_on, is_del
FROM p_message
WHERE (receiver_user_id=$1 OR (sender_user_id=$2 AND type=4)) AND is_del=0
ORDER BY id DESC
LIMIT $3 OFFSET $4
`
type GetAllMessagesParams struct {
ReceiverUserID int64
SenderUserID int64
Limit int32
Offset int32
}
func (q *Queries) GetAllMessages(ctx context.Context, arg *GetAllMessagesParams) ([]*PMessage, error) {
rows, err := q.db.Query(ctx, getAllMessages,
arg.ReceiverUserID,
arg.SenderUserID,
arg.Limit,
arg.Offset,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*PMessage
for rows.Next() {
var i PMessage
if err := rows.Scan(
&i.ID,
&i.SenderUserID,
&i.ReceiverUserID,
&i.Type,
&i.Brief,
&i.Content,
&i.PostID,
&i.CommentID,
&i.ReplyID,
&i.IsRead,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getMessageById = `-- name: GetMessageById :one
SELECT id, sender_user_id, receiver_user_id, type, brief, content, post_id, comment_id, reply_id, is_read, created_on, modified_on, deleted_on, is_del FROM p_message WHERE id=$1 AND is_del=0
`
func (q *Queries) GetMessageById(ctx context.Context, id int64) (*PMessage, error) {
row := q.db.QueryRow(ctx, getMessageById, id)
var i PMessage
err := row.Scan(
&i.ID,
&i.SenderUserID,
&i.ReceiverUserID,
&i.Type,
&i.Brief,
&i.Content,
&i.PostID,
&i.CommentID,
&i.ReplyID,
&i.IsRead,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
)
return &i, err
}
const getRequestingMessages = `-- name: GetRequestingMessages :many
SELECT id, sender_user_id, receiver_user_id, type, brief, content, post_id, comment_id, reply_id, is_read, created_on, modified_on, deleted_on, is_del
FROM p_message
WHERE receiver_user_id=$1 AND type=5 AND is_del=0
ORDER BY id DESC
LIMIT $2 OFFSET $3
`
type GetRequestingMessagesParams struct {
ReceiverUserID int64
Limit int32
Offset int32
}
func (q *Queries) GetRequestingMessages(ctx context.Context, arg *GetRequestingMessagesParams) ([]*PMessage, error) {
rows, err := q.db.Query(ctx, getRequestingMessages, arg.ReceiverUserID, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*PMessage
for rows.Next() {
var i PMessage
if err := rows.Scan(
&i.ID,
&i.SenderUserID,
&i.ReceiverUserID,
&i.Type,
&i.Brief,
&i.Content,
&i.PostID,
&i.CommentID,
&i.ReplyID,
&i.IsRead,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getSystemMessages = `-- name: GetSystemMessages :many
SELECT id, sender_user_id, receiver_user_id, type, brief, content, post_id, comment_id, reply_id, is_read, created_on, modified_on, deleted_on, is_del
FROM p_message
WHERE receiver_user_id=$1 AND type IN (1, 2, 3, 99) AND is_del=0
ORDER BY id DESC
LIMIT $2 OFFSET $3
`
type GetSystemMessagesParams struct {
ReceiverUserID int64
Limit int32
Offset int32
}
func (q *Queries) GetSystemMessages(ctx context.Context, arg *GetSystemMessagesParams) ([]*PMessage, error) {
rows, err := q.db.Query(ctx, getSystemMessages, arg.ReceiverUserID, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*PMessage
for rows.Next() {
var i PMessage
if err := rows.Scan(
&i.ID,
&i.SenderUserID,
&i.ReceiverUserID,
&i.Type,
&i.Brief,
&i.Content,
&i.PostID,
&i.CommentID,
&i.ReplyID,
&i.IsRead,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getUnreadCount = `-- name: GetUnreadCount :one const getUnreadCount = `-- name: GetUnreadCount :one
SELECT count(*) FROM p_message WHERE receiver_user_id=$1 AND is_read=0 AND is_del=0 SELECT count(*) FROM p_message WHERE receiver_user_id=$1 AND is_read=0 AND is_del=0
@ -23,3 +277,135 @@ func (q *Queries) GetUnreadCount(ctx context.Context, receiverUserID int64) (int
err := row.Scan(&count) err := row.Scan(&count)
return count, err return count, err
} }
const getUnreadMessages = `-- name: GetUnreadMessages :many
SELECT id, sender_user_id, receiver_user_id, type, brief, content, post_id, comment_id, reply_id, is_read, created_on, modified_on, deleted_on, is_del
FROM p_message
WHERE receiver_user_id=$1 AND is_read=0 AND is_del=0
ORDER BY id DESC
LIMIT $2 OFFSET $3
`
type GetUnreadMessagesParams struct {
ReceiverUserID int64
Limit int32
Offset int32
}
func (q *Queries) GetUnreadMessages(ctx context.Context, arg *GetUnreadMessagesParams) ([]*PMessage, error) {
rows, err := q.db.Query(ctx, getUnreadMessages, arg.ReceiverUserID, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*PMessage
for rows.Next() {
var i PMessage
if err := rows.Scan(
&i.ID,
&i.SenderUserID,
&i.ReceiverUserID,
&i.Type,
&i.Brief,
&i.Content,
&i.PostID,
&i.CommentID,
&i.ReplyID,
&i.IsRead,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getWhisperMessages = `-- name: GetWhisperMessages :many
SELECT id, sender_user_id, receiver_user_id, type, brief, content, post_id, comment_id, reply_id, is_read, created_on, modified_on, deleted_on, is_del
FROM p_message
WHERE ((receiver_user_id=$1 OR sender_user_id=$2) AND type=4) AND is_del=0
ORDER BY id DESC
LIMIT $3 OFFSET $4
`
type GetWhisperMessagesParams struct {
ReceiverUserID int64
SenderUserID int64
Limit int32
Offset int32
}
func (q *Queries) GetWhisperMessages(ctx context.Context, arg *GetWhisperMessagesParams) ([]*PMessage, error) {
rows, err := q.db.Query(ctx, getWhisperMessages,
arg.ReceiverUserID,
arg.SenderUserID,
arg.Limit,
arg.Offset,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*PMessage
for rows.Next() {
var i PMessage
if err := rows.Scan(
&i.ID,
&i.SenderUserID,
&i.ReceiverUserID,
&i.Type,
&i.Brief,
&i.Content,
&i.PostID,
&i.CommentID,
&i.ReplyID,
&i.IsRead,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const readAllMessage = `-- name: ReadAllMessage :exec
UPDATE p_message SET is_read=1, modified_on=$1 WHERE receiver_user_id=$2
`
type ReadAllMessageParams struct {
ModifiedOn int64
ReceiverUserID int64
}
func (q *Queries) ReadAllMessage(ctx context.Context, arg *ReadAllMessageParams) error {
_, err := q.db.Exec(ctx, readAllMessage, arg.ModifiedOn, arg.ReceiverUserID)
return err
}
const readMessage = `-- name: ReadMessage :exec
UPDATE p_message SET is_read=1, modified_on=$1 WHERE id=$2
`
type ReadMessageParams struct {
ModifiedOn int64
ID int64
}
func (q *Queries) ReadMessage(ctx context.Context, arg *ReadMessageParams) error {
_, err := q.db.Exec(ctx, readMessage, arg.ModifiedOn, arg.ID)
return err
}

@ -0,0 +1,226 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.21.0
// source: metrics.sql
package pgc
import (
"context"
)
const addCommentMetric = `-- name: AddCommentMetric :one
INSERT INTO p_comment_metric (comment_id, created_on)
VALUES ($1, $2)
RETURNING id
`
type AddCommentMetricParams struct {
CommentID int64
CreatedOn int64
}
func (q *Queries) AddCommentMetric(ctx context.Context, arg *AddCommentMetricParams) (int64, error) {
row := q.db.QueryRow(ctx, addCommentMetric, arg.CommentID, arg.CreatedOn)
var id int64
err := row.Scan(&id)
return id, err
}
const addTweetMetric = `-- name: AddTweetMetric :one
INSERT INTO p_post_metric (post_id, created_on)
VALUES ($1, $2)
RETURNING id
`
type AddTweetMetricParams struct {
PostID int64
CreatedOn int64
}
func (q *Queries) AddTweetMetric(ctx context.Context, arg *AddTweetMetricParams) (int64, error) {
row := q.db.QueryRow(ctx, addTweetMetric, arg.PostID, arg.CreatedOn)
var id int64
err := row.Scan(&id)
return id, err
}
const addUserMetric = `-- name: AddUserMetric :one
INSERT INTO p_user_metric (user_id, created_on) VALUES ($1, $2) RETURNING id
`
type AddUserMetricParams struct {
UserID int64
CreatedOn int64
}
func (q *Queries) AddUserMetric(ctx context.Context, arg *AddUserMetricParams) (int64, error) {
row := q.db.QueryRow(ctx, addUserMetric, arg.UserID, arg.CreatedOn)
var id int64
err := row.Scan(&id)
return id, err
}
const commentMotivationFactor = `-- name: CommentMotivationFactor :one
SELECT motivation_factor FROM p_comment_metric WHERE comment_id=$1 AND is_del=0
`
func (q *Queries) CommentMotivationFactor(ctx context.Context, commentID int64) (int32, error) {
row := q.db.QueryRow(ctx, commentMotivationFactor, commentID)
var motivation_factor int32
err := row.Scan(&motivation_factor)
return motivation_factor, err
}
const deleteCommentMetric = `-- name: DeleteCommentMetric :exec
UPDATE p_comment_metric SET is_del=1, deleted_on=$1 WHERE comment_id=$2 AND is_del=0
`
type DeleteCommentMetricParams struct {
DeletedOn int64
CommentID int64
}
func (q *Queries) DeleteCommentMetric(ctx context.Context, arg *DeleteCommentMetricParams) error {
_, err := q.db.Exec(ctx, deleteCommentMetric, arg.DeletedOn, arg.CommentID)
return err
}
const deleteTweetMetric = `-- name: DeleteTweetMetric :exec
UPDATE p_post_metric SET is_del=1, deleted_on=$1 WHERE post_id=$2 AND is_del=0
`
type DeleteTweetMetricParams struct {
DeletedOn int64
PostID int64
}
func (q *Queries) DeleteTweetMetric(ctx context.Context, arg *DeleteTweetMetricParams) error {
_, err := q.db.Exec(ctx, deleteTweetMetric, arg.DeletedOn, arg.PostID)
return err
}
const deleteUserMetric = `-- name: DeleteUserMetric :exec
UPDATE p_user_metric SET is_del=1, deleted_on=$1 WHERE user_id=$2 AND is_del=0
`
type DeleteUserMetricParams struct {
DeletedOn int64
UserID int64
}
func (q *Queries) DeleteUserMetric(ctx context.Context, arg *DeleteUserMetricParams) error {
_, err := q.db.Exec(ctx, deleteUserMetric, arg.DeletedOn, arg.UserID)
return err
}
const getUserTweetsCount = `-- name: GetUserTweetsCount :one
SELECT tweets_count FROM p_user_metric WHERE user_id=$1 AND is_del=0
`
func (q *Queries) GetUserTweetsCount(ctx context.Context, userID int64) (int32, error) {
row := q.db.QueryRow(ctx, getUserTweetsCount, userID)
var tweets_count int32
err := row.Scan(&tweets_count)
return tweets_count, err
}
const tweetMotivationFactor = `-- name: TweetMotivationFactor :one
SELECT motivation_factor FROM p_post_metric WHERE post_id=$1 AND is_del=0
`
func (q *Queries) TweetMotivationFactor(ctx context.Context, postID int64) (int32, error) {
row := q.db.QueryRow(ctx, tweetMotivationFactor, postID)
var motivation_factor int32
err := row.Scan(&motivation_factor)
return motivation_factor, err
}
const updateCommentMetric = `-- name: UpdateCommentMetric :exec
UPDATE p_comment_metric SET rank_score=$1, modified_on=$2 WHERE comment_id=$3 AND is_del=0
`
type UpdateCommentMetricParams struct {
RankScore int64
ModifiedOn int64
CommentID int64
}
// ------------------------------------------------------------------------------
// comment_metrics sql dml
// ------------------------------------------------------------------------------
func (q *Queries) UpdateCommentMetric(ctx context.Context, arg *UpdateCommentMetricParams) error {
_, err := q.db.Exec(ctx, updateCommentMetric, arg.RankScore, arg.ModifiedOn, arg.CommentID)
return err
}
const updateTweetMetric = `-- name: UpdateTweetMetric :exec
UPDATE p_post_metric SET rank_score=$1, modified_on=$2 WHERE post_id=$3 AND is_del=0
`
type UpdateTweetMetricParams struct {
RankScore int64
ModifiedOn int64
PostID int64
}
// ------------------------------------------------------------------------------
// tweet_metrics sql dml
// ------------------------------------------------------------------------------
func (q *Queries) UpdateTweetMetric(ctx context.Context, arg *UpdateTweetMetricParams) error {
_, err := q.db.Exec(ctx, updateTweetMetric, arg.RankScore, arg.ModifiedOn, arg.PostID)
return err
}
const updateUserMetric = `-- name: UpdateUserMetric :exec
UPDATE p_user_metric SET tweets_count=$1, modified_on=$2 WHERE user_id=$3 AND is_del=0
`
type UpdateUserMetricParams struct {
TweetsCount int32
ModifiedOn int64
UserID int64
}
// ------------------------------------------------------------------------------
// user_metrics sql dml
// ------------------------------------------------------------------------------
func (q *Queries) UpdateUserMetric(ctx context.Context, arg *UpdateUserMetricParams) error {
_, err := q.db.Exec(ctx, updateUserMetric, arg.TweetsCount, arg.ModifiedOn, arg.UserID)
return err
}
const upsertCommentMetric = `-- name: UpsertCommentMetric :exec
INSERT INTO p_comment_metric (comment_id, rank_score, created_on)
VALUES ($1, $2, $3)
RETURNING id
`
type UpsertCommentMetricParams struct {
CommentID int64
RankScore int64
CreatedOn int64
}
func (q *Queries) UpsertCommentMetric(ctx context.Context, arg *UpsertCommentMetricParams) error {
_, err := q.db.Exec(ctx, upsertCommentMetric, arg.CommentID, arg.RankScore, arg.CreatedOn)
return err
}
const upsertTweetMetric = `-- name: UpsertTweetMetric :exec
INSERT INTO p_post_metric (post_id, rank_score, created_on) VALUES ($1, $2, $3)
`
type UpsertTweetMetricParams struct {
PostID int64
RankScore int64
CreatedOn int64
}
func (q *Queries) UpsertTweetMetric(ctx context.Context, arg *UpsertTweetMetricParams) error {
_, err := q.db.Exec(ctx, upsertTweetMetric, arg.PostID, arg.RankScore, arg.CreatedOn)
return err
}

@ -46,6 +46,8 @@ type PComment struct {
IsDel int16 IsDel int16
ThumbsUpCount int32 ThumbsUpCount int32
ThumbsDownCount int32 ThumbsDownCount int32
IsEssence int16
ReplyCount int32
} }
type PCommentContent struct { type PCommentContent struct {
@ -61,6 +63,19 @@ type PCommentContent struct {
IsDel int16 IsDel int16
} }
type PCommentMetric struct {
ID int64
CommentID int64
RankScore int64
IncentiveScore int32
DecayFactor int32
MotivationFactor int32
IsDel int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
}
type PCommentReply struct { type PCommentReply struct {
ID int64 ID int64
CommentID int64 CommentID int64
@ -231,6 +246,19 @@ type PPostContent struct {
IsDel int16 IsDel int16
} }
type PPostMetric struct {
ID int64
PostID int64
RankScore int64
IncentiveScore int32
DecayFactor int32
MotivationFactor int32
IsDel int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
}
type PPostStar struct { type PPostStar struct {
ID int64 ID int64
PostID int64 PostID int64
@ -300,6 +328,17 @@ type PUser struct {
IsDel int16 IsDel int16
} }
type PUserMetric struct {
ID int64
UserID int64
TweetsCount int32
LatestTrendsOn int64
IsDel int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
}
type PWalletRecharge struct { type PWalletRecharge struct {
ID int64 ID int64
UserID int64 UserID int64

@ -11,10 +11,60 @@ import (
) )
type Querier interface { type Querier interface {
AddAttachment(ctx context.Context, arg *AddAttachmentParams) (int64, error)
AddCommentMetric(ctx context.Context, arg *AddCommentMetricParams) (int64, error)
AddFriendMsgsUpdate(ctx context.Context, arg *AddFriendMsgsUpdateParams) error
//------------------------------------------------------------------------------
// tweet_manage sql dml
//------------------------------------------------------------------------------
AddPost(ctx context.Context, arg *AddPostParams) error
AddPostCollection(ctx context.Context, arg *AddPostCollectionParams) (int64, error)
AddPostContent(ctx context.Context, arg *AddPostContentParams) (int64, error)
AddPostStar(ctx context.Context, arg *AddPostStarParams) (int64, error)
AddTweetMetric(ctx context.Context, arg *AddTweetMetricParams) (int64, error)
AddUserBalance(ctx context.Context, arg *AddUserBalanceParams) (int64, error)
AddUserMetric(ctx context.Context, arg *AddUserMetricParams) (int64, error)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// authorization_manage sql dml // authorization_manage sql dml
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BeFriendIds(ctx context.Context, friendID int64) ([]int64, error) BeFriendIds(ctx context.Context, friendID int64) ([]int64, error)
CommentIdsByPostId(ctx context.Context, postID int64) ([]int64, error)
CommentMediaFromCommentIds(ctx context.Context, ids []int64) ([]string, error)
CommentMotivationFactor(ctx context.Context, commentID int64) (int32, error)
CountAllMessages(ctx context.Context, arg *CountAllMessagesParams) (int64, error)
CountAnyPost(ctx context.Context, visibility int16) (int64, error)
CountFollowingTweets(ctx context.Context, userID int64) (int64, error)
CountFollowingTweetsFollow(ctx context.Context, arg *CountFollowingTweetsFollowParams) (int64, error)
CountFollowingTweetsFriendFollow(ctx context.Context, arg *CountFollowingTweetsFriendFollowParams) (int64, error)
CountFollowings(ctx context.Context, followID int64) (int64, error)
CountFollows(ctx context.Context, userID int64) (int64, error)
CountFriendsById(ctx context.Context, userID int64) (int64, error)
CountIndexHotsTweets(ctx context.Context) (int64, error)
CountIndexNewestTweets(ctx context.Context) (int64, error)
CountIndexTrends(ctx context.Context, userID int64) (int64, error)
CountListFollowingTweetsFriend(ctx context.Context, arg *CountListFollowingTweetsFriendParams) (int64, error)
CountRequestingMessages(ctx context.Context, receiverUserID int64) (int64, error)
CountSyncSearchTweets(ctx context.Context) (int64, error)
CountSystemMessages(ctx context.Context, receiverUserID int64) (int64, error)
CountUnreadMessages(ctx context.Context, receiverUserID int64) (int64, error)
CountUserCommentTweetsByFriend(ctx context.Context, commentUserID int64) (int64, error)
CountUserCommentTweetsByGuest(ctx context.Context, commentUserID int64) (int64, error)
CountUserCommentTweetsBySelf(ctx context.Context, commentUserID int64) (int64, error)
CountUserMediaTweetsByFriend(ctx context.Context, userID int64) (int64, error)
CountUserMediaTweetsByGuest(ctx context.Context, userID int64) (int64, error)
CountUserMediaTweetsBySelf(ctx context.Context, userID int64) (int64, error)
CountUserPostStars(ctx context.Context, arg *CountUserPostStarsParams) (int64, error)
CountUserPosts(ctx context.Context, arg *CountUserPostsParams) (int64, error)
CountUserStarTweetsByAdmin(ctx context.Context, userID int64) (int64, error)
CountUserStarTweetsByFriend(ctx context.Context, userID int64) (int64, error)
CountUserStarTweetsByGuest(ctx context.Context, userID int64) (int64, error)
CountUserStarTweetsBySelf(ctx context.Context, arg *CountUserStarTweetsBySelfParams) (int64, error)
CountUserTweets(ctx context.Context, arg *CountUserTweetsParams) (int64, error)
CountUserWalletBill(ctx context.Context, userID int64) (int64, error)
CountWhisperMessages(ctx context.Context, arg *CountWhisperMessagesParams) (int64, error)
CreateComment(ctx context.Context, arg *CreateCommentParams) (int64, error)
CreateCommentContent(ctx context.Context, arg *CreateCommentContentParams) (int64, error)
CreateCommentReply(ctx context.Context, arg *CreateCommentReplyParams) (int64, error)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// contact_manager sql dml // contact_manager sql dml
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -23,48 +73,178 @@ type Querier interface {
// following_manager sql dml // following_manager sql dml
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
CreateFollowing(ctx context.Context, arg *CreateFollowingParams) error CreateFollowing(ctx context.Context, arg *CreateFollowingParams) error
CreateMessage(ctx context.Context, arg *CreateMessageParams) (int64, error)
CreatePhoneCaptcha(ctx context.Context, arg *CreatePhoneCaptchaParams) (int64, error)
CreatePostAttachmentBill(ctx context.Context, arg *CreatePostAttachmentBillParams) (int64, error)
CreatePostBill(ctx context.Context, arg *CreatePostBillParams) (int64, error)
CreateRecharge(ctx context.Context, arg *CreateRechargeParams) (int64, error)
CreateThumbsUpDownComment(ctx context.Context, arg *CreateThumbsUpDownCommentParams) (int64, error)
CreateUser(ctx context.Context, arg *CreateUserParams) (int64, error)
CreateWalletStatement(ctx context.Context, arg *CreateWalletStatementParams) (int64, error)
DecrCommentReplyCount(ctx context.Context, arg *DecrCommentReplyCountParams) error
DecrTagsById(ctx context.Context, arg *DecrTagsByIdParams) error DecrTagsById(ctx context.Context, arg *DecrTagsByIdParams) error
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// comment_manage sql dml // comment_manage sql dml
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
DeleteComment(ctx context.Context, arg *DeleteCommentParams) error DeleteComment(ctx context.Context, arg *DeleteCommentParams) error
DeleteCommentByPostId(ctx context.Context, arg *DeleteCommentByPostIdParams) error
DeleteCommentContentByCommentIds(ctx context.Context, arg *DeleteCommentContentByCommentIdsParams) error
DeleteCommentMetric(ctx context.Context, arg *DeleteCommentMetricParams) error
DeleteCommentReply(ctx context.Context, arg *DeleteCommentReplyParams) error
DeleteCommentThumbs(ctx context.Context, arg *DeleteCommentThumbsParams) error
DeleteFollowing(ctx context.Context, arg *DeleteFollowingParams) error
DeleteFriend(ctx context.Context, arg *DeleteFriendParams) error
DeletePostById(ctx context.Context, arg *DeletePostByIdParams) error
DeletePostCollecton(ctx context.Context, arg *DeletePostCollectonParams) error
DeletePostStar(ctx context.Context, arg *DeletePostStarParams) error
DeleteReplyByCommentIds(ctx context.Context, arg *DeleteReplyByCommentIdsParams) error
DeleteReplyThumbs(ctx context.Context, arg *DeleteReplyThumbsParams) error
DeleteTweetMetric(ctx context.Context, arg *DeleteTweetMetricParams) error
DeleteUserMetric(ctx context.Context, arg *DeleteUserMetricParams) error
ExistFollowing(ctx context.Context, arg *ExistFollowingParams) (int32, error)
FreshContactStatus(ctx context.Context, arg *FreshContactStatusParams) error
GetAllMessages(ctx context.Context, arg *GetAllMessagesParams) ([]*PMessage, error)
GetAnyPosts(ctx context.Context, arg *GetAnyPostsParams) ([]*PPost, error)
GetAnyusers(ctx context.Context) ([]*PUser, error)
GetBeFollowIds(ctx context.Context, userID int64) ([]int64, error)
GetBeFriendIds(ctx context.Context, friendID int64) ([]int64, error)
GetCommentById(ctx context.Context, id int64) (*PComment, error)
GetCommentContentsByIds(ctx context.Context, ids []int64) ([]*PCommentContent, error)
GetCommentCount(ctx context.Context, postID int64) (int64, error)
GetCommentRepliesByIds(ctx context.Context, ids []int64) ([]*PCommentReply, error)
GetCommentReplyById(ctx context.Context, id int64) (*PCommentReply, error)
GetCommentReplyThumb(ctx context.Context, arg *GetCommentReplyThumbParams) (*PTweetCommentThumb, error)
GetCommentThumbs(ctx context.Context, arg *GetCommentThumbsParams) ([]*GetCommentThumbsRow, error)
GetContact(ctx context.Context, arg *GetContactParams) (*GetContactRow, error)
GetContacts(ctx context.Context, arg *GetContactsParams) ([]*GetContactsRow, error)
GetDefaultComments(ctx context.Context, arg *GetDefaultCommentsParams) ([]*PComment, error) GetDefaultComments(ctx context.Context, arg *GetDefaultCommentsParams) ([]*PComment, error)
GetHotsComments(ctx context.Context, arg *GetHotsCommentsParams) ([]*PComment, error)
//------------------------------------------------------------------------------
// trends_manager sql dml
//------------------------------------------------------------------------------
GetIndexTrends(ctx context.Context, arg *GetIndexTrendsParams) ([]*GetIndexTrendsRow, error)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// security sql dml // security sql dml
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
GetLatestPhoneCaptcha(ctx context.Context, phone pgtype.Text) (*PCaptcha, error) GetLatestPhoneCaptcha(ctx context.Context, phone pgtype.Text) (*PCaptcha, error)
GetMessageById(ctx context.Context, id int64) (*PMessage, error)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// comment sql dml // comment sql dml
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
GetNewestComments(ctx context.Context, arg *GetNewestCommentsParams) ([]*PComment, error) GetNewestComments(ctx context.Context, arg *GetNewestCommentsParams) ([]*PComment, error)
GetPostAttachementBill(ctx context.Context, arg *GetPostAttachementBillParams) (*PPostAttachmentBill, error)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// tweet sql dml // tweet sql dml
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
GetPostById(ctx context.Context, id int64) (*PPost, error) GetPostById(ctx context.Context, id int64) (*PPost, error)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// message sql dml // tweet_help sql dml
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
GetUnreadCount(ctx context.Context, receiverUserID int64) (int64, error) GetPostConetentByIds(ctx context.Context, ids []int64) ([]*GetPostConetentByIdsRow, error)
GetPostContentById(ctx context.Context, id int64) (*PPostContent, error)
GetPostContentsByIds(ctx context.Context, ids []int64) ([]*PPostContent, error)
GetRechargeById(ctx context.Context, id int64) (*PWalletRecharge, error)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// user_manage sql dml // user_manage sql dml
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
GetRegisterUserCount(ctx context.Context) (int64, error)
GetRequestingMessages(ctx context.Context, arg *GetRequestingMessagesParams) ([]*PMessage, error)
GetSystemMessages(ctx context.Context, arg *GetSystemMessagesParams) ([]*PMessage, error)
GetTweetCommentThumb(ctx context.Context, arg *GetTweetCommentThumbParams) (*PTweetCommentThumb, error)
//------------------------------------------------------------------------------
// message sql dml
//------------------------------------------------------------------------------
GetUnreadCount(ctx context.Context, receiverUserID int64) (int64, error)
GetUnreadMessages(ctx context.Context, arg *GetUnreadMessagesParams) ([]*PMessage, error)
GetUserBalance(ctx context.Context, id int64) (int64, error)
GetUserById(ctx context.Context, id int64) (*PUser, error) GetUserById(ctx context.Context, id int64) (*PUser, error)
GetUserByPhone(ctx context.Context, phone string) (*PUser, error)
GetUserByUsername(ctx context.Context, username string) (*PUser, error)
GetUserFriend(ctx context.Context, arg *GetUserFriendParams) (*GetUserFriendRow, error)
GetUserPostCollection(ctx context.Context, arg *GetUserPostCollectionParams) (*GetUserPostCollectionRow, error)
GetUserPostCollections(ctx context.Context, arg *GetUserPostCollectionsParams) ([]*GetUserPostCollectionsRow, error)
GetUserPostStar(ctx context.Context, arg *GetUserPostStarParams) (*GetUserPostStarRow, error)
GetUserPostStars(ctx context.Context, arg *GetUserPostStarsParams) ([]*GetUserPostStarsRow, error)
GetUserPosts(ctx context.Context, arg *GetUserPostsParams) ([]*PPost, error)
GetUserTweetsCount(ctx context.Context, userID int64) (int32, error)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// wallet sql dml // wallet sql dml
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
GetUserWalletBills(ctx context.Context, arg *GetUserWalletBillsParams) (*PWalletStatement, error) GetUserWalletBills(ctx context.Context, arg *GetUserWalletBillsParams) ([]*PWalletStatement, error)
GetUsersByIds(ctx context.Context, ids []int64) ([]*PUser, error)
GetUsersByKeyword(ctx context.Context, username string) ([]*PUser, error)
GetWhisperMessages(ctx context.Context, arg *GetWhisperMessagesParams) ([]*PMessage, error)
HighlightPost(ctx context.Context, id int64) (int16, error)
HotTags(ctx context.Context, arg *HotTagsParams) ([]*HotTagsRow, error) HotTags(ctx context.Context, arg *HotTagsParams) ([]*HotTagsRow, error)
IncrCommentReplyCount(ctx context.Context, arg *IncrCommentReplyCountParams) error
IncrTags(ctx context.Context, arg *IncrTagsParams) ([]*IncrTagsRow, error) IncrTags(ctx context.Context, arg *IncrTagsParams) ([]*IncrTagsRow, error)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// ship_index sql dml // ship_index sql dml
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
IndexByAdmin(ctx context.Context, arg *IndexByAdminParams) ([]*PPost, error) IndexByAdmin(ctx context.Context, arg *IndexByAdminParams) ([]*PPost, error)
InsertTags(ctx context.Context, arg *InsertTagsParams) (int64, error) InsertTags(ctx context.Context, arg *InsertTagsParams) (int64, error)
IsFriend(ctx context.Context, arg *IsFriendParams) (int16, error) IsFriend(ctx context.Context, arg *IsFriendParams) (bool, error)
ListFollowingTweets(ctx context.Context, arg *ListFollowingTweetsParams) ([]*PPost, error)
ListFollowingTweetsFollow(ctx context.Context, arg *ListFollowingTweetsFollowParams) ([]*PPost, error)
ListFollowingTweetsFriend(ctx context.Context, arg *ListFollowingTweetsFriendParams) ([]*PPost, error)
ListFollowingTweetsFriendFollow(ctx context.Context, arg *ListFollowingTweetsFriendFollowParams) ([]*PPost, error)
ListFollowings(ctx context.Context, arg *ListFollowingsParams) ([]*ListFollowingsRow, error)
ListFollows(ctx context.Context, arg *ListFollowsParams) ([]*ListFollowsRow, error)
ListFriend(ctx context.Context, arg *ListFriendParams) ([]*ListFriendRow, error)
ListIndexHotsTweets(ctx context.Context, arg *ListIndexHotsTweetsParams) ([]*PPost, error)
ListIndexNewestTweets(ctx context.Context, arg *ListIndexNewestTweetsParams) ([]*PPost, error)
ListSyncSearchTweets(ctx context.Context, arg *ListSyncSearchTweetsParams) ([]*PPost, error)
ListUserTweets(ctx context.Context, arg *ListUserTweetsParams) ([]*PPost, error)
LockPost(ctx context.Context, arg *LockPostParams) (int16, error)
MarkSuccessRecharge(ctx context.Context, arg *MarkSuccessRechargeParams) error
MediaContentByPostId(ctx context.Context, postID int64) ([]string, error)
MinusUserBalance(ctx context.Context, arg *MinusUserBalanceParams) (int64, error)
MyFollowIds(ctx context.Context, userID int64) ([]int64, error)
//------------------------------------------------------------------------------
// user_relation sql dml
//------------------------------------------------------------------------------
MyFriendIds(ctx context.Context, userID int64) ([]int64, error)
MyFriendSet(ctx context.Context, userID int64) ([]int64, error) MyFriendSet(ctx context.Context, userID int64) ([]int64, error)
NewestTags(ctx context.Context, arg *NewestTagsParams) ([]*NewestTagsRow, error) NewestTags(ctx context.Context, arg *NewestTagsParams) ([]*NewestTagsRow, error)
PostHighlightStatus(ctx context.Context, id int64) (*PostHighlightStatusRow, error)
ReadAllMessage(ctx context.Context, arg *ReadAllMessageParams) error
ReadMessage(ctx context.Context, arg *ReadMessageParams) error
RejectFriendMsgsUpdate(ctx context.Context, arg *RejectFriendMsgsUpdateParams) error
StickPost(ctx context.Context, arg *StickPostParams) (int16, error)
TagsByKeywordA(ctx context.Context) ([]*TagsByKeywordARow, error) TagsByKeywordA(ctx context.Context) ([]*TagsByKeywordARow, error)
TagsByKeywordB(ctx context.Context, tag string) ([]*TagsByKeywordBRow, error) TagsByKeywordB(ctx context.Context, tag string) ([]*TagsByKeywordBRow, error)
TweetMotivationFactor(ctx context.Context, postID int64) (int32, error)
//------------------------------------------------------------------------------
// comment_metrics sql dml
//------------------------------------------------------------------------------
UpdateCommentMetric(ctx context.Context, arg *UpdateCommentMetricParams) error
UpdateCommentThumbsCount(ctx context.Context, arg *UpdateCommentThumbsCountParams) error
UpdatePost(ctx context.Context, arg *UpdatePostParams) error
UpdateReplyThumbsCount(ctx context.Context, arg *UpdateReplyThumbsCountParams) error
UpdateThumbsUpDownComment(ctx context.Context, arg *UpdateThumbsUpDownCommentParams) error
//------------------------------------------------------------------------------
// tweet_metrics sql dml
//------------------------------------------------------------------------------
UpdateTweetMetric(ctx context.Context, arg *UpdateTweetMetricParams) error
UpdateUser(ctx context.Context, arg *UpdateUserParams) error
//------------------------------------------------------------------------------
// user_metrics sql dml
//------------------------------------------------------------------------------
UpdateUserMetric(ctx context.Context, arg *UpdateUserMetricParams) error
UpsertCommentMetric(ctx context.Context, arg *UpsertCommentMetricParams) error
UpsertTweetMetric(ctx context.Context, arg *UpsertTweetMetricParams) error
UsePhoneCaptcha(ctx context.Context, arg *UsePhoneCaptchaParams) error
UserCommentTweetsByFriend(ctx context.Context, arg *UserCommentTweetsByFriendParams) ([]*UserCommentTweetsByFriendRow, error)
UserCommentTweetsByGuest(ctx context.Context, arg *UserCommentTweetsByGuestParams) ([]*UserCommentTweetsByGuestRow, error)
UserCommentTweetsBySelf(ctx context.Context, arg *UserCommentTweetsBySelfParams) ([]*UserCommentTweetsBySelfRow, error)
UserMediaTweetsByFriend(ctx context.Context, arg *UserMediaTweetsByFriendParams) ([]*UserMediaTweetsByFriendRow, error)
UserMediaTweetsByGuest(ctx context.Context, arg *UserMediaTweetsByGuestParams) ([]*UserMediaTweetsByGuestRow, error)
UserMediaTweetsBySelf(ctx context.Context, arg *UserMediaTweetsBySelfParams) ([]*UserMediaTweetsBySelfRow, error)
UserStarTweetsByAdmin(ctx context.Context, arg *UserStarTweetsByAdminParams) ([]*UserStarTweetsByAdminRow, error)
UserStarTweetsByFriend(ctx context.Context, arg *UserStarTweetsByFriendParams) ([]*UserStarTweetsByFriendRow, error)
UserStarTweetsByGuest(ctx context.Context, arg *UserStarTweetsByGuestParams) ([]*UserStarTweetsByGuestRow, error)
UserStarTweetsBySelf(ctx context.Context, arg *UserStarTweetsBySelfParams) ([]*UserStarTweetsBySelfRow, error)
VisiblePost(ctx context.Context, arg *VisiblePostParams) (int16, error)
} }
var _ Querier = (*Queries)(nil) var _ Querier = (*Queries)(nil)

@ -11,6 +11,31 @@ import (
"github.com/jackc/pgx/v5/pgtype" "github.com/jackc/pgx/v5/pgtype"
) )
const createPhoneCaptcha = `-- name: CreatePhoneCaptcha :one
INSERT INTO p_captcha (phone, captcha, expired_on, created_on)
VALUES ($1, $2, $3, $4)
RETURNING id
`
type CreatePhoneCaptchaParams struct {
Phone pgtype.Text
Captcha pgtype.Text
ExpiredOn int64
CreatedOn int64
}
func (q *Queries) CreatePhoneCaptcha(ctx context.Context, arg *CreatePhoneCaptchaParams) (int64, error) {
row := q.db.QueryRow(ctx, createPhoneCaptcha,
arg.Phone,
arg.Captcha,
arg.ExpiredOn,
arg.CreatedOn,
)
var id int64
err := row.Scan(&id)
return id, err
}
const getLatestPhoneCaptcha = `-- name: GetLatestPhoneCaptcha :one const getLatestPhoneCaptcha = `-- name: GetLatestPhoneCaptcha :one
SELECT id, phone, captcha, use_times, expired_on, created_on, modified_on, deleted_on, is_del FROM p_captcha WHERE phone=$1 AND is_del=0 SELECT id, phone, captcha, use_times, expired_on, created_on, modified_on, deleted_on, is_del FROM p_captcha WHERE phone=$1 AND is_del=0
@ -35,3 +60,17 @@ func (q *Queries) GetLatestPhoneCaptcha(ctx context.Context, phone pgtype.Text)
) )
return &i, err return &i, err
} }
const usePhoneCaptcha = `-- name: UsePhoneCaptcha :exec
UPDATE p_captcha SET use_times=use_times+1, modified_on=$1 WHERE id=$2 AND is_del=0
`
type UsePhoneCaptchaParams struct {
ModifiedOn int64
ID int64
}
func (q *Queries) UsePhoneCaptcha(ctx context.Context, arg *UsePhoneCaptchaParams) error {
_, err := q.db.Exec(ctx, usePhoneCaptcha, arg.ModifiedOn, arg.ID)
return err
}

@ -0,0 +1,76 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.21.0
// source: trends.sql
package pgc
import (
"context"
)
const countIndexTrends = `-- name: CountIndexTrends :one
SELECT count(*)
FROM p_contact c
JOIN p_user u
ON c.friend_id=u.id
JOIN p_user_metric m
ON c.friend_id=m.user_id
WHERE c.user_id=$1 AND c.is_del=0 AND u.is_del=0 AND m.is_del=0 AND m.tweets_count>0
`
func (q *Queries) CountIndexTrends(ctx context.Context, userID int64) (int64, error) {
row := q.db.QueryRow(ctx, countIndexTrends, userID)
var count int64
err := row.Scan(&count)
return count, err
}
const getIndexTrends = `-- name: GetIndexTrends :many
SELECT u.username username,
u.nickname nickname,
u.avatar avatar
FROM p_contact c
JOIN p_user u
ON c.friend_id=u.id
JOIN p_user_metric m
ON c.friend_id=m.user_id
WHERE c.user_id=$1 AND c.is_del=0 AND u.is_del=0 AND m.is_del=0 AND m.tweets_count>0
LIMIT $2 OFFSET $3
`
type GetIndexTrendsParams struct {
UserID int64
Limit int32
Offset int32
}
type GetIndexTrendsRow struct {
Username string
Nickname string
Avatar string
}
// ------------------------------------------------------------------------------
// trends_manager sql dml
// ------------------------------------------------------------------------------
func (q *Queries) GetIndexTrends(ctx context.Context, arg *GetIndexTrendsParams) ([]*GetIndexTrendsRow, error) {
rows, err := q.db.Query(ctx, getIndexTrends, arg.UserID, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*GetIndexTrendsRow
for rows.Next() {
var i GetIndexTrendsRow
if err := rows.Scan(&i.Username, &i.Nickname, &i.Avatar); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}

File diff suppressed because it is too large Load Diff

@ -9,14 +9,95 @@ import (
"context" "context"
) )
const getUserById = `-- name: GetUserById :one const createUser = `-- name: CreateUser :one
INSERT INTO p_user (username, nickname, password, salt, avatar, status, created_on, balance)
VALUES ($1, $2, $3, $4, $5, $6, $7, 0)
RETURNING id
`
SELECT id, nickname, username, phone, password, salt, status, avatar, balance, is_admin, created_on, modified_on, deleted_on, is_del FROM p_user WHERE id=$1 AND is_del=0 type CreateUserParams struct {
Username string
Nickname string
Password string
Salt string
Avatar string
Status int16
CreatedOn int64
}
func (q *Queries) CreateUser(ctx context.Context, arg *CreateUserParams) (int64, error) {
row := q.db.QueryRow(ctx, createUser,
arg.Username,
arg.Nickname,
arg.Password,
arg.Salt,
arg.Avatar,
arg.Status,
arg.CreatedOn,
)
var id int64
err := row.Scan(&id)
return id, err
}
const getAnyusers = `-- name: GetAnyusers :many
SELECT id, nickname, username, phone, password, salt, status, avatar, balance, is_admin, created_on, modified_on, deleted_on, is_del FROM p_user WHERE is_del=0 ORDER BY id ASC limit 6
`
func (q *Queries) GetAnyusers(ctx context.Context) ([]*PUser, error) {
rows, err := q.db.Query(ctx, getAnyusers)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*PUser
for rows.Next() {
var i PUser
if err := rows.Scan(
&i.ID,
&i.Nickname,
&i.Username,
&i.Phone,
&i.Password,
&i.Salt,
&i.Status,
&i.Avatar,
&i.Balance,
&i.IsAdmin,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getRegisterUserCount = `-- name: GetRegisterUserCount :one
SELECT count(*) FROM p_user WHERE is_del=0
` `
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// user_manage sql dml // user_manage sql dml
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
func (q *Queries) GetRegisterUserCount(ctx context.Context) (int64, error) {
row := q.db.QueryRow(ctx, getRegisterUserCount)
var count int64
err := row.Scan(&count)
return count, err
}
const getUserById = `-- name: GetUserById :one
SELECT id, nickname, username, phone, password, salt, status, avatar, balance, is_admin, created_on, modified_on, deleted_on, is_del FROM p_user WHERE id=$1 AND is_del=0
`
func (q *Queries) GetUserById(ctx context.Context, id int64) (*PUser, error) { func (q *Queries) GetUserById(ctx context.Context, id int64) (*PUser, error) {
row := q.db.QueryRow(ctx, getUserById, id) row := q.db.QueryRow(ctx, getUserById, id)
var i PUser var i PUser
@ -38,3 +119,231 @@ func (q *Queries) GetUserById(ctx context.Context, id int64) (*PUser, error) {
) )
return &i, err return &i, err
} }
const getUserByPhone = `-- name: GetUserByPhone :one
SELECT id, nickname, username, phone, password, salt, status, avatar, balance, is_admin, created_on, modified_on, deleted_on, is_del FROM p_user WHERE phone=$1 AND is_del=0
`
func (q *Queries) GetUserByPhone(ctx context.Context, phone string) (*PUser, error) {
row := q.db.QueryRow(ctx, getUserByPhone, phone)
var i PUser
err := row.Scan(
&i.ID,
&i.Nickname,
&i.Username,
&i.Phone,
&i.Password,
&i.Salt,
&i.Status,
&i.Avatar,
&i.Balance,
&i.IsAdmin,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
)
return &i, err
}
const getUserByUsername = `-- name: GetUserByUsername :one
SELECT id, nickname, username, phone, password, salt, status, avatar, balance, is_admin, created_on, modified_on, deleted_on, is_del FROM p_user WHERE username=$1 AND is_del=0
`
func (q *Queries) GetUserByUsername(ctx context.Context, username string) (*PUser, error) {
row := q.db.QueryRow(ctx, getUserByUsername, username)
var i PUser
err := row.Scan(
&i.ID,
&i.Nickname,
&i.Username,
&i.Phone,
&i.Password,
&i.Salt,
&i.Status,
&i.Avatar,
&i.Balance,
&i.IsAdmin,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
)
return &i, err
}
const getUsersByIds = `-- name: GetUsersByIds :many
SELECT id, nickname, username, phone, password, salt, status, avatar, balance, is_admin, created_on, modified_on, deleted_on, is_del FROM p_user WHERE id = ANY($1::BIGINT[]) AND is_del=0
`
func (q *Queries) GetUsersByIds(ctx context.Context, ids []int64) ([]*PUser, error) {
rows, err := q.db.Query(ctx, getUsersByIds, ids)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*PUser
for rows.Next() {
var i PUser
if err := rows.Scan(
&i.ID,
&i.Nickname,
&i.Username,
&i.Phone,
&i.Password,
&i.Salt,
&i.Status,
&i.Avatar,
&i.Balance,
&i.IsAdmin,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getUsersByKeyword = `-- name: GetUsersByKeyword :many
SELECT id, nickname, username, phone, password, salt, status, avatar, balance, is_admin, created_on, modified_on, deleted_on, is_del FROM p_user WHERE username LIKE $1 AND is_del=0 limit 6
`
func (q *Queries) GetUsersByKeyword(ctx context.Context, username string) ([]*PUser, error) {
rows, err := q.db.Query(ctx, getUsersByKeyword, username)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*PUser
for rows.Next() {
var i PUser
if err := rows.Scan(
&i.ID,
&i.Nickname,
&i.Username,
&i.Phone,
&i.Password,
&i.Salt,
&i.Status,
&i.Avatar,
&i.Balance,
&i.IsAdmin,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const myFollowIds = `-- name: MyFollowIds :many
SELECT follow_id FROM p_following WHERE user_id=$1 AND is_del=0
`
func (q *Queries) MyFollowIds(ctx context.Context, userID int64) ([]int64, error) {
rows, err := q.db.Query(ctx, myFollowIds, userID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []int64
for rows.Next() {
var follow_id int64
if err := rows.Scan(&follow_id); err != nil {
return nil, err
}
items = append(items, follow_id)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const myFriendIds = `-- name: MyFriendIds :many
SELECT friend_id FROM p_contact WHERE user_id=$1 AND is_del=0
`
// ------------------------------------------------------------------------------
// user_relation sql dml
// ------------------------------------------------------------------------------
func (q *Queries) MyFriendIds(ctx context.Context, userID int64) ([]int64, error) {
rows, err := q.db.Query(ctx, myFriendIds, userID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []int64
for rows.Next() {
var friend_id int64
if err := rows.Scan(&friend_id); err != nil {
return nil, err
}
items = append(items, friend_id)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateUser = `-- name: UpdateUser :exec
UPDATE p_user
SET username=$1,
nickname=$2,
phone=$3,
password=$4,
salt=$5,
status=$6,
avatar=$7,
balance=$8,
is_admin=$9,
modified_on=$10
WHERE id=$11 AND is_del=0
`
type UpdateUserParams struct {
Username string
Nickname string
Phone string
Password string
Salt string
Status int16
Avatar string
Balance int64
IsAdmin bool
ModifiedOn int64
ID int64
}
func (q *Queries) UpdateUser(ctx context.Context, arg *UpdateUserParams) error {
_, err := q.db.Exec(ctx, updateUser,
arg.Username,
arg.Nickname,
arg.Phone,
arg.Password,
arg.Salt,
arg.Status,
arg.Avatar,
arg.Balance,
arg.IsAdmin,
arg.ModifiedOn,
arg.ID,
)
return err
}

@ -9,7 +9,170 @@ import (
"context" "context"
) )
const getUserWalletBills = `-- name: GetUserWalletBills :one const addUserBalance = `-- name: AddUserBalance :one
UPDATE p_user
SET balance=balance+$1, modified_on=$2
WHERE id=$3 AND is_del=0
RETURNING balance
`
type AddUserBalanceParams struct {
Balance int64
ModifiedOn int64
ID int64
}
func (q *Queries) AddUserBalance(ctx context.Context, arg *AddUserBalanceParams) (int64, error) {
row := q.db.QueryRow(ctx, addUserBalance, arg.Balance, arg.ModifiedOn, arg.ID)
var balance int64
err := row.Scan(&balance)
return balance, err
}
const countUserWalletBill = `-- name: CountUserWalletBill :one
SELECT count(*) FROM p_wallet_statement WHERE user_id=$1 AND is_del=0
`
func (q *Queries) CountUserWalletBill(ctx context.Context, userID int64) (int64, error) {
row := q.db.QueryRow(ctx, countUserWalletBill, userID)
var count int64
err := row.Scan(&count)
return count, err
}
const createPostAttachmentBill = `-- name: CreatePostAttachmentBill :one
INSERT INTO p_post_attachment_bill (post_id, user_id, paid_amount, created_on)
VALUES ($1, $2, $3, $4)
RETURNING id
`
type CreatePostAttachmentBillParams struct {
PostID int64
UserID int64
PaidAmount int64
CreatedOn int64
}
func (q *Queries) CreatePostAttachmentBill(ctx context.Context, arg *CreatePostAttachmentBillParams) (int64, error) {
row := q.db.QueryRow(ctx, createPostAttachmentBill,
arg.PostID,
arg.UserID,
arg.PaidAmount,
arg.CreatedOn,
)
var id int64
err := row.Scan(&id)
return id, err
}
const createPostBill = `-- name: CreatePostBill :one
INSERT INTO p_wallet_statement (post_id, user_id, change_amount, balance_snapshot, reason, created_on)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id
`
type CreatePostBillParams struct {
PostID int64
UserID int64
ChangeAmount int64
BalanceSnapshot int64
Reason string
CreatedOn int64
}
func (q *Queries) CreatePostBill(ctx context.Context, arg *CreatePostBillParams) (int64, error) {
row := q.db.QueryRow(ctx, createPostBill,
arg.PostID,
arg.UserID,
arg.ChangeAmount,
arg.BalanceSnapshot,
arg.Reason,
arg.CreatedOn,
)
var id int64
err := row.Scan(&id)
return id, err
}
const createRecharge = `-- name: CreateRecharge :one
INSERT INTO p_wallet_recharge (user_id, amount, created_on)
VALUES ($1, $2, $3)
RETURNING id
`
type CreateRechargeParams struct {
UserID int64
Amount int64
CreatedOn int64
}
func (q *Queries) CreateRecharge(ctx context.Context, arg *CreateRechargeParams) (int64, error) {
row := q.db.QueryRow(ctx, createRecharge, arg.UserID, arg.Amount, arg.CreatedOn)
var id int64
err := row.Scan(&id)
return id, err
}
const createWalletStatement = `-- name: CreateWalletStatement :one
INSERT INTO p_wallet_statement (user_id, change_amount, balance_snapshot, reason, created_on)
VALUES ($1, $2, $3, $4, $5)
RETURNING id
`
type CreateWalletStatementParams struct {
UserID int64
ChangeAmount int64
BalanceSnapshot int64
Reason string
CreatedOn int64
}
func (q *Queries) CreateWalletStatement(ctx context.Context, arg *CreateWalletStatementParams) (int64, error) {
row := q.db.QueryRow(ctx, createWalletStatement,
arg.UserID,
arg.ChangeAmount,
arg.BalanceSnapshot,
arg.Reason,
arg.CreatedOn,
)
var id int64
err := row.Scan(&id)
return id, err
}
const getRechargeById = `-- name: GetRechargeById :one
SELECT id, user_id, amount, trade_no, trade_status, created_on, modified_on, deleted_on, is_del FROM p_wallet_recharge WHERE id=$1 AND is_del=0
`
func (q *Queries) GetRechargeById(ctx context.Context, id int64) (*PWalletRecharge, error) {
row := q.db.QueryRow(ctx, getRechargeById, id)
var i PWalletRecharge
err := row.Scan(
&i.ID,
&i.UserID,
&i.Amount,
&i.TradeNo,
&i.TradeStatus,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
)
return &i, err
}
const getUserBalance = `-- name: GetUserBalance :one
SELECT balance FROM p_user WHERE id=$1 AND is_del=0
`
func (q *Queries) GetUserBalance(ctx context.Context, id int64) (int64, error) {
row := q.db.QueryRow(ctx, getUserBalance, id)
var balance int64
err := row.Scan(&balance)
return balance, err
}
const getUserWalletBills = `-- name: GetUserWalletBills :many
SELECT id, user_id, change_amount, balance_snapshot, reason, post_id, created_on, modified_on, deleted_on, is_del SELECT id, user_id, change_amount, balance_snapshot, reason, post_id, created_on, modified_on, deleted_on, is_del
FROM p_wallet_statement FROM p_wallet_statement
@ -27,10 +190,16 @@ type GetUserWalletBillsParams struct {
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// wallet sql dml // wallet sql dml
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
func (q *Queries) GetUserWalletBills(ctx context.Context, arg *GetUserWalletBillsParams) (*PWalletStatement, error) { func (q *Queries) GetUserWalletBills(ctx context.Context, arg *GetUserWalletBillsParams) ([]*PWalletStatement, error) {
row := q.db.QueryRow(ctx, getUserWalletBills, arg.UserID, arg.Limit, arg.Offset) rows, err := q.db.Query(ctx, getUserWalletBills, arg.UserID, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*PWalletStatement
for rows.Next() {
var i PWalletStatement var i PWalletStatement
err := row.Scan( if err := rows.Scan(
&i.ID, &i.ID,
&i.UserID, &i.UserID,
&i.ChangeAmount, &i.ChangeAmount,
@ -41,6 +210,50 @@ func (q *Queries) GetUserWalletBills(ctx context.Context, arg *GetUserWalletBill
&i.ModifiedOn, &i.ModifiedOn,
&i.DeletedOn, &i.DeletedOn,
&i.IsDel, &i.IsDel,
) ); err != nil {
return &i, err return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const markSuccessRecharge = `-- name: MarkSuccessRecharge :exec
UPDATE p_wallet_recharge
SET trade_no=$1, trade_status='TRADE_SUCCESS', modified_on=$2
WHERE id=$3 AND is_del=0
`
type MarkSuccessRechargeParams struct {
TradeNo string
ModifiedOn int64
ID int64
}
func (q *Queries) MarkSuccessRecharge(ctx context.Context, arg *MarkSuccessRechargeParams) error {
_, err := q.db.Exec(ctx, markSuccessRecharge, arg.TradeNo, arg.ModifiedOn, arg.ID)
return err
}
const minusUserBalance = `-- name: MinusUserBalance :one
UPDATE p_user
SET balance=balance-$1, modified_on=$2
WHERE id=$3 AND is_del=0
RETURNING balance
`
type MinusUserBalanceParams struct {
Balance int64
ModifiedOn int64
ID int64
}
func (q *Queries) MinusUserBalance(ctx context.Context, arg *MinusUserBalanceParams) (int64, error) {
row := q.db.QueryRow(ctx, minusUserBalance, arg.Balance, arg.ModifiedOn, arg.ID)
var balance int64
err := row.Scan(&balance)
return balance, err
} }

@ -1,78 +0,0 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: authrity.sql
package dbr
import (
"context"
)
const beFriendIds = `-- name: BeFriendIds :many
SELECT user_id FROM p_contact WHERE friend_id=$1 AND status=2 AND is_del=0
`
// ------------------------------------------------------------------------------
// authorization_manage sql dml
// ------------------------------------------------------------------------------
func (q *Queries) BeFriendIds(ctx context.Context, friendID int64) ([]int64, error) {
rows, err := q.db.Query(ctx, beFriendIds, friendID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []int64
for rows.Next() {
var user_id int64
if err := rows.Scan(&user_id); err != nil {
return nil, err
}
items = append(items, user_id)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const isFriend = `-- name: IsFriend :one
SELECT status FROM p_contact WHERE user_id=$1 AND friend_id=$2 AND is_del=0
`
type IsFriendParams struct {
UserID int64
FriendID int64
}
func (q *Queries) IsFriend(ctx context.Context, arg *IsFriendParams) (int16, error) {
row := q.db.QueryRow(ctx, isFriend, arg.UserID, arg.FriendID)
var status int16
err := row.Scan(&status)
return status, err
}
const myFriendSet = `-- name: MyFriendSet :many
SELECT friend_id FROM p_contact WHERE user_id=$1 AND status=2 AND is_del=0
`
func (q *Queries) MyFriendSet(ctx context.Context, userID int64) ([]int64, error) {
rows, err := q.db.Query(ctx, myFriendSet, userID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []int64
for rows.Next() {
var friend_id int64
if err := rows.Scan(&friend_id); err != nil {
return nil, err
}
items = append(items, friend_id)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}

@ -1,116 +0,0 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: comments.sql
package dbr
import (
"context"
)
const deleteComment = `-- name: DeleteComment :exec
UPDATE p_comment SET deleted_on=$1, is_del=1 WHERE id=$2 AND is_del=0
`
type DeleteCommentParams struct {
DeletedOn int64
ID int64
}
// ------------------------------------------------------------------------------
// comment_manage sql dml
// ------------------------------------------------------------------------------
func (q *Queries) DeleteComment(ctx context.Context, arg *DeleteCommentParams) error {
_, err := q.db.Exec(ctx, deleteComment, arg.DeletedOn, arg.ID)
return err
}
const getDefaultComments = `-- name: GetDefaultComments :many
SELECT id, post_id, user_id, ip, ip_loc, created_on, modified_on, deleted_on, is_del, thumbs_up_count, thumbs_down_count FROM p_comment WHERE post_id=$1 AND is_del=0 ORDER BY id ASC LIMIT $2 OFFSET $3
`
type GetDefaultCommentsParams struct {
PostID int64
Limit int32
Offset int32
}
func (q *Queries) GetDefaultComments(ctx context.Context, arg *GetDefaultCommentsParams) ([]*PComment, error) {
rows, err := q.db.Query(ctx, getDefaultComments, arg.PostID, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*PComment
for rows.Next() {
var i PComment
if err := rows.Scan(
&i.ID,
&i.PostID,
&i.UserID,
&i.Ip,
&i.IpLoc,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
&i.ThumbsUpCount,
&i.ThumbsDownCount,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getNewestComments = `-- name: GetNewestComments :many
SELECT id, post_id, user_id, ip, ip_loc, created_on, modified_on, deleted_on, is_del, thumbs_up_count, thumbs_down_count FROM p_comment WHERE post_id=$1 AND is_del=0 ORDER BY id DESC LIMIT $2 OFFSET $3
`
type GetNewestCommentsParams struct {
PostID int64
Limit int32
Offset int32
}
// ------------------------------------------------------------------------------
// comment sql dml
// ------------------------------------------------------------------------------
func (q *Queries) GetNewestComments(ctx context.Context, arg *GetNewestCommentsParams) ([]*PComment, error) {
rows, err := q.db.Query(ctx, getNewestComments, arg.PostID, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*PComment
for rows.Next() {
var i PComment
if err := rows.Scan(
&i.ID,
&i.PostID,
&i.UserID,
&i.Ip,
&i.IpLoc,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
&i.ThumbsUpCount,
&i.ThumbsDownCount,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}

@ -1,35 +0,0 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: contacts.sql
package dbr
import (
"context"
)
const createContact = `-- name: CreateContact :exec
INSERT INTO p_contact (user_id, friend_id, status, created_on) VALUES ($1, $2, $3, $4)
`
type CreateContactParams struct {
UserID int64
FriendID int64
Status int16
CreatedOn int64
}
// ------------------------------------------------------------------------------
// contact_manager sql dml
// ------------------------------------------------------------------------------
func (q *Queries) CreateContact(ctx context.Context, arg *CreateContactParams) error {
_, err := q.db.Exec(ctx, createContact,
arg.UserID,
arg.FriendID,
arg.Status,
arg.CreatedOn,
)
return err
}

@ -1,32 +0,0 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
package dbr
import (
"context"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
)
type DBTX interface {
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
QueryRow(context.Context, string, ...interface{}) pgx.Row
}
func New(db DBTX) *Queries {
return &Queries{db: db}
}
type Queries struct {
db DBTX
}
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
return &Queries{
db: tx,
}
}

@ -1,29 +0,0 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: following.sql
package dbr
import (
"context"
)
const createFollowing = `-- name: CreateFollowing :exec
INSERT INTO p_following (user_id, follow_id, created_on) VALUES ($1, $2, $3)
`
type CreateFollowingParams struct {
UserID int64
FollowID int64
CreatedOn int64
}
// ------------------------------------------------------------------------------
// following_manager sql dml
// ------------------------------------------------------------------------------
func (q *Queries) CreateFollowing(ctx context.Context, arg *CreateFollowingParams) error {
_, err := q.db.Exec(ctx, createFollowing, arg.UserID, arg.FollowID, arg.CreatedOn)
return err
}

@ -1,25 +0,0 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: messages.sql
package dbr
import (
"context"
)
const getUnreadCount = `-- name: GetUnreadCount :one
SELECT count(*) FROM p_message WHERE receiver_user_id=$1 AND is_read=0 AND is_del=0
`
// ------------------------------------------------------------------------------
// message sql dml
// ------------------------------------------------------------------------------
func (q *Queries) GetUnreadCount(ctx context.Context, receiverUserID int64) (int64, error) {
row := q.db.QueryRow(ctx, getUnreadCount, receiverUserID)
var count int64
err := row.Scan(&count)
return count, err
}

@ -1,326 +0,0 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
package dbr
import (
"github.com/jackc/pgx/v5/pgtype"
)
type PAttachment struct {
ID int64
UserID int64
FileSize int64
ImgWidth int64
ImgHeight int64
Type int16
Content string
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PCaptcha struct {
ID int64
Phone pgtype.Text
Captcha pgtype.Text
UseTimes int32
ExpiredOn int64
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PComment struct {
ID int64
PostID int64
UserID int64
Ip string
IpLoc string
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
ThumbsUpCount int32
ThumbsDownCount int32
}
type PCommentContent struct {
ID int64
CommentID int64
UserID int64
Content string
Type int16
Sort int64
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PCommentReply struct {
ID int64
CommentID int64
UserID int64
AtUserID int64
Content string
Ip string
IpLoc string
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
ThumbsUpCount int32
ThumbsDownCount int32
}
type PContact struct {
ID int64
UserID int64
FriendID int64
GroupID int64
Remark string
Status int16
IsTop int16
IsBlack int16
IsDel int16
NoticeEnable int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
}
type PContactGroup struct {
ID int64
UserID int32
Name string
IsDel int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
}
type PFollowing struct {
ID int64
UserID int64
FollowID int64
IsDel int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
}
type PMessage struct {
ID int64
SenderUserID int64
ReceiverUserID int64
Type int16
Brief string
Content string
PostID int64
CommentID int64
ReplyID int64
IsRead int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PPost struct {
ID int64
UserID int64
CommentCount int64
CollectionCount int64
UpvoteCount int64
IsTop int16
IsEssence int16
IsLock int16
LatestRepliedOn int64
Tags string
AttachmentPrice int64
Ip string
IpLoc string
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
Visibility int16
ShareCount int64
}
type PPostAttachmentBill struct {
ID int64
PostID int64
UserID int64
PaidAmount int64
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PPostByComment struct {
ID int64
UserID int64
CommentCount int64
CollectionCount int64
UpvoteCount int64
IsTop int16
IsEssence int16
IsLock int16
LatestRepliedOn int64
Tags string
AttachmentPrice int64
Ip string
IpLoc string
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
Visibility int16
ShareCount int64
CommentUserID int64
}
type PPostByMedium struct {
ID int64
UserID int64
CommentCount int64
CollectionCount int64
UpvoteCount int64
IsTop int16
IsEssence int16
IsLock int16
LatestRepliedOn int64
Tags string
AttachmentPrice int64
Ip string
IpLoc string
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
Visibility int16
ShareCount int64
}
type PPostCollection struct {
ID int64
PostID int64
UserID int64
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PPostContent struct {
ID int64
PostID int64
UserID int64
Content string
Type int16
Sort int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PPostStar struct {
ID int64
PostID int64
UserID int64
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PTag struct {
ID int64
UserID int64
Tag string
QuoteNum int64
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PTopicUser struct {
ID int64
TopicID int64
UserID int64
AliasName pgtype.Text
Remark pgtype.Text
QuoteNum pgtype.Int8
IsTop int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
ReserveA pgtype.Text
ReserveB pgtype.Text
}
type PTweetCommentThumb struct {
ID int64
UserID int64
TweetID int64
CommentID int64
ReplyID pgtype.Int8
CommentType int16
IsThumbsUp int16
IsThumbsDown int16
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PUser struct {
ID int64
Nickname string
Username string
Phone string
Password string
Salt string
Status int16
Avatar string
Balance int64
IsAdmin bool
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PWalletRecharge struct {
ID int64
UserID int64
Amount int64
TradeNo string
TradeStatus string
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}
type PWalletStatement struct {
ID int64
UserID int64
ChangeAmount int64
BalanceSnapshot int64
Reason string
PostID int64
CreatedOn int64
ModifiedOn int64
DeletedOn int64
IsDel int16
}

@ -1,70 +0,0 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
package dbr
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
type Querier interface {
//------------------------------------------------------------------------------
// authorization_manage sql dml
//------------------------------------------------------------------------------
BeFriendIds(ctx context.Context, friendID int64) ([]int64, error)
//------------------------------------------------------------------------------
// contact_manager sql dml
//------------------------------------------------------------------------------
CreateContact(ctx context.Context, arg *CreateContactParams) error
//------------------------------------------------------------------------------
// following_manager sql dml
//------------------------------------------------------------------------------
CreateFollowing(ctx context.Context, arg *CreateFollowingParams) error
DecrTagsById(ctx context.Context, arg *DecrTagsByIdParams) error
//------------------------------------------------------------------------------
// comment_manage sql dml
//------------------------------------------------------------------------------
DeleteComment(ctx context.Context, arg *DeleteCommentParams) error
GetDefaultComments(ctx context.Context, arg *GetDefaultCommentsParams) ([]*PComment, error)
//------------------------------------------------------------------------------
// security sql dml
//------------------------------------------------------------------------------
GetLatestPhoneCaptcha(ctx context.Context, phone pgtype.Text) (*PCaptcha, error)
//------------------------------------------------------------------------------
// comment sql dml
//------------------------------------------------------------------------------
GetNewestComments(ctx context.Context, arg *GetNewestCommentsParams) ([]*PComment, error)
//------------------------------------------------------------------------------
// tweet sql dml
//------------------------------------------------------------------------------
GetPostById(ctx context.Context, id int64) (*PPost, error)
//------------------------------------------------------------------------------
// message sql dml
//------------------------------------------------------------------------------
GetUnreadCount(ctx context.Context, receiverUserID int64) (int64, error)
//------------------------------------------------------------------------------
// user_manage sql dml
//------------------------------------------------------------------------------
GetUserById(ctx context.Context, id int64) (*PUser, error)
//------------------------------------------------------------------------------
// wallet sql dml
//------------------------------------------------------------------------------
GetUserWalletBills(ctx context.Context, arg *GetUserWalletBillsParams) (*PWalletStatement, error)
HotTags(ctx context.Context, arg *HotTagsParams) ([]*HotTagsRow, error)
IncrTags(ctx context.Context, arg *IncrTagsParams) ([]*IncrTagsRow, error)
//------------------------------------------------------------------------------
// ship_index sql dml
//------------------------------------------------------------------------------
IndexByAdmin(ctx context.Context, arg *IndexByAdminParams) ([]*PPost, error)
InsertTags(ctx context.Context, arg *InsertTagsParams) (int64, error)
IsFriend(ctx context.Context, arg *IsFriendParams) (int16, error)
MyFriendSet(ctx context.Context, userID int64) ([]int64, error)
NewestTags(ctx context.Context, arg *NewestTagsParams) ([]*NewestTagsRow, error)
TagsByKeywordA(ctx context.Context) ([]*TagsByKeywordARow, error)
TagsByKeywordB(ctx context.Context, tag string) ([]*TagsByKeywordBRow, error)
}
var _ Querier = (*Queries)(nil)

@ -7,6 +7,3 @@ SELECT user_id FROM p_contact WHERE friend_id=$1 AND status=2 AND is_del=0;
-- name: MyFriendSet :many -- name: MyFriendSet :many
SELECT friend_id FROM p_contact WHERE user_id=$1 AND status=2 AND is_del=0; SELECT friend_id FROM p_contact WHERE user_id=$1 AND status=2 AND is_del=0;
-- name: IsFriend :one
SELECT status FROM p_contact WHERE user_id=$1 AND friend_id=$2 AND is_del=0;

@ -3,10 +3,56 @@
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- name: GetNewestComments :many -- name: GetNewestComments :many
SELECT * FROM p_comment WHERE post_id=$1 AND is_del=0 ORDER BY id DESC LIMIT $2 OFFSET $3; SELECT *
FROM p_comment
WHERE post_id=$1 AND is_del=0
ORDER BY is_essence DESC, id DESC
LIMIT $2 OFFSET $3;
-- name: GetHotsComments :many
SELECT c.*
FROM p_comment c
LEFT JOIN p_comment_metric m
ON c.id=m.comment_id
WHERE c.post_id=$1 AND c.is_del=0 AND m.is_del=0
ORDER BY is_essence DESC, m.rank_score DESC, c.id DESC
LIMIT $2 OFFSET $3;
-- name: GetDefaultComments :many -- name: GetDefaultComments :many
SELECT * FROM p_comment WHERE post_id=$1 AND is_del=0 ORDER BY id ASC LIMIT $2 OFFSET $3; SELECT *
FROM p_comment
WHERE post_id=$1 AND is_del=0
ORDER BY is_essence DESC, id ASC
LIMIT $2 OFFSET $3;
-- name: GetCommentById :one
SELECT * FROM p_comment WHERE id=$1 AND is_del=0;
-- name: GetCommentCount :one
SELECT count(*) FROM p_comment WHERE post_id=$1 AND is_del=0;
-- name: GetCommentReplyById :one
SELECT * FROM p_comment_reply WHERE id=$1 AND is_del=0;
-- name: GetCommentContentsByIds :many
SELECT * FROM p_comment_content WHERE comment_id = ANY(@ids::BIGINT[]);
-- name: GetCommentRepliesByIds :many
SELECT *
FROM p_comment_reply
WHERE comment_id = ANY(@ids::BIGINT[])
ORDER BY id ASC;
-- name: GetCommentThumbs :many
SELECT user_id,
tweet_id,
comment_id,
reply_id,
comment_type,
is_thumbs_up,
is_thumbs_down
FROM p_tweet_comment_thumbs
WHERE user_id=$1 AND tweet_id=$2;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- comment_manage sql dml -- comment_manage sql dml
@ -14,3 +60,76 @@ SELECT * FROM p_comment WHERE post_id=$1 AND is_del=0 ORDER BY id ASC LIMIT $2 O
-- name: DeleteComment :exec -- name: DeleteComment :exec
UPDATE p_comment SET deleted_on=$1, is_del=1 WHERE id=$2 AND is_del=0; UPDATE p_comment SET deleted_on=$1, is_del=1 WHERE id=$2 AND is_del=0;
-- name: DeleteCommentThumbs :exec
UPDATE p_tweet_comment_thumbs
SET deleted_on=$1, is_del=1
WHERE user_id=$2 AND tweet_id=$3 AND comment_id=$4 AND is_del=0;
-- name: CreateComment :one
INSERT INTO p_comment (post_id, user_id, ip, ip_loc, created_on)
VALUES ($1, $2, $3, $4, $5)
RETURNING id;
-- name: CreateCommentReply :one
INSERT INTO p_comment_reply (comment_id, user_id, content, at_user_id, ip, ip_loc, created_on)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id;
-- name: IncrCommentReplyCount :exec
UPDATE p_comment
SET reply_count=reply_count+1,
modified_on=$1
WHERE id=$2 AND is_del=0;
-- name: DecrCommentReplyCount :exec
UPDATE p_comment
SET reply_count=reply_count-1,
modified_on=$1
WHERE id=$2 AND is_del=0;
-- name: DeleteCommentReply :exec
UPDATE p_comment_reply SET deleted_on=$1, is_del=1 WHERE id=$2 AND is_del=0;
-- name: DeleteReplyThumbs :exec
UPDATE p_tweet_comment_thumbs
SET deleted_on=$1, is_del=1
WHERE user_id=$2 AND comment_id=$3 AND reply_id=$4 AND is_del=0;
-- name: CreateCommentContent :one
INSERT INTO p_comment_content (comment_id, user_id, content, type, sort, created_on)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id;
-- name: UpdateThumbsUpDownComment :exec
UPDATE p_tweet_comment_thumbs
SET is_thumbs_up=$1,
is_thumbs_down=$2,
modified_on=$3
WHERE id=$4 AND is_del=0;
-- name: CreateThumbsUpDownComment :one
INSERT INTO p_tweet_comment_thumbs (user_id, tweet_id, comment_id,
reply_id, is_thumbs_up, is_thumbs_down, comment_type, created_on)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING id;
-- name: UpdateCommentThumbsCount :exec
UPDATE p_comment
SET thumbs_up_count=$1, Thumbs_down_count=$2, modified_on=$3
WHERE id=$4 AND is_del=0;
-- name: GetTweetCommentThumb :one
SELECT *
FROM p_tweet_comment_thumbs
WHERE user_id=$1 AND tweet_id=$2 AND comment_id=$3 AND comment_type=0 AND is_del=0;
-- name: GetCommentReplyThumb :one
SELECT *
FROM p_tweet_comment_thumbs
WHERE user_id=$1 AND tweet_id=$2 AND comment_id=$3 AND reply_id=$4 AND comment_type=1 AND is_del=0;
-- name: UpdateReplyThumbsCount :exec
UPDATE p_comment_reply
SET thumbs_up_count=$1, thumbs_down_count=$2, modified_on=$3
WHERE id=$4 AND is_del=0;

@ -4,3 +4,60 @@
-- name: CreateContact :exec -- name: CreateContact :exec
INSERT INTO p_contact (user_id, friend_id, status, created_on) VALUES ($1, $2, $3, $4); INSERT INTO p_contact (user_id, friend_id, status, created_on) VALUES ($1, $2, $3, $4);
-- name: FreshContactStatus :exec
UPDATE p_contact SET status=$1, modified_on=$2, is_del=0 WHERE id=$3;
-- name: CreateMessage :one
INSERT INTO p_message (sender_user_id, receiver_user_id, type, brief, content, reply_id, created_on)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id;
-- name: AddFriendMsgsUpdate :exec
UPDATE p_message
SET reply_id=$1, modified_on=$2
WHERE ((sender_user_id = $3 AND receiver_user_id = $4) OR
(sender_user_id = $4 AND receiver_user_id = $3)) AND
type = $5 AND reply_id = $6;
-- name: RejectFriendMsgsUpdate :exec
UPDATE p_message
SET reply_id=$1, modified_on=$2
WHERE sender_user_id=$3 AND receiver_user_id=$4 AND type=$5 AND reply_id=$6;
-- name: DeleteFriend :exec
UPDATE p_contact SET status=4, is_del=1, deleted_on=$1 WHERE id=$2;
-- name: ListFriend :many
SELECT c.friend_id user_id,
u.username username,
u.nickname nickname,
u.avatar avatar,
u.phone phone
FROM p_contact c
JOIN p_user u
ON c.friend_id=u.id
WHERE c.user_id=$1 AND c.status=2 AND c.is_del=0
ORDER BY u.nickname ASC
LIMIT $2 OFFSET $3;
-- name: CountFriendsById :one
SELECT count(*) FROM p_contact WHERE user_id=$1 AND status=2 AND is_del=0;
-- name: GetContacts :many
SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del
FROM p_contact
WHERE (user_id=$1 AND friend_id=$2) OR (user_id=$3 AND friend_id=$4);
-- name: GetUserFriend :one
SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del
FROM p_contact
WHERE user_id=$1 AND friend_id=$2 AND is_del=0;
-- name: GetContact :one
SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del
FROM p_contact
WHERE user_id=$1 AND friend_id=$2;
-- name: IsFriend :one
SELECT true FROM p_contact WHERE user_id=$1 AND friend_id=$2 AND is_del=0 AND status=2;

@ -3,4 +3,42 @@
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- name: CreateFollowing :exec -- name: CreateFollowing :exec
INSERT INTO p_following (user_id, follow_id, created_on) VALUES ($1, $2, $3); INSERT INTO p_following (user_id, follow_id, created_on)
VALUES ($1, $2, $3)
RETURNING id;
-- name: ExistFollowing :one
SELECT 1 FROM p_following WHERE user_id=$1 AND follow_id=$2 AND is_del=0;
-- name: DeleteFollowing :exec
UPDATE p_following
SET is_del=1, deleted_on=$1
WHERE user_id=$2 AND follow_id=$3 AND is_del=0;
-- name: ListFollows :many
SELECT u.id user_id,
u.username username,
u.nickname nickname,
u.avatar avatar,
u.created_on created_on
FROM p_following f JOIN p_user u ON f.follow_id=u.id
WHERE f.user_id=$1 AND f.is_del=0
ORDER BY u.nickname ASC
LIMIT $2 OFFSET $3;
-- name: CountFollows :one
SELECT count(*) FROM p_following WHERE user_id=$1 AND is_del=0;
-- name: ListFollowings :many
SELECT u.id user_id,
u.username username,
u.nickname nickname,
u.avatar avatar,
u.created_on created_on
FROM p_following f JOIN p_user u ON f.user_id=u.id
WHERE f.follow_id=$1 AND f.is_del=0
ORDER BY u.nickname ASC
LIMIT $2 OFFSET $3;
-- name: CountFollowings :one
SELECT count(*) FROM p_following WHERE follow_id=$1 AND is_del=0;

@ -4,3 +4,72 @@
-- name: GetUnreadCount :one -- name: GetUnreadCount :one
SELECT count(*) FROM p_message WHERE receiver_user_id=$1 AND is_read=0 AND is_del=0; SELECT count(*) FROM p_message WHERE receiver_user_id=$1 AND is_read=0 AND is_del=0;
-- name: GetMessageById :one
SELECT * FROM p_message WHERE id=$1 AND is_del=0;
-- name: ReadMessage :exec
UPDATE p_message SET is_read=1, modified_on=$1 WHERE id=$2;
-- name: ReadAllMessage :exec
UPDATE p_message SET is_read=1, modified_on=$1 WHERE receiver_user_id=$2;
-- name: GetSystemMessages :many
SELECT *
FROM p_message
WHERE receiver_user_id=$1 AND type IN (1, 2, 3, 99) AND is_del=0
ORDER BY id DESC
LIMIT $2 OFFSET $3;
-- name: CountSystemMessages :one
SELECT count(*)
FROM p_message
WHERE receiver_user_id=$1 AND type IN (1, 2, 3, 99) AND is_del=0;
-- name: GetWhisperMessages :many
SELECT *
FROM p_message
WHERE ((receiver_user_id=$1 OR sender_user_id=$2) AND type=4) AND is_del=0
ORDER BY id DESC
LIMIT $3 OFFSET $4;
-- name: CountWhisperMessages :one
SELECT count(*)
FROM p_message
WHERE ((receiver_user_id=$1 OR sender_user_id=$2) AND type=4) AND is_del=0;
-- name: GetRequestingMessages :many
SELECT *
FROM p_message
WHERE receiver_user_id=$1 AND type=5 AND is_del=0
ORDER BY id DESC
LIMIT $2 OFFSET $3;
-- name: CountRequestingMessages :one
SELECT count(*)
FROM p_message
WHERE receiver_user_id=$1 AND type=5 AND is_del=0;
-- name: GetUnreadMessages :many
SELECT *
FROM p_message
WHERE receiver_user_id=$1 AND is_read=0 AND is_del=0
ORDER BY id DESC
LIMIT $2 OFFSET $3;
-- name: CountUnreadMessages :one
SELECT count(*)
FROM p_message
WHERE receiver_user_id=$1 AND is_read=0 AND is_del=0;
-- name: GetAllMessages :many
SELECT *
FROM p_message
WHERE (receiver_user_id=$1 OR (sender_user_id=$2 AND type=4)) AND is_del=0
ORDER BY id DESC
LIMIT $3 OFFSET $4;
-- name: CountAllMessages :one
SELECT count(*)
FROM p_message
WHERE (receiver_user_id=$1 OR (sender_user_id=$2 AND type=4)) AND is_del=0;

@ -0,0 +1,59 @@
--------------------------------------------------------------------------------
-- tweet_metrics sql dml
--------------------------------------------------------------------------------
-- name: UpdateTweetMetric :exec
UPDATE p_post_metric SET rank_score=$1, modified_on=$2 WHERE post_id=$3 AND is_del=0;
-- name: TweetMotivationFactor :one
SELECT motivation_factor FROM p_post_metric WHERE post_id=$1 AND is_del=0;
-- name: AddTweetMetric :one
INSERT INTO p_post_metric (post_id, created_on)
VALUES ($1, $2)
RETURNING id;
-- name: UpsertTweetMetric :exec
INSERT INTO p_post_metric (post_id, rank_score, created_on) VALUES ($1, $2, $3);
-- name: DeleteTweetMetric :exec
UPDATE p_post_metric SET is_del=1, deleted_on=$1 WHERE post_id=$2 AND is_del=0;
--------------------------------------------------------------------------------
-- comment_metrics sql dml
--------------------------------------------------------------------------------
-- name: UpdateCommentMetric :exec
UPDATE p_comment_metric SET rank_score=$1, modified_on=$2 WHERE comment_id=$3 AND is_del=0;
-- name: CommentMotivationFactor :one
SELECT motivation_factor FROM p_comment_metric WHERE comment_id=$1 AND is_del=0;
-- name: AddCommentMetric :one
INSERT INTO p_comment_metric (comment_id, created_on)
VALUES ($1, $2)
RETURNING id;
-- name: UpsertCommentMetric :exec
INSERT INTO p_comment_metric (comment_id, rank_score, created_on)
VALUES ($1, $2, $3)
RETURNING id;
-- name: DeleteCommentMetric :exec
UPDATE p_comment_metric SET is_del=1, deleted_on=$1 WHERE comment_id=$2 AND is_del=0;
--------------------------------------------------------------------------------
-- user_metrics sql dml
--------------------------------------------------------------------------------
-- name: UpdateUserMetric :exec
UPDATE p_user_metric SET tweets_count=$1, modified_on=$2 WHERE user_id=$3 AND is_del=0;
-- name: GetUserTweetsCount :one
SELECT tweets_count FROM p_user_metric WHERE user_id=$1 AND is_del=0;
-- name: AddUserMetric :one
INSERT INTO p_user_metric (user_id, created_on) VALUES ($1, $2) RETURNING id;
-- name: DeleteUserMetric :exec
UPDATE p_user_metric SET is_del=1, deleted_on=$1 WHERE user_id=$2 AND is_del=0;

@ -4,3 +4,11 @@
-- name: GetLatestPhoneCaptcha :one -- name: GetLatestPhoneCaptcha :one
SELECT * FROM p_captcha WHERE phone=$1 AND is_del=0; SELECT * FROM p_captcha WHERE phone=$1 AND is_del=0;
-- name: UsePhoneCaptcha :exec
UPDATE p_captcha SET use_times=use_times+1, modified_on=$1 WHERE id=$2 AND is_del=0;
-- name: CreatePhoneCaptcha :one
INSERT INTO p_captcha (phone, captcha, expired_on, created_on)
VALUES ($1, $2, $3, $4)
RETURNING id;

@ -0,0 +1,24 @@
--------------------------------------------------------------------------------
-- trends_manager sql dml
--------------------------------------------------------------------------------
-- name: GetIndexTrends :many
SELECT u.username username,
u.nickname nickname,
u.avatar avatar
FROM p_contact c
JOIN p_user u
ON c.friend_id=u.id
JOIN p_user_metric m
ON c.friend_id=m.user_id
WHERE c.user_id=$1 AND c.is_del=0 AND u.is_del=0 AND m.is_del=0 AND m.tweets_count>0
LIMIT $2 OFFSET $3;
-- name: CountIndexTrends :one
SELECT count(*)
FROM p_contact c
JOIN p_user u
ON c.friend_id=u.id
JOIN p_user_metric m
ON c.friend_id=m.user_id
WHERE c.user_id=$1 AND c.is_del=0 AND u.is_del=0 AND m.is_del=0 AND m.tweets_count>0;

@ -4,3 +4,717 @@
-- name: GetPostById :one -- name: GetPostById :one
SELECT * FROM p_post WHERE id=$1 AND is_del=0; SELECT * FROM p_post WHERE id=$1 AND is_del=0;
-- name: GetUserPosts :many
SELECT * FROM p_post
WHERE user_id=$1 AND visibility IN ($1) AND is_del=0
ORDER BY latest_replied_on DESC
LIMIT $2 OFFSET $3;
-- name: GetAnyPosts :many
SELECT * FROM p_post WHERE visibility IN ($1) AND is_del=0 LIMIT $2 OFFSET $3;
-- name: CountUserPosts :one
SELECT count(*) FROM p_post WHERE user_id=$1 AND visibility IN ($2) AND is_del=0;
-- name: CountAnyPost :one
SELECT count(*) FROM p_post WHERE visibility IN ($1) AND is_del=0;
-- name: GetUserPostStar :one
SELECT
s.*,
P.ID "post.id",
P.user_id "post.user_id",
P.comment_count "post.comment_count",
P.collection_count "post.collection_count",
P.upvote_count "post.upvote_count",
P.share_count "post.share_count",
P.visibility "post.visibility",
P.is_top "post.is_top",
P.is_essence "post.is_essence",
P.is_lock "post.is_lock",
P.latest_replied_on "post.latest_replied_on",
P.tags "post.tags",
P.attachment_price "post.attachment_price",
P.ip "post.ip",
P.ip_loc "post.ip_loc",
P.is_del "post.is_del",
P.created_on "post.created_on",
P.modified_on "post.modified_on",
P.deleted_on "post.deleted_on"
FROM
p_post_star s
JOIN p_post P ON s.post_id = P.ID
WHERE
s.post_id = $1
AND s.user_id = $2
AND s.is_del = 0
AND (visibility >= 50 OR (visibility = 0 AND P.user_id = $3 ));
-- name: GetUserPostStars :many
SELECT
s.*,
P.ID "post.id",
P.user_id "post.user_id",
P.comment_count "post.comment_count",
P.collection_count "post.collection_count",
P.upvote_count "post.upvote_count",
P.share_count "post.share_count",
P.visibility "post.visibility",
P.is_top "post.is_top",
P.is_essence "post.is_essence",
P.is_lock "post.is_lock",
P.latest_replied_on "post.latest_replied_on",
P.tags "post.tags",
P.attachment_price "post.attachment_price",
P.ip "post.ip",
P.ip_loc "post.ip_loc",
P.is_del "post.is_del",
P.created_on "post.created_on",
P.modified_on "post.modified_on",
P.deleted_on "post.deleted_on"
FROM
p_post_star s
JOIN p_post P ON s.post_id = P.ID
WHERE
s.user_id = $1
AND s.is_del = 0
AND (visibility >= 50 OR (visibility = 0 AND P.user_id = $2))
ORDER BY
s.ID DESC,
P.ID DESC
LIMIT $3 OFFSET $4;
-- name: CountUserPostStars :one
SELECT
count(*)
FROM
p_post_star s
JOIN p_post P ON s.post_id = P.ID
WHERE
s.user_id = $1
AND s.is_del = 0
AND (visibility >= 50 OR (visibility = 0 AND P.user_id = $2));
-- name: GetUserPostCollection :one
SELECT
s.*,
P.ID "post.id",
P.user_id "post.user_id",
P.comment_count "post.comment_count",
P.collection_count "post.collection_count",
P.upvote_count "post.upvote_count",
P.share_count "post.share_count",
P.visibility "post.visibility",
P.is_top "post.is_top",
P.is_essence "post.is_essence",
P.is_lock "post.is_lock",
P.latest_replied_on "post.latest_replied_on",
P.tags "post.tags",
P.attachment_price "post.attachment_price",
P.ip "post.ip",
P.ip_loc "post.ip_loc",
P.is_del "post.is_del",
P.created_on "post.created_on",
P.modified_on "post.modified_on",
P.deleted_on "post.deleted_on"
FROM
p_post_collection s
JOIN p_post P ON s.post_id = P.ID
WHERE
s.post_id = $1
AND s.user_id = $2
AND s.is_del = 0
AND (visibility >= 50 OR (visibility = 0 AND P.user_id = $3));
-- name: GetUserPostCollections :many
SELECT
s.*,
P.ID "post.id",
P.user_id "post.user_id",
P.comment_count "post.comment_count",
P.collection_count "post.collection_count",
P.upvote_count "post.upvote_count",
P.share_count "post.share_count",
P.visibility "post.visibility",
P.is_top "post.is_top",
P.is_essence "post.is_essence",
P.is_lock "post.is_lock",
P.latest_replied_on "post.latest_replied_on",
P.tags "post.tags",
P.attachment_price "post.attachment_price",
P.ip "post.ip",
P.ip_loc "post.ip_loc",
P.is_del "post.is_del",
P.created_on "post.created_on",
P.modified_on "post.modified_on",
P.deleted_on "post.deleted_on"
FROM
p_post_collection s
JOIN p_post P ON s.post_id = P.ID
WHERE
s.user_id = $1
AND s.is_del = 0
AND (visibility >= 50 OR ( visibility = 0 AND P.user_id = $2 ) )
ORDER BY
s.ID DESC,
P.ID DESC
LIMIT $3 OFFSET $4;
-- CountGetUserPostCollection :one
SELECT
count(*)
FROM
p_post_collection s
JOIN p_post P ON s.post_id = P.ID
WHERE
s.user_id = $1
AND s.is_del = 0
AND (visibility >= 50 OR (visibility = 0 AND P.user_id = $2));
-- name: GetPostAttachementBill :one
SELECT * FROM p_post_attachment_bill WHERE post_id=$1 AND user_id=$2 AND is_del=0;
-- name: GetPostContentsByIds :many
SELECT *
FROM p_post_content
WHERE post_id = ANY(@ids::BIGINT[]) AND is_del=0;
-- name: GetPostContentById :one
SELECT * FROM p_post_content WHERE id=$1 AND is_del=0;
-- name: UserMediaTweetsByGuest :many
SELECT id,
user_id,
comment_count,
collection_count,
upvote_count,
share_count,
visibility,
is_top,
is_essence,
is_lock,
latest_replied_on,
tags,
attachment_price,
ip,
ip_loc,
created_on,
modified_on,
deleted_on,
is_del
FROM p_post_by_media
WHERE is_del=0 AND user_id=$1 AND visibility=90
ORDER BY latest_replied_on DESC
LIMIT $2 OFFSET $3;
-- name: CountUserMediaTweetsByGuest :one
SELECT count(*)
FROM p_post_by_media
WHERE is_del=0 AND user_id=$1 AND visibility>=90;
-- name: UserMediaTweetsByFriend :many
SELECT id,
user_id,
comment_count,
collection_count,
upvote_count,
share_count,
visibility,
is_top,
is_essence,
is_lock,
latest_replied_on,
tags,
attachment_price,
ip,
ip_loc,
created_on,
modified_on,
deleted_on,
is_del
FROM p_post_by_media
WHERE is_del=0 AND user_id=$1 AND visibility>=50
ORDER BY latest_replied_on DESC
LIMIT $2 OFFSET $3;
-- name: CountUserMediaTweetsByFriend :one
SELECT count(*)
FROM p_post_by_media
WHERE is_del=0 AND user_id=$1 AND visibility>=50;
-- name: UserMediaTweetsBySelf :many
SELECT id,
user_id,
comment_count,
collection_count,
upvote_count,
share_count,
visibility,
is_top,
is_essence,
is_lock,
latest_replied_on,
tags,
attachment_price,
ip,
ip_loc,
created_on,
modified_on,
deleted_on,
is_del
FROM p_post_by_media
WHERE is_del=0 AND user_id=$1
ORDER BY latest_replied_on DESC
LIMIT $2 OFFSET $3;
-- name: CountUserMediaTweetsBySelf :one
SELECT count(*)
FROM p_post_by_media
WHERE is_del=0 AND user_id=$1;
-- name: UserCommentTweetsByGuest :many
SELECT id,
user_id,
comment_count,
collection_count,
upvote_count,
share_count,
visibility,
is_top,
is_essence,
is_lock,
latest_replied_on,
tags,
attachment_price,
ip,
ip_loc,
created_on,
modified_on,
deleted_on,
is_del
FROM p_post_by_comment
WHERE is_del=0 AND comment_user_id=$1 AND visibility>=90
ORDER BY latest_replied_on DESC
LIMIT $2 OFFSET $3;
-- name: CountUserCommentTweetsByGuest :one
SELECT count(*)
FROM p_post_by_comment
WHERE is_del=0 AND comment_user_id=$1 AND visibility>=90;
-- name: UserCommentTweetsByFriend :many
SELECT id,
user_id,
comment_count,
collection_count,
upvote_count,
share_count,
visibility,
is_top,
is_essence,
is_lock,
latest_replied_on,
tags,
attachment_price,
ip,
ip_loc,
created_on,
modified_on,
deleted_on,
is_del
FROM p_post_by_comment
WHERE is_del=0 AND comment_user_id=$1 AND visibility>=50
ORDER BY latest_replied_on DESC
LIMIT $2 OFFSET $3;
-- name: CountUserCommentTweetsByFriend :one
SELECT count(*)
FROM p_post_by_comment
WHERE is_del=0 AND comment_user_id=$1 AND visibility>=50;
-- name: UserCommentTweetsBySelf :many
SELECT id,
user_id,
comment_count,
collection_count,
upvote_count,
share_count,
visibility,
is_top,
is_essence,
is_lock,
latest_replied_on,
tags,
attachment_price,
ip,
ip_loc,
created_on,
modified_on,
deleted_on,
is_del
FROM p_post_by_comment
WHERE is_del=0 AND comment_user_id=$1
ORDER BY latest_replied_on DESC
LIMIT $2 OFFSET $3;
-- name: CountUserCommentTweetsBySelf :one
SELECT count(*)
FROM p_post_by_comment
WHERE is_del=0 AND comment_user_id=$1;
-- name: UserStarTweetsByGuest :many
SELECT
star.*,
post.ID "post.id",
post.created_on "post.created_on",
post.modified_on "post.modified_on",
post.deleted_on "post.deleted_on",
post.is_del "post.is_del",
post.user_id "post.user_id",
post.comment_count "post.comment_count",
post.collection_count "post.collection_count",
post.share_count "post.share_count",
post.upvote_count "post.upvote_count",
post.visibility "post.visibility",
post.is_top "post.is_top",
post.is_essence "post.is_essence",
post.is_lock "post.is_lock",
post.latest_replied_on "post.latest_replied_on",
post.tags "post.tags",
post.attachment_price "post.attachment_price",
post.ip "post.ip",
post.ip_loc "post.ip_loc"
FROM
p_post_star star
JOIN p_post post ON star.post_id = post.ID
WHERE
star.is_del=0
AND star.user_id=$1
AND post.visibility>=90
ORDER BY post.latest_replied_on DESC
LIMIT $2 OFFSET $3;
-- name: CountUserStarTweetsByGuest :one
SELECT count(*)
FROM
p_post_star star
JOIN p_post post ON star.post_id = post.ID
WHERE star.is_del=0 AND star.user_id=$1 AND post.visibility>=90;
-- name: UserStarTweetsByFriend :many
SELECT
star.*,
post.ID "post.id",
post.created_on "post.created_on",
post.modified_on "post.modified_on",
post.deleted_on "post.deleted_on",
post.is_del "post.is_del",
post.user_id "post.user_id",
post.comment_count "post.comment_count",
post.collection_count "post.collection_count",
post.share_count "post.share_count",
post.upvote_count "post.upvote_count",
post.visibility "post.visibility",
post.is_top "post.is_top",
post.is_essence "post.is_essence",
post.is_lock "post.is_lock",
post.latest_replied_on "post.latest_replied_on",
post.tags "post.tags",
post.attachment_price "post.attachment_price",
post.ip "post.ip",
post.ip_loc "post.ip_loc"
FROM
p_post_star star
JOIN p_post post ON star.post_id = post.ID
WHERE star.is_del=0 AND star.user_id=$1 AND post.visibility>=50
ORDER BY post.latest_replied_on DESC
LIMIT $2 OFFSET $3;
-- name: CountUserStarTweetsByFriend :one
SELECT count(*)
FROM
p_post_star star
JOIN p_post post ON star.post_id = post.ID
WHERE star.is_del=0 AND star.user_id=$1 AND post.visibility>=50;
-- name: UserStarTweetsBySelf :many
SELECT
star.*,
post.ID "post.id",
post.created_on "post.created_on",
post.modified_on "post.modified_on",
post.deleted_on "post.deleted_on",
post.is_del "post.is_del",
post.user_id "post.user_id",
post.comment_count "post.comment_count",
post.collection_count "post.collection_count",
post.share_count "post.share_count",
post.upvote_count "post.upvote_count",
post.visibility "post.visibility",
post.is_top "post.is_top",
post.is_essence "post.is_essence",
post.is_lock "post.is_lock",
post.latest_replied_on "post.latest_replied_on",
post.tags "post.tags",
post.attachment_price "post.attachment_price",
post.ip "post.ip",
post.ip_loc "post.ip_loc"
FROM
p_post_star star
JOIN p_post post ON star.post_id = post.ID
WHERE star.is_del=0 AND star.user_id=$1 AND (post.visibility<>90 OR (post.visibility>=90 AND post.user_id=$2))
ORDER BY post.latest_replied_on DESC
LIMIT $3 OFFSET $4;
-- name: CountUserStarTweetsBySelf :one
SELECT count(*)
FROM
p_post_star star
JOIN p_post post ON star.post_id = post.ID
WHERE star.is_del=0 AND star.user_id=$1 AND (post.visibility<>90 OR (post.visibility>=90 AND post.user_id=$2));
-- name: UserStarTweetsByAdmin :many
SELECT
star.*,
post.ID "post.id",
post.created_on "post.created_on",
post.modified_on "post.modified_on",
post.deleted_on "post.deleted_on",
post.is_del "post.is_del",
post.user_id "post.user_id",
post.comment_count "post.comment_count",
post.collection_count "post.collection_count",
post.share_count "post.share_count",
post.upvote_count "post.upvote_count",
post.visibility "post.visibility",
post.is_top "post.is_top",
post.is_essence "post.is_essence",
post.is_lock "post.is_lock",
post.latest_replied_on "post.latest_replied_on",
post.tags "post.tags",
post.attachment_price "post.attachment_price",
post.ip "post.ip",
post.ip_loc "post.ip_loc"
FROM
p_post_star star
JOIN p_post post ON star.post_id = post.ID
WHERE star.is_del=0 AND star.user_id=$1
ORDER BY post.latest_replied_on DESC
LIMIT $2 OFFSET $3;
-- name: CountUserStarTweetsByAdmin :one
SELECT count(*)
FROM
p_post_star star
JOIN p_post post ON star.post_id = post.ID
WHERE star.is_del=0 AND star.user_id=$1;
-- name: ListUserTweets :many
SELECT *
FROM p_post
WHERE user_id=$1 AND visibility>=$2 AND is_essence=$3 AND is_del=0
ORDER BY is_top DESC, latest_replied_on DESC
LIMIT $4 OFFSET $5;
-- name: CountUserTweets :one
SELECT count(*)
FROM p_post
WHERE user_id=$1 AND visibility>=$2 AND is_essence=$3 AND is_del=0;
-- name: ListIndexNewestTweets :many
SELECT *
FROM p_post
WHERE visibility>=90 AND is_del=0
ORDER BY is_top DESC, latest_replied_on DESC
LIMIT $1 OFFSET $2;
-- name: CountIndexNewestTweets :one
SELECT count(*)
FROM p_post
WHERE visibility>=90 AND is_del=0;
-- name: ListIndexHotsTweets :many
SELECT post.*
FROM p_post post
LEFT JOIN p_post_metric metric
ON post.id=metric.post_id
WHERE post.visibility>=90 AND post.is_del=0
ORDER BY post.is_top DESC, metric.rank_score DESC, post.latest_replied_on DESC
LIMIT $1 OFFSET $2;
-- name: CountIndexHotsTweets :one
SELECT count(*)
FROM p_post post
LEFT JOIN p_post_metric metric
ON post.id=metric.post_id AND metric.is_del=0
WHERE post.visibility>=90 AND post.is_del=0;
-- name: ListSyncSearchTweets :many
SELECT *
FROM p_post
WHERE visibility>=50 AND is_del=0
LIMIT $1 OFFSET $2;
-- name: CountSyncSearchTweets :one
SELECT count(*)
FROM p_post
WHERE visibility>=50 AND is_del=0;
-- name: ListFollowingTweetsFriendFollow :many
SELECT *
FROM p_post
WHERE (user_id=$1 OR (visibility>=50 AND user_id = ANY(@friendIds::BIGINT[])) OR (visibility>=60 AND user_id = ANY(@followIds::BIGINT[]))) AND is_del=0
ORDER BY is_top DESC, latest_replied_on DESC
LIMIT $2 OFFSET $3;
-- name: CountFollowingTweetsFriendFollow :one
SELECT count(*)
FROM p_post
WHERE (user_id=$1 OR (visibility>=50 AND user_id = ANY(@fiendIds::BIGINT[])) OR (visibility>=60 AND user_id = ANY(@followIds::BIGINT[]))) AND is_del=0;
-- name: ListFollowingTweetsFriend :many
SELECT *
FROM p_post
WHERE (user_id=$1 OR (visibility>=50 AND user_id = ANY(@friendIds::BIGINT[]))) AND is_del=0
ORDER BY is_top DESC, latest_replied_on DESC
LIMIT $2 OFFSET $3;
-- name: CountListFollowingTweetsFriend :one
SELECT count(*)
FROM p_post
WHERE (user_id=$1 OR (visibility>=50 AND user_id = ANY(@friendIds::BIGINT[]))) AND is_del=0;
-- name: ListFollowingTweetsFollow :many
SELECT *
FROM p_post
WHERE (user_id=$1 OR (visibility>=60 AND user_id = ANY(@followIds::BIGINT[]))) AND is_del=0
ORDER BY is_top DESC, latest_replied_on DESC
LIMIT $2 OFFSET $3;
-- name: CountFollowingTweetsFollow :one
SELECT count(*)
FROM p_post
WHERE (user_id=$1 OR (visibility>=60 AND user_id = ANY(@followIds::BIGINT[]))) AND is_del=0;
-- name: ListFollowingTweets :many
SELECT *
FROM p_post
WHERE user_id=$1 AND is_del=0
ORDER BY is_top DESC, latest_replied_on DESC
LIMIT $2 OFFSET $3;
-- name: CountFollowingTweets :one
SELECT count(*)
FROM p_post
WHERE user_id=$1 AND is_del=0;
-- name: GetBeFriendIds :many
SELECT user_id FROM p_contact WHERE friend_id=$1 AND is_del=0;
-- name: GetBeFollowIds :many
SELECT follow_id FROM p_following WHERE user_id=$1 AND is_del=0;
--------------------------------------------------------------------------------
-- tweet_manage sql dml
--------------------------------------------------------------------------------
-- name: AddPost :exec
INSERT INTO p_post (user_id, tags, ip, ip_loc, attachment_price, visibility, latest_replied_on, created_on)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING id;
-- name: MediaContentByPostId :many
SELECT content FROM p_post_content WHERE post_id=$1 AND is_del=0 AND type IN (3, 4, 5, 7, 8);
-- name: DeletePostById :exec
UPDATE p_post SET is_del=1, deleted_on=$1 WHERE id=$2 AND is_del=0;
-- name: LockPost :one
UPDATE p_post
SET is_lock=1-is_lock, modified_on=$1
WHERE id=$2 AND is_del=0
RETURNING is_lock;
-- name: StickPost :one
UPDATE p_post
SET is_top=1-is_top, modified_on=$1
WHERE id=$2 AND is_del=0
RETURNING is_top;
-- name: VisiblePost :one
UPDATE p_post
SET visibility=$1, is_top=$2, modified_on=$3
WHERE id=$4 AND is_del=0
RETURNING visibility;
-- name: HighlightPost :one
UPDATE p_post
SET is_essence=1-is_essence
WHERE id=$1 AND is_del=0
RETURNING is_essence;
-- name: PostHighlightStatus :one
SELECT user_id, is_essence
FROM p_post
WHERE id=$1 AND is_del=0;
-- name: UpdatePost :exec
UPDATE p_post SET comment_count=$1,
upvote_count=$2,
collection_count=$3,
latest_replied_on=$4,
modified_on=$5
WHERE id=$6 AND is_del=0;
-- name: AddPostStar :one
INSERT INTO p_post_star (post_id, user_id, created_on)
VALUES ($1, $2, $3)
RETURNING id;
-- name: DeletePostStar :exec
UPDATE p_post_star
SET is_del=1, deleted_on=$1
WHERE id=$2 AND is_del=0;
-- name: AddPostCollection :one
INSERT INTO p_post_collection (post_id, user_id, created_on)
VALUES ($1, $2, $3)
RETURNING id;
-- name: DeletePostCollecton :exec
UPDATE p_post_collection SET is_del=1, deleted_on=$1 WHERE id=$2 AND is_del=0;
-- name: AddPostContent :one
INSERT INTO p_post_content (post_id, user_id, content, type, sort, created_on)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id;
-- name: AddAttachment :one
INSERT INTO p_attachment (user_id, file_size, img_width, img_height, type, content, created_on)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id;
-- name: CommentIdsByPostId :many
SELECT id FROM p_comment WHERE post_id=$1 AND is_del=0;
-- name: CommentMediaFromCommentIds :many
SELECT content FROM p_comment_content WHERE comment_id = ANY(@ids::BIGINT[]) AND type=3 AND is_del=0;
-- name: DeleteCommentByPostId :exec
UPDATE p_comment SET deleted_on=$1, is_del=1 WHERE post_id=$2 AND is_del=0;
-- name: DeleteCommentContentByCommentIds :exec
UPDATE p_comment_content SET deleted_on=$1, is_del=1 WHERE comment_id = ANY(@ids::BIGINT[]) AND is_del=0;
-- name: DeleteReplyByCommentIds :exec
UPDATE p_comment_reply SET deleted_on=$1, is_del=1 WHERE comment_id = ANY(@ids::BIGINT[]) AND is_del=0;
--------------------------------------------------------------------------------
-- tweet_help sql dml
--------------------------------------------------------------------------------
-- name: GetPostConetentByIds :many
SELECT id, post_id, content, type, sort
FROM p_post_content
WHERE post_id = ANY(@ids::BIGINT[]) AND is_del=0;

@ -3,5 +3,52 @@
-- user_manage sql dml -- user_manage sql dml
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- name: GetRegisterUserCount :one
SELECT count(*) FROM p_user WHERE is_del=0;
-- name: GetUserById :one -- name: GetUserById :one
SELECT * FROM p_user WHERE id=$1 AND is_del=0; SELECT * FROM p_user WHERE id=$1 AND is_del=0;
-- name: GetUserByUsername :one
SELECT * FROM p_user WHERE username=$1 AND is_del=0;
-- name: GetUserByPhone :one
SELECT * FROM p_user WHERE phone=$1 AND is_del=0;
-- name: GetUsersByIds :many
SELECT * FROM p_user WHERE id = ANY(@ids::BIGINT[]) AND is_del=0;
-- name: GetUsersByKeyword :many
SELECT * FROM p_user WHERE username LIKE $1 AND is_del=0 limit 6;
-- name: GetAnyusers :many
SELECT * FROM p_user WHERE is_del=0 ORDER BY id ASC limit 6;
-- name: CreateUser :one
INSERT INTO p_user (username, nickname, password, salt, avatar, status, created_on, balance)
VALUES ($1, $2, $3, $4, $5, $6, $7, 0)
RETURNING id;
-- name: UpdateUser :exec
UPDATE p_user
SET username=$1,
nickname=$2,
phone=$3,
password=$4,
salt=$5,
status=$6,
avatar=$7,
balance=$8,
is_admin=$9,
modified_on=$10
WHERE id=$11 AND is_del=0;
--------------------------------------------------------------------------------
-- user_relation sql dml
--------------------------------------------------------------------------------
-- name: MyFriendIds :many
SELECT friend_id FROM p_contact WHERE user_id=$1 AND is_del=0;
-- name: MyFollowIds :many
SELECT follow_id FROM p_following WHERE user_id=$1 AND is_del=0;

@ -2,9 +2,55 @@
-- wallet sql dml -- wallet sql dml
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- name: GetUserWalletBills :one -- name: GetUserWalletBills :many
SELECT * SELECT *
FROM p_wallet_statement FROM p_wallet_statement
WHERE user_id=$1 AND is_del=0 WHERE user_id=$1 AND is_del=0
ORDER BY id DESC ORDER BY id DESC
LIMIT $2 OFFSET $3; LIMIT $2 OFFSET $3;
-- name: CountUserWalletBill :one
SELECT count(*) FROM p_wallet_statement WHERE user_id=$1 AND is_del=0;
-- name: GetRechargeById :one
SELECT * FROM p_wallet_recharge WHERE id=$1 AND is_del=0;
-- name: CreateRecharge :one
INSERT INTO p_wallet_recharge (user_id, amount, created_on)
VALUES ($1, $2, $3)
RETURNING id;
-- name: AddUserBalance :one
UPDATE p_user
SET balance=balance+$1, modified_on=$2
WHERE id=$3 AND is_del=0
RETURNING balance;
-- name: MinusUserBalance :one
UPDATE p_user
SET balance=balance-$1, modified_on=$2
WHERE id=$3 AND is_del=0
RETURNING balance;
-- name: CreateWalletStatement :one
INSERT INTO p_wallet_statement (user_id, change_amount, balance_snapshot, reason, created_on)
VALUES ($1, $2, $3, $4, $5)
RETURNING id;
-- name: GetUserBalance :one
SELECT balance FROM p_user WHERE id=$1 AND is_del=0;
-- name: MarkSuccessRecharge :exec
UPDATE p_wallet_recharge
SET trade_no=$1, trade_status='TRADE_SUCCESS', modified_on=$2
WHERE id=$3 AND is_del=0;
-- name: CreatePostAttachmentBill :one
INSERT INTO p_post_attachment_bill (post_id, user_id, paid_amount, created_on)
VALUES ($1, $2, $3, $4)
RETURNING id;
-- name: CreatePostBill :one
INSERT INTO p_wallet_statement (post_id, user_id, change_amount, balance_snapshot, reason, created_on)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id;

@ -0,0 +1,19 @@
DROP TABLE IF EXISTS p_post_metric;
-- 原来的可见性: 0公开 1私密 2好友可见 3关注可见
-- 现在的可见性: 0私密 10充电可见 20订阅可见 30保留 40保留 50好友可见 60关注可见 70保留 80保留 90公开
UPDATE p_post a
SET visibility = (
SELECT
CASE visibility
WHEN 90 THEN 0
WHEN 0 THEN 1
WHEN 50 THEN 2
WHEN 60 THEN 3
ELSE 0
END
FROM
p_post b
WHERE
a.ID = b.ID
);

@ -0,0 +1,40 @@
CREATE TABLE p_post_metric (
ID BIGSERIAL PRIMARY KEY,
post_id BIGINT NOT NULL,
rank_score BIGINT NOT NULL DEFAULT 0,
incentive_score INT NOT NULL DEFAULT 0,
decay_factor INT NOT NULL DEFAULT 0,
motivation_factor INT NOT NULL DEFAULT 0,
is_del SMALLINT NOT NULL DEFAULT 0,
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0
);
CREATE INDEX idx_post_metric_post_id_rank_score ON p_post_metric USING btree ( post_id, rank_score );
INSERT INTO p_post_metric ( post_id, rank_score, created_on ) SELECT ID AS
post_id,
comment_count + upvote_count * 2 + collection_count * 4 AS rank_score,
created_on
FROM
p_post
WHERE
is_del = 0;
-- 原来的可见性: 0公开 1私密 2好友可见 3关注可见
-- 现在的可见性: 0私密 10充电可见 20订阅可见 30保留 40保留 50好友可见 60关注可见 70保留 80保留 90公开
UPDATE p_post a
SET visibility = (
SELECT
CASE visibility
WHEN 0 THEN 90
WHEN 1 THEN 0
WHEN 2 THEN 50
WHEN 3 THEN 60
ELSE 0
END
FROM
p_post b
WHERE
a.ID = b.ID
);

@ -0,0 +1 @@
ALTER TABLE p_comment DROP COLUMN is_essence;

@ -0,0 +1 @@
ALTER TABLE p_comment ADD COLUMN is_essence SMALLINT NOT NULL DEFAULT 0;

@ -0,0 +1,3 @@
ALTER TABLE p_comment DROP COLUMN IF EXISTS reply_count;
DROP TABLE IF EXISTS p_comment_metric;
DROP TABLE IF EXISTS p_user_metric;

@ -0,0 +1,51 @@
ALTER TABLE p_comment ADD COLUMN reply_count INT NOT NULL DEFAULT 0;
WITH comment_reply AS (
SELECT comment_id, count(*) AS count
FROM p_comment_reply
WHERE is_del=0
GROUP By comment_id
)
UPDATE p_comment comment
SET reply_count = reply.count
FROM comment_reply reply
WHERE comment.id = reply.comment_id;
CREATE TABLE p_comment_metric (
id BIGSERIAL PRIMARY KEY,
comment_id BIGINT NOT NULL,
rank_score BIGINT NOT NULL DEFAULT 0,
incentive_score INT NOT NULL DEFAULT 0,
decay_factor INT NOT NULL DEFAULT 0,
motivation_factor INT NOT NULL DEFAULT 0,
is_del SMALLINT NOT NULL DEFAULT 0,
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0
);
CREATE INDEX idx_comment_metric_comment_id_rank_score ON p_comment_metric USING btree (comment_id, rank_score);
INSERT INTO p_comment_metric (comment_id, rank_score, created_on)
SELECT id AS comment_id,
reply_count*2 + thumbs_up_count*4 - thumbs_down_count AS rank_score,
created_on
FROM p_comment
WHERE is_del=0;
CREATE TABLE p_user_metric (
id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL,
tweets_count INT NOT NULL DEFAULT 0,
latest_trends_on BIGINT NOT NULL DEFAULT 0,
is_del SMALLINT NOT NULL DEFAULT 0,
created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0
);
CREATE INDEX idx_user_metric_user_id_tweets_count_trends ON p_user_metric USING btree (user_id, tweets_count, latest_trends_on);
INSERT INTO p_user_metric (user_id, tweets_count)
SELECT user_id, count(*) AS tweets_count
FROM p_post
WHERE is_del=0
GROUP BY user_id;

@ -1,37 +0,0 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: security.sql
package dbr
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const getLatestPhoneCaptcha = `-- name: GetLatestPhoneCaptcha :one
SELECT id, phone, captcha, use_times, expired_on, created_on, modified_on, deleted_on, is_del FROM p_captcha WHERE phone=$1 AND is_del=0
`
// ------------------------------------------------------------------------------
// security sql dml
// ------------------------------------------------------------------------------
func (q *Queries) GetLatestPhoneCaptcha(ctx context.Context, phone pgtype.Text) (*PCaptcha, error) {
row := q.db.QueryRow(ctx, getLatestPhoneCaptcha, phone)
var i PCaptcha
err := row.Scan(
&i.ID,
&i.Phone,
&i.Captcha,
&i.UseTimes,
&i.ExpiredOn,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
)
return &i, err
}

@ -1,67 +0,0 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: timeline.sql
package dbr
import (
"context"
)
const indexByAdmin = `-- name: IndexByAdmin :many
SELECT id, user_id, comment_count, collection_count, upvote_count, is_top, is_essence, is_lock, latest_replied_on, tags, attachment_price, ip, ip_loc, created_on, modified_on, deleted_on, is_del, visibility, share_count
FROM p_post
WHERE is_del=0
ORDER BY is_top DESC, latest_replied_on DESC
LIMIT $1 OFFSET $2
`
type IndexByAdminParams struct {
Limit int32
Offset int32
}
// ------------------------------------------------------------------------------
// ship_index sql dml
// ------------------------------------------------------------------------------
func (q *Queries) IndexByAdmin(ctx context.Context, arg *IndexByAdminParams) ([]*PPost, error) {
rows, err := q.db.Query(ctx, indexByAdmin, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*PPost
for rows.Next() {
var i PPost
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.CommentCount,
&i.CollectionCount,
&i.UpvoteCount,
&i.IsTop,
&i.IsEssence,
&i.IsLock,
&i.LatestRepliedOn,
&i.Tags,
&i.AttachmentPrice,
&i.Ip,
&i.IpLoc,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
&i.Visibility,
&i.ShareCount,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}

@ -1,290 +0,0 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: topics.sql
package dbr
import (
"context"
)
const decrTagsById = `-- name: DecrTagsById :exec
UPDATE p_tag
SET quote_num = quote_num-1,
modified_on=$1
WHERE id IN (
SELECT id
FROM p_tag
WHERE id = ANY($2::BIGINT[]) AND is_del = false AND quote_num >= 1
)
`
type DecrTagsByIdParams struct {
ModifiedOn int64
Ids []int64
}
func (q *Queries) DecrTagsById(ctx context.Context, arg *DecrTagsByIdParams) error {
_, err := q.db.Exec(ctx, decrTagsById, arg.ModifiedOn, arg.Ids)
return err
}
const hotTags = `-- name: HotTags :many
SELECT t.id, t.tag, t.quote_num, u.id user_id, u.nickname, u.username, u.status, u.avatar, u.is_admin
FROM p_tag t JOIN p_user u ON t.user_id = u.id
WHERE t.is_del = false AND t.quote_num > 0
ORDER BY quote_num DESC
OFFSET $1 LIMIT $2
`
type HotTagsParams struct {
Offset int32
Limit int32
}
type HotTagsRow struct {
ID int64
Tag string
QuoteNum int64
UserID int64
Nickname string
Username string
Status int16
Avatar string
IsAdmin bool
}
func (q *Queries) HotTags(ctx context.Context, arg *HotTagsParams) ([]*HotTagsRow, error) {
rows, err := q.db.Query(ctx, hotTags, arg.Offset, arg.Limit)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*HotTagsRow
for rows.Next() {
var i HotTagsRow
if err := rows.Scan(
&i.ID,
&i.Tag,
&i.QuoteNum,
&i.UserID,
&i.Nickname,
&i.Username,
&i.Status,
&i.Avatar,
&i.IsAdmin,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const incrTags = `-- name: IncrTags :many
UPDATE p_tag
SET quote_num = quote_num+1,
modified_on = $1,
id_del = false
WHERE id IN (
SELECT id
FROM p_tag
WHERE tag = ANY($2::VARCHAR[])
)
RETURNING id, user_id, tag, quote_num
`
type IncrTagsParams struct {
ModifiedOn int64
Tags []string
}
type IncrTagsRow struct {
ID int64
UserID int64
Tag string
QuoteNum int64
}
func (q *Queries) IncrTags(ctx context.Context, arg *IncrTagsParams) ([]*IncrTagsRow, error) {
rows, err := q.db.Query(ctx, incrTags, arg.ModifiedOn, arg.Tags)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*IncrTagsRow
for rows.Next() {
var i IncrTagsRow
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.Tag,
&i.QuoteNum,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const insertTags = `-- name: InsertTags :one
INSERT INTO p_tag (user_id, tag, created_on, modified_on, quote_num)
VALUES ($1, $2, $3, $3, 1)
RETURNING id
`
type InsertTagsParams struct {
UserID int64
Tag string
CreatedOn int64
}
func (q *Queries) InsertTags(ctx context.Context, arg *InsertTagsParams) (int64, error) {
row := q.db.QueryRow(ctx, insertTags, arg.UserID, arg.Tag, arg.CreatedOn)
var id int64
err := row.Scan(&id)
return id, err
}
const newestTags = `-- name: NewestTags :many
SELECT t.id, t.tag, t.quote_num, u.id user_id, u.nickname, u.username, u.status, u.avatar, u.is_admin
FROM p_tag t JOIN p_user u ON t.user_id = u.id
WHERE t.is_del = false AND t.quote_num > 0
ORDER BY t.id DESC
OFFSET $1 LIMIT $2
`
type NewestTagsParams struct {
Offset int32
Limit int32
}
type NewestTagsRow struct {
ID int64
Tag string
QuoteNum int64
UserID int64
Nickname string
Username string
Status int16
Avatar string
IsAdmin bool
}
func (q *Queries) NewestTags(ctx context.Context, arg *NewestTagsParams) ([]*NewestTagsRow, error) {
rows, err := q.db.Query(ctx, newestTags, arg.Offset, arg.Limit)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*NewestTagsRow
for rows.Next() {
var i NewestTagsRow
if err := rows.Scan(
&i.ID,
&i.Tag,
&i.QuoteNum,
&i.UserID,
&i.Nickname,
&i.Username,
&i.Status,
&i.Avatar,
&i.IsAdmin,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const tagsByKeywordA = `-- name: TagsByKeywordA :many
SELECT id, user_id, tag, quote_num
FROM p_tag
WHERE is_del AND quote_num > 0
ORDER BY quote_num DESC
OFFSET 0 LIMIT 6
`
type TagsByKeywordARow struct {
ID int64
UserID int64
Tag string
QuoteNum int64
}
func (q *Queries) TagsByKeywordA(ctx context.Context) ([]*TagsByKeywordARow, error) {
rows, err := q.db.Query(ctx, tagsByKeywordA)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*TagsByKeywordARow
for rows.Next() {
var i TagsByKeywordARow
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.Tag,
&i.QuoteNum,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const tagsByKeywordB = `-- name: TagsByKeywordB :many
SELECT id, user_id, tag, quote_num
FROM p_tag
WHERE is_del = false AND tag LIKE $1
ORDER BY quote_num DESC
OFFSET 0 LIMIT 6
`
type TagsByKeywordBRow struct {
ID int64
UserID int64
Tag string
QuoteNum int64
}
func (q *Queries) TagsByKeywordB(ctx context.Context, tag string) ([]*TagsByKeywordBRow, error) {
rows, err := q.db.Query(ctx, tagsByKeywordB, tag)
if err != nil {
return nil, err
}
defer rows.Close()
var items []*TagsByKeywordBRow
for rows.Next() {
var i TagsByKeywordBRow
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.Tag,
&i.QuoteNum,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}

@ -1,45 +0,0 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: tweets.sql
package dbr
import (
"context"
)
const getPostById = `-- name: GetPostById :one
SELECT id, user_id, comment_count, collection_count, upvote_count, is_top, is_essence, is_lock, latest_replied_on, tags, attachment_price, ip, ip_loc, created_on, modified_on, deleted_on, is_del, visibility, share_count FROM p_post WHERE id=$1 AND is_del=0
`
// ------------------------------------------------------------------------------
// tweet sql dml
// ------------------------------------------------------------------------------
func (q *Queries) GetPostById(ctx context.Context, id int64) (*PPost, error) {
row := q.db.QueryRow(ctx, getPostById, id)
var i PPost
err := row.Scan(
&i.ID,
&i.UserID,
&i.CommentCount,
&i.CollectionCount,
&i.UpvoteCount,
&i.IsTop,
&i.IsEssence,
&i.IsLock,
&i.LatestRepliedOn,
&i.Tags,
&i.AttachmentPrice,
&i.Ip,
&i.IpLoc,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
&i.Visibility,
&i.ShareCount,
)
return &i, err
}

@ -1,40 +0,0 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: user.sql
package dbr
import (
"context"
)
const getUserById = `-- name: GetUserById :one
SELECT id, nickname, username, phone, password, salt, status, avatar, balance, is_admin, created_on, modified_on, deleted_on, is_del FROM p_user WHERE id=$1 AND is_del=0
`
// ------------------------------------------------------------------------------
// user_manage sql dml
// ------------------------------------------------------------------------------
func (q *Queries) GetUserById(ctx context.Context, id int64) (*PUser, error) {
row := q.db.QueryRow(ctx, getUserById, id)
var i PUser
err := row.Scan(
&i.ID,
&i.Nickname,
&i.Username,
&i.Phone,
&i.Password,
&i.Salt,
&i.Status,
&i.Avatar,
&i.Balance,
&i.IsAdmin,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
)
return &i, err
}

@ -1,46 +0,0 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: wallet.sql
package dbr
import (
"context"
)
const getUserWalletBills = `-- name: GetUserWalletBills :one
SELECT id, user_id, change_amount, balance_snapshot, reason, post_id, created_on, modified_on, deleted_on, is_del
FROM p_wallet_statement
WHERE user_id=$1 AND is_del=0
ORDER BY id DESC
LIMIT $2 OFFSET $3
`
type GetUserWalletBillsParams struct {
UserID int64
Limit int32
Offset int32
}
// ------------------------------------------------------------------------------
// wallet sql dml
// ------------------------------------------------------------------------------
func (q *Queries) GetUserWalletBills(ctx context.Context, arg *GetUserWalletBillsParams) (*PWalletStatement, error) {
row := q.db.QueryRow(ctx, getUserWalletBills, arg.UserID, arg.Limit, arg.Offset)
var i PWalletStatement
err := row.Scan(
&i.ID,
&i.UserID,
&i.ChangeAmount,
&i.BalanceSnapshot,
&i.Reason,
&i.PostID,
&i.CreatedOn,
&i.ModifiedOn,
&i.DeletedOn,
&i.IsDel,
)
return &i, err
}
Loading…
Cancel
Save