From ac78970ce15ceece2af6f3f90be12aaa370ddc85 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Thu, 31 Aug 2023 12:30:25 +0800 Subject: [PATCH] sqlc: add some stub sql query --- go.mod | 2 +- go.sum | 4 +- .../dao/slonik/sqlc/postgres/authrity.sql.go | 78 ++++++++++ .../dao/slonik/sqlc/postgres/comments.sql.go | 116 +++++++++++++++ .../dao/slonik/sqlc/postgres/contacts.sql.go | 35 +++++ .../dao/slonik/sqlc/postgres/following.sql.go | 29 ++++ .../dao/slonik/sqlc/postgres/messages.sql.go | 25 ++++ internal/dao/slonik/sqlc/postgres/models.go | 134 +++++++++++++----- internal/dao/slonik/sqlc/postgres/querier.go | 49 +++++++ .../slonik/sqlc/postgres/query/authrity.sql | 12 ++ .../slonik/sqlc/postgres/query/comments.sql | 16 +++ .../slonik/sqlc/postgres/query/contacts.sql | 6 + .../slonik/sqlc/postgres/query/following.sql | 6 + .../slonik/sqlc/postgres/query/messages.sql | 6 + .../slonik/sqlc/postgres/query/security.sql | 6 + .../slonik/sqlc/postgres/query/timeline.sql | 10 ++ .../postgres/query/{topic.sql => topics.sql} | 0 .../dao/slonik/sqlc/postgres/query/tweets.sql | 6 + .../dao/slonik/sqlc/postgres/query/user.sql | 7 + .../dao/slonik/sqlc/postgres/query/wallet.sql | 10 ++ ...wn.sql => 0000_setup_modified_on.down.sql} | 0 ...n.up.sql => 0000_setup_modified_on.up.sql} | 0 .../schema/0001_initialize_schema.down.sql | 1 - .../schema/0001_initialize_schema.up.sql | 4 - .../schema/0006_comment_thumbs.down.sql | 6 + .../schema/0006_comment_thumbs.up.sql | 20 +++ .../schema/0007_content_type_alter.down.sql | 1 + .../schema/0007_content_type_alter.up.sql | 3 + .../0008_create_view_post_filter.down.sql | 5 + .../0008_create_view_post_filter.up.sql | 32 +++++ .../schema/0009_user_following.down.sql | 1 + .../schema/0009_user_following.up.sql | 10 ++ .../dao/slonik/sqlc/postgres/security.sql.go | 37 +++++ .../dao/slonik/sqlc/postgres/timeline.sql.go | 67 +++++++++ .../postgres/{topic.sql.go => topics.sql.go} | 2 +- .../dao/slonik/sqlc/postgres/tweets.sql.go | 45 ++++++ internal/dao/slonik/sqlc/postgres/user.sql.go | 40 ++++++ .../dao/slonik/sqlc/postgres/wallet.sql.go | 46 ++++++ .../postgres/0007_content_type_alter.up.sql | 6 +- 39 files changed, 839 insertions(+), 44 deletions(-) create mode 100644 internal/dao/slonik/sqlc/postgres/authrity.sql.go create mode 100644 internal/dao/slonik/sqlc/postgres/comments.sql.go create mode 100644 internal/dao/slonik/sqlc/postgres/contacts.sql.go create mode 100644 internal/dao/slonik/sqlc/postgres/following.sql.go create mode 100644 internal/dao/slonik/sqlc/postgres/messages.sql.go create mode 100644 internal/dao/slonik/sqlc/postgres/query/authrity.sql create mode 100644 internal/dao/slonik/sqlc/postgres/query/comments.sql create mode 100644 internal/dao/slonik/sqlc/postgres/query/contacts.sql create mode 100644 internal/dao/slonik/sqlc/postgres/query/following.sql create mode 100644 internal/dao/slonik/sqlc/postgres/query/messages.sql create mode 100644 internal/dao/slonik/sqlc/postgres/query/security.sql create mode 100644 internal/dao/slonik/sqlc/postgres/query/timeline.sql rename internal/dao/slonik/sqlc/postgres/query/{topic.sql => topics.sql} (100%) create mode 100644 internal/dao/slonik/sqlc/postgres/query/tweets.sql create mode 100644 internal/dao/slonik/sqlc/postgres/query/user.sql create mode 100644 internal/dao/slonik/sqlc/postgres/query/wallet.sql rename internal/dao/slonik/sqlc/postgres/schema/{0006_setup_modified_on.down.sql => 0000_setup_modified_on.down.sql} (100%) rename internal/dao/slonik/sqlc/postgres/schema/{0006_setup_modified_on.up.sql => 0000_setup_modified_on.up.sql} (100%) create mode 100644 internal/dao/slonik/sqlc/postgres/schema/0006_comment_thumbs.down.sql create mode 100644 internal/dao/slonik/sqlc/postgres/schema/0006_comment_thumbs.up.sql create mode 100644 internal/dao/slonik/sqlc/postgres/schema/0007_content_type_alter.down.sql create mode 100644 internal/dao/slonik/sqlc/postgres/schema/0007_content_type_alter.up.sql create mode 100644 internal/dao/slonik/sqlc/postgres/schema/0008_create_view_post_filter.down.sql create mode 100644 internal/dao/slonik/sqlc/postgres/schema/0008_create_view_post_filter.up.sql create mode 100644 internal/dao/slonik/sqlc/postgres/schema/0009_user_following.down.sql create mode 100644 internal/dao/slonik/sqlc/postgres/schema/0009_user_following.up.sql create mode 100644 internal/dao/slonik/sqlc/postgres/security.sql.go create mode 100644 internal/dao/slonik/sqlc/postgres/timeline.sql.go rename internal/dao/slonik/sqlc/postgres/{topic.sql.go => topics.sql.go} (99%) create mode 100644 internal/dao/slonik/sqlc/postgres/tweets.sql.go create mode 100644 internal/dao/slonik/sqlc/postgres/user.sql.go create mode 100644 internal/dao/slonik/sqlc/postgres/wallet.sql.go diff --git a/go.mod b/go.mod index 5be25f88..85e9df1d 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/golang-jwt/jwt/v5 v5.0.0 github.com/golang-migrate/migrate/v4 v4.15.2 github.com/huaweicloud/huaweicloud-sdk-go-obs v3.23.4+incompatible - github.com/jackc/pgx/v5 v5.4.2 + github.com/jackc/pgx/v5 v5.4.3 github.com/json-iterator/go v1.1.12 github.com/meilisearch/meilisearch-go v0.25.0 github.com/minio/minio-go/v7 v7.0.62 diff --git a/go.sum b/go.sum index b4ddf67e..44febf4e 100644 --- a/go.sum +++ b/go.sum @@ -806,8 +806,8 @@ github.com/jackc/pgx/v4 v4.5.0/go.mod h1:EpAKPLdnTorwmPUUsqrPxy5fphV18j9q3wrfRXg github.com/jackc/pgx/v4 v4.6.1-0.20200510190926-94ba730bb1e9/go.mod h1:t3/cdRQl6fOLDxqtlyhe9UWgfIi9R8+8v8GKV5TRA/o= github.com/jackc/pgx/v4 v4.6.1-0.20200606145419-4e5062306904/go.mod h1:ZDaNWkt9sW1JMiNn0kdYBaLelIhw7Pg4qd+Vk6tw7Hg= github.com/jackc/pgx/v4 v4.10.1/go.mod h1:QlrWebbs3kqEZPHCTGyxecvzG6tvIsYu+A5b1raylkA= -github.com/jackc/pgx/v5 v5.4.2 h1:u1gmGDwbdRUZiwisBm/Ky2M14uQyUP65bG8+20nnyrg= -github.com/jackc/pgx/v5 v5.4.2/go.mod h1:q6iHT8uDNXWiFNOlRqJzBTaSH3+2xCXkokxHZC5qWFY= +github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY= +github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA= github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= diff --git a/internal/dao/slonik/sqlc/postgres/authrity.sql.go b/internal/dao/slonik/sqlc/postgres/authrity.sql.go new file mode 100644 index 00000000..eed9c4dc --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/authrity.sql.go @@ -0,0 +1,78 @@ +// 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 +} diff --git a/internal/dao/slonik/sqlc/postgres/comments.sql.go b/internal/dao/slonik/sqlc/postgres/comments.sql.go new file mode 100644 index 00000000..f78550a4 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/comments.sql.go @@ -0,0 +1,116 @@ +// 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 +} diff --git a/internal/dao/slonik/sqlc/postgres/contacts.sql.go b/internal/dao/slonik/sqlc/postgres/contacts.sql.go new file mode 100644 index 00000000..b2168790 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/contacts.sql.go @@ -0,0 +1,35 @@ +// 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 +} diff --git a/internal/dao/slonik/sqlc/postgres/following.sql.go b/internal/dao/slonik/sqlc/postgres/following.sql.go new file mode 100644 index 00000000..db15762f --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/following.sql.go @@ -0,0 +1,29 @@ +// 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 +} diff --git a/internal/dao/slonik/sqlc/postgres/messages.sql.go b/internal/dao/slonik/sqlc/postgres/messages.sql.go new file mode 100644 index 00000000..872ae56a --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/messages.sql.go @@ -0,0 +1,25 @@ +// 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 +} diff --git a/internal/dao/slonik/sqlc/postgres/models.go b/internal/dao/slonik/sqlc/postgres/models.go index f1486189..2a20a41f 100644 --- a/internal/dao/slonik/sqlc/postgres/models.go +++ b/internal/dao/slonik/sqlc/postgres/models.go @@ -35,15 +35,17 @@ type PCaptcha struct { } type PComment struct { - ID int64 - PostID int64 - UserID int64 - Ip string - IpLoc string - CreatedOn int64 - ModifiedOn int64 - DeletedOn int64 - IsDel int16 + 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 { @@ -60,17 +62,19 @@ type PCommentContent struct { } 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 + 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 { @@ -99,6 +103,16 @@ type PContactGroup struct { 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 @@ -149,6 +163,51 @@ type PPostAttachmentBill struct { 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 @@ -209,19 +268,30 @@ type PTopicUser struct { 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 - // MD5密码 - Password string - Salt string - // 状态, 1正常, 2停用 - Status int16 - Avatar string - // 用户余额(分) + ID int64 + Nickname string + Username string + Phone string + Password string + Salt string + Status int16 + Avatar string Balance int64 IsAdmin bool CreatedOn int64 diff --git a/internal/dao/slonik/sqlc/postgres/querier.go b/internal/dao/slonik/sqlc/postgres/querier.go index 6f2e94a1..b2190489 100644 --- a/internal/dao/slonik/sqlc/postgres/querier.go +++ b/internal/dao/slonik/sqlc/postgres/querier.go @@ -6,13 +6,62 @@ 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) diff --git a/internal/dao/slonik/sqlc/postgres/query/authrity.sql b/internal/dao/slonik/sqlc/postgres/query/authrity.sql new file mode 100644 index 00000000..d3f5b945 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/query/authrity.sql @@ -0,0 +1,12 @@ +-------------------------------------------------------------------------------- +-- authorization_manage sql dml +-------------------------------------------------------------------------------- + +-- name: BeFriendIds :many +SELECT user_id FROM p_contact WHERE friend_id=$1 AND status=2 AND is_del=0; + +-- name: MyFriendSet :many +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; diff --git a/internal/dao/slonik/sqlc/postgres/query/comments.sql b/internal/dao/slonik/sqlc/postgres/query/comments.sql new file mode 100644 index 00000000..6aaa3a50 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/query/comments.sql @@ -0,0 +1,16 @@ +-------------------------------------------------------------------------------- +-- comment sql dml +-------------------------------------------------------------------------------- + +-- name: GetNewestComments :many +SELECT * FROM p_comment WHERE post_id=$1 AND is_del=0 ORDER BY id DESC LIMIT $2 OFFSET $3; + +-- name: GetDefaultComments :many +SELECT * FROM p_comment WHERE post_id=$1 AND is_del=0 ORDER BY id ASC LIMIT $2 OFFSET $3; + +-------------------------------------------------------------------------------- +-- comment_manage sql dml +-------------------------------------------------------------------------------- + +-- name: DeleteComment :exec +UPDATE p_comment SET deleted_on=$1, is_del=1 WHERE id=$2 AND is_del=0; diff --git a/internal/dao/slonik/sqlc/postgres/query/contacts.sql b/internal/dao/slonik/sqlc/postgres/query/contacts.sql new file mode 100644 index 00000000..b894882e --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/query/contacts.sql @@ -0,0 +1,6 @@ +-------------------------------------------------------------------------------- +-- contact_manager sql dml +-------------------------------------------------------------------------------- + +-- name: CreateContact :exec +INSERT INTO p_contact (user_id, friend_id, status, created_on) VALUES ($1, $2, $3, $4); diff --git a/internal/dao/slonik/sqlc/postgres/query/following.sql b/internal/dao/slonik/sqlc/postgres/query/following.sql new file mode 100644 index 00000000..9df11e50 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/query/following.sql @@ -0,0 +1,6 @@ +-------------------------------------------------------------------------------- +-- following_manager sql dml +-------------------------------------------------------------------------------- + +-- name: CreateFollowing :exec +INSERT INTO p_following (user_id, follow_id, created_on) VALUES ($1, $2, $3); diff --git a/internal/dao/slonik/sqlc/postgres/query/messages.sql b/internal/dao/slonik/sqlc/postgres/query/messages.sql new file mode 100644 index 00000000..113fba75 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/query/messages.sql @@ -0,0 +1,6 @@ +-------------------------------------------------------------------------------- +-- message sql dml +-------------------------------------------------------------------------------- + +-- name: GetUnreadCount :one +SELECT count(*) FROM p_message WHERE receiver_user_id=$1 AND is_read=0 AND is_del=0; diff --git a/internal/dao/slonik/sqlc/postgres/query/security.sql b/internal/dao/slonik/sqlc/postgres/query/security.sql new file mode 100644 index 00000000..0849a729 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/query/security.sql @@ -0,0 +1,6 @@ +-------------------------------------------------------------------------------- +-- security sql dml +-------------------------------------------------------------------------------- + +-- name: GetLatestPhoneCaptcha :one +SELECT * FROM p_captcha WHERE phone=$1 AND is_del=0; diff --git a/internal/dao/slonik/sqlc/postgres/query/timeline.sql b/internal/dao/slonik/sqlc/postgres/query/timeline.sql new file mode 100644 index 00000000..c2c4e0b4 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/query/timeline.sql @@ -0,0 +1,10 @@ +-------------------------------------------------------------------------------- +-- ship_index sql dml +-------------------------------------------------------------------------------- + +-- name: IndexByAdmin :many +SELECT * +FROM p_post +WHERE is_del=0 +ORDER BY is_top DESC, latest_replied_on DESC +LIMIT $1 OFFSET $2; diff --git a/internal/dao/slonik/sqlc/postgres/query/topic.sql b/internal/dao/slonik/sqlc/postgres/query/topics.sql similarity index 100% rename from internal/dao/slonik/sqlc/postgres/query/topic.sql rename to internal/dao/slonik/sqlc/postgres/query/topics.sql diff --git a/internal/dao/slonik/sqlc/postgres/query/tweets.sql b/internal/dao/slonik/sqlc/postgres/query/tweets.sql new file mode 100644 index 00000000..2c2a9e36 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/query/tweets.sql @@ -0,0 +1,6 @@ +-------------------------------------------------------------------------------- +-- tweet sql dml +-------------------------------------------------------------------------------- + +-- name: GetPostById :one +SELECT * FROM p_post WHERE id=$1 AND is_del=0; diff --git a/internal/dao/slonik/sqlc/postgres/query/user.sql b/internal/dao/slonik/sqlc/postgres/query/user.sql new file mode 100644 index 00000000..5356614a --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/query/user.sql @@ -0,0 +1,7 @@ + +-------------------------------------------------------------------------------- +-- user_manage sql dml +-------------------------------------------------------------------------------- + +-- name: GetUserById :one +SELECT * FROM p_user WHERE id=$1 AND is_del=0; diff --git a/internal/dao/slonik/sqlc/postgres/query/wallet.sql b/internal/dao/slonik/sqlc/postgres/query/wallet.sql new file mode 100644 index 00000000..96b53b16 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/query/wallet.sql @@ -0,0 +1,10 @@ +-------------------------------------------------------------------------------- +-- wallet sql dml +-------------------------------------------------------------------------------- + +-- name: GetUserWalletBills :one +SELECT * +FROM p_wallet_statement +WHERE user_id=$1 AND is_del=0 +ORDER BY id DESC +LIMIT $2 OFFSET $3; diff --git a/internal/dao/slonik/sqlc/postgres/schema/0006_setup_modified_on.down.sql b/internal/dao/slonik/sqlc/postgres/schema/0000_setup_modified_on.down.sql similarity index 100% rename from internal/dao/slonik/sqlc/postgres/schema/0006_setup_modified_on.down.sql rename to internal/dao/slonik/sqlc/postgres/schema/0000_setup_modified_on.down.sql diff --git a/internal/dao/slonik/sqlc/postgres/schema/0006_setup_modified_on.up.sql b/internal/dao/slonik/sqlc/postgres/schema/0000_setup_modified_on.up.sql similarity index 100% rename from internal/dao/slonik/sqlc/postgres/schema/0006_setup_modified_on.up.sql rename to internal/dao/slonik/sqlc/postgres/schema/0000_setup_modified_on.up.sql diff --git a/internal/dao/slonik/sqlc/postgres/schema/0001_initialize_schema.down.sql b/internal/dao/slonik/sqlc/postgres/schema/0001_initialize_schema.down.sql index d1fdd15f..52326aff 100644 --- a/internal/dao/slonik/sqlc/postgres/schema/0001_initialize_schema.down.sql +++ b/internal/dao/slonik/sqlc/postgres/schema/0001_initialize_schema.down.sql @@ -14,4 +14,3 @@ DROP TABLE IF EXISTS p_user; DROP TABLE IF EXISTS p_wallet_recharge; DROP TABLE IF EXISTS p_wallet_statement; DROP SEQUENCE IF EXISTS post_id_seq; - diff --git a/internal/dao/slonik/sqlc/postgres/schema/0001_initialize_schema.up.sql b/internal/dao/slonik/sqlc/postgres/schema/0001_initialize_schema.up.sql index 43a68d2f..cfaccf28 100644 --- a/internal/dao/slonik/sqlc/postgres/schema/0001_initialize_schema.up.sql +++ b/internal/dao/slonik/sqlc/postgres/schema/0001_initialize_schema.up.sql @@ -199,10 +199,6 @@ CREATE TABLE p_user ( deleted_on BIGINT NOT NULL DEFAULT 0, is_del SMALLINT NOT NULL DEFAULT 0 ); -COMMENT ON TABLE p_user IS '用户'; -COMMENT ON COLUMN p_user.password IS 'MD5密码'; -COMMENT ON COLUMN p_user.status IS '状态, 1正常, 2停用'; -COMMENT ON COLUMN p_user.balance IS '用户余额(分)'; CREATE UNIQUE INDEX idx_user_username ON p_user USING btree (username); CREATE INDEX idx_user_phone ON p_user USING btree (phone); diff --git a/internal/dao/slonik/sqlc/postgres/schema/0006_comment_thumbs.down.sql b/internal/dao/slonik/sqlc/postgres/schema/0006_comment_thumbs.down.sql new file mode 100644 index 00000000..79f878e2 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/schema/0006_comment_thumbs.down.sql @@ -0,0 +1,6 @@ +ALTER TABLE p_comment DROP COLUMN thumbs_up_count; +ALTER TABLE p_comment DROP COLUMN thumbs_down_count; +ALTER TABLE p_comment_reply DROP COLUMN thumbs_up_count; +ALTER TABLE p_comment_reply DROP COLUMN thumbs_down_count; + +DROP TABLE IF EXISTS p_tweet_comment_thumbs; diff --git a/internal/dao/slonik/sqlc/postgres/schema/0006_comment_thumbs.up.sql b/internal/dao/slonik/sqlc/postgres/schema/0006_comment_thumbs.up.sql new file mode 100644 index 00000000..02250b7d --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/schema/0006_comment_thumbs.up.sql @@ -0,0 +1,20 @@ +ALTER TABLE p_comment ADD COLUMN thumbs_up_count INT NOT NULL DEFAULT 0; +ALTER TABLE p_comment ADD COLUMN thumbs_down_count INT NOT NULL DEFAULT 0; +ALTER TABLE p_comment_reply ADD COLUMN thumbs_up_count INT NOT NULL DEFAULT 0; +ALTER TABLE p_comment_reply ADD COLUMN thumbs_down_count INT NOT NULL DEFAULT 0; + +CREATE TABLE p_tweet_comment_thumbs ( + ID BIGSERIAL PRIMARY KEY, + user_id BIGINT NOT NULL, + tweet_id BIGINT NOT NULL, + comment_id BIGINT NOT NULL, + reply_id BIGINT, + comment_type SMALLINT NOT NULL DEFAULT 0,-- 评论类型 0为推文评论、1为评论回复 + is_thumbs_up SMALLINT NOT NULL DEFAULT 0,-- 是否点赞 0 为否 1为是 + is_thumbs_down SMALLINT NOT NULL DEFAULT 0,-- 是否点踩 0 为否 1为是 + created_on BIGINT NOT NULL DEFAULT 0, + modified_on BIGINT NOT NULL DEFAULT 0, + deleted_on BIGINT NOT NULL DEFAULT 0, + is_del SMALLINT NOT NULL DEFAULT 0 -- 是否删除 0 为未删除、1 为已删除 +); +CREATE INDEX idx_tweet_comment_thumbs_uid_tid ON p_tweet_comment_thumbs USING btree ( user_id, tweet_id ); \ No newline at end of file diff --git a/internal/dao/slonik/sqlc/postgres/schema/0007_content_type_alter.down.sql b/internal/dao/slonik/sqlc/postgres/schema/0007_content_type_alter.down.sql new file mode 100644 index 00000000..e95cb5d1 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/schema/0007_content_type_alter.down.sql @@ -0,0 +1 @@ +-- nothing diff --git a/internal/dao/slonik/sqlc/postgres/schema/0007_content_type_alter.up.sql b/internal/dao/slonik/sqlc/postgres/schema/0007_content_type_alter.up.sql new file mode 100644 index 00000000..bc031891 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/schema/0007_content_type_alter.up.sql @@ -0,0 +1,3 @@ +ALTER TABLE p_post_content ALTER COLUMN content SET DATA TYPE TEXT, ALTER COLUMN content SET NOT NULL, ALTER COLUMN content SET DEFAULT ''; +ALTER TABLE p_comment_content ALTER COLUMN content SET DATA TYPE TEXT, ALTER COLUMN content SET NOT NULL, ALTER COLUMN content SET DEFAULT ''; +ALTER TABLE p_comment_reply ALTER COLUMN content SET DATA TYPE TEXT, ALTER COLUMN content SET NOT NULL, ALTER COLUMN content SET DEFAULT ''; \ No newline at end of file diff --git a/internal/dao/slonik/sqlc/postgres/schema/0008_create_view_post_filter.down.sql b/internal/dao/slonik/sqlc/postgres/schema/0008_create_view_post_filter.down.sql new file mode 100644 index 00000000..b1550d2e --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/schema/0008_create_view_post_filter.down.sql @@ -0,0 +1,5 @@ +DROP VIEW IF EXISTS p_post_by_media; +DROP VIEW IF EXISTS p_post_by_comment; + + + diff --git a/internal/dao/slonik/sqlc/postgres/schema/0008_create_view_post_filter.up.sql b/internal/dao/slonik/sqlc/postgres/schema/0008_create_view_post_filter.up.sql new file mode 100644 index 00000000..b0e62a31 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/schema/0008_create_view_post_filter.up.sql @@ -0,0 +1,32 @@ +CREATE VIEW p_post_by_media AS +SELECT post.* +FROM + ( SELECT DISTINCT post_id FROM p_post_content WHERE ( TYPE = 3 OR TYPE = 4 OR TYPE = 7 OR TYPE = 8 ) AND is_del = 0 ) media + JOIN p_post post ON media.post_id = post.ID +WHERE + post.is_del = 0; + +CREATE VIEW p_post_by_comment AS +SELECT P.*, C.user_id comment_user_id +FROM + ( + SELECT + post_id, + user_id + FROM + p_comment + WHERE + is_del = 0 UNION + SELECT + post_id, + reply.user_id user_id + FROM + p_comment_reply reply + JOIN p_comment COMMENT ON reply.comment_id = COMMENT.ID + WHERE + reply.is_del = 0 + AND COMMENT.is_del = 0 + ) + C JOIN p_post P ON C.post_id = P.ID +WHERE + P.is_del = 0; \ No newline at end of file diff --git a/internal/dao/slonik/sqlc/postgres/schema/0009_user_following.down.sql b/internal/dao/slonik/sqlc/postgres/schema/0009_user_following.down.sql new file mode 100644 index 00000000..d16a02f8 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/schema/0009_user_following.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS p_following; diff --git a/internal/dao/slonik/sqlc/postgres/schema/0009_user_following.up.sql b/internal/dao/slonik/sqlc/postgres/schema/0009_user_following.up.sql new file mode 100644 index 00000000..8ce887b0 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/schema/0009_user_following.up.sql @@ -0,0 +1,10 @@ +CREATE TABLE p_following ( + id BIGSERIAL PRIMARY KEY, + user_id BIGINT NOT NULL, + follow_id BIGINT NOT NULL, + is_del SMALLINT NOT NULL DEFAULT 0, -- 是否删除, 0否, 1是 + created_on BIGINT NOT NULL DEFAULT 0, + modified_on BIGINT NOT NULL DEFAULT 0, + deleted_on BIGINT NOT NULL DEFAULT 0 +); +CREATE INDEX idx_following_user_follow ON p_following USING btree (user_id, follow_id); diff --git a/internal/dao/slonik/sqlc/postgres/security.sql.go b/internal/dao/slonik/sqlc/postgres/security.sql.go new file mode 100644 index 00000000..76602f2f --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/security.sql.go @@ -0,0 +1,37 @@ +// 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 +} diff --git a/internal/dao/slonik/sqlc/postgres/timeline.sql.go b/internal/dao/slonik/sqlc/postgres/timeline.sql.go new file mode 100644 index 00000000..0c56cb51 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/timeline.sql.go @@ -0,0 +1,67 @@ +// 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 +} diff --git a/internal/dao/slonik/sqlc/postgres/topic.sql.go b/internal/dao/slonik/sqlc/postgres/topics.sql.go similarity index 99% rename from internal/dao/slonik/sqlc/postgres/topic.sql.go rename to internal/dao/slonik/sqlc/postgres/topics.sql.go index a26c70dc..de2e89c1 100644 --- a/internal/dao/slonik/sqlc/postgres/topic.sql.go +++ b/internal/dao/slonik/sqlc/postgres/topics.sql.go @@ -1,7 +1,7 @@ // Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.20.0 -// source: topic.sql +// source: topics.sql package dbr diff --git a/internal/dao/slonik/sqlc/postgres/tweets.sql.go b/internal/dao/slonik/sqlc/postgres/tweets.sql.go new file mode 100644 index 00000000..23362c39 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/tweets.sql.go @@ -0,0 +1,45 @@ +// 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 +} diff --git a/internal/dao/slonik/sqlc/postgres/user.sql.go b/internal/dao/slonik/sqlc/postgres/user.sql.go new file mode 100644 index 00000000..3ddc3acf --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/user.sql.go @@ -0,0 +1,40 @@ +// 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 +} diff --git a/internal/dao/slonik/sqlc/postgres/wallet.sql.go b/internal/dao/slonik/sqlc/postgres/wallet.sql.go new file mode 100644 index 00000000..6c7c8561 --- /dev/null +++ b/internal/dao/slonik/sqlc/postgres/wallet.sql.go @@ -0,0 +1,46 @@ +// 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 +} diff --git a/scripts/migration/postgres/0007_content_type_alter.up.sql b/scripts/migration/postgres/0007_content_type_alter.up.sql index 4df0470d..2315fa6c 100644 --- a/scripts/migration/postgres/0007_content_type_alter.up.sql +++ b/scripts/migration/postgres/0007_content_type_alter.up.sql @@ -1,3 +1,3 @@ -ALTER TABLE p_post_content ALTER COLUMN content SET DATA TYPE TEXT NOT NULL DEFAULT ''; -ALTER TABLE p_comment_content ALTER COLUMN content SET DATA TYPE TEXT NOT NULL DEFAULT ''; -ALTER TABLE p_comment_reply ALTER COLUMN content SET DATA TYPE TEXT NOT NULL DEFAULT ''; +ALTER TABLE p_post_content ALTER COLUMN content SET DATA TYPE TEXT, ALTER COLUMN content SET NOT NULL, ALTER COLUMN content SET DEFAULT ''; +ALTER TABLE p_comment_content ALTER COLUMN content SET DATA TYPE TEXT, ALTER COLUMN content SET NOT NULL, ALTER COLUMN content SET DEFAULT ''; +ALTER TABLE p_comment_reply ALTER COLUMN content SET DATA TYPE TEXT, ALTER COLUMN content SET NOT NULL, ALTER COLUMN content SET DEFAULT '';