sqlc: add some base initial logic

r/paopao-ce-pro
Michael Li 1 year ago
parent 0b0270a74b
commit 8688023508
No known key found for this signature in database

@ -89,9 +89,9 @@ gen-rpc:
.PHONY: gen-sqlc
gen-sqlc:
@find internal/dao/slonik/sqlc/postgres -name '*.go' -exec rm -f {} +
@find internal/dao/slonik/sqlc/auto -name '*.go' -exec rm -f {} +
@go generate internal/dao/slonik/sqlc/gen.go
@go fmt ./internal/dao/slonik/sqlc/...
@go fmt ./internal/dao/slonik/sqlc/auto/...
.PHONY: proto-mod
proto-mod:

@ -10,7 +10,7 @@ import (
"github.com/jackc/pgx/v5"
"github.com/rocboss/paopao-ce/internal/conf"
dbr "github.com/rocboss/paopao-ce/internal/dao/slonik/sqlc/postgres"
pg "github.com/rocboss/paopao-ce/internal/dao/slonik/sqlc/auto"
)
var (
@ -20,70 +20,54 @@ var (
type pgxSrv struct {
db *pgx.Conn
q dbr.Querier
p pg.Querier
}
func (s *pgxSrv) begin(ctx context.Context) (pgx.Tx, dbr.Querier, error) {
tx, err := s.db.Begin(ctx)
if err != nil {
return nil, nil, err
}
return tx, dbr.New(tx), nil
}
func (s *pgxSrv) beingTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, dbr.Querier, error) {
tx, err := s.db.BeginTx(ctx, txOptions)
if err != nil {
return nil, nil, err
}
return tx, dbr.New(tx), nil
}
func (s *pgxSrv) with(handle func(c context.Context, q dbr.Querier) error) error {
func (s *pgxSrv) with(fn func(c context.Context, tx pgx.Tx) error) error {
ctx := context.Background()
tx, err := s.db.Begin(ctx)
if err != nil {
return err
}
defer tx.Rollback(ctx)
if err = handle(ctx, dbr.New(tx)); err != nil {
if err = fn(ctx, tx); err != nil {
return err
}
return tx.Commit(ctx)
}
func (s *pgxSrv) withTx(txOptions pgx.TxOptions, handle func(ctx context.Context, q dbr.Querier) error) error {
func (s *pgxSrv) withTx(txOptions pgx.TxOptions, fn func(ctx context.Context, tx pgx.Tx) error) error {
ctx := context.Background()
tx, err := s.db.BeginTx(ctx, txOptions)
if err != nil {
return err
}
defer tx.Rollback(ctx)
if err = handle(ctx, dbr.New(tx)); err != nil {
if err = fn(ctx, tx); err != nil {
return err
}
return tx.Commit(ctx)
}
func (s *pgxSrv) withCtx(ctx context.Context, handle func(dbr.Querier) error) error {
func (s *pgxSrv) withCtx(ctx context.Context, fn func(tx pgx.Tx) error) error {
tx, err := s.db.Begin(ctx)
if err != nil {
return err
}
defer tx.Rollback(ctx)
if err = handle(dbr.New(tx)); err != nil {
if err = fn(tx); err != nil {
return err
}
return tx.Commit(ctx)
}
func (s *pgxSrv) withTxCtx(ctx context.Context, txOptions pgx.TxOptions, handle func(dbr.Querier) error) error {
func (s *pgxSrv) withTxCtx(ctx context.Context, txOptions pgx.TxOptions, fn func(tx pgx.Tx) error) error {
tx, err := s.db.BeginTx(ctx, txOptions)
if err != nil {
return err
}
defer tx.Rollback(ctx)
if err = handle(dbr.New(tx)); err != nil {
if err = fn(tx); err != nil {
return err
}
return tx.Commit(ctx)
@ -92,7 +76,7 @@ func (s *pgxSrv) withTxCtx(ctx context.Context, txOptions pgx.TxOptions, handle
func newPgxSrv(db *pgx.Conn) *pgxSrv {
return &pgxSrv{
db: db,
q: dbr.New(db),
p: pg.New(db),
}
}

@ -0,0 +1,67 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: core.sql
package pg
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
}
// ------------------------------------------------------------------------------
// core global 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
}

@ -0,0 +1,32 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
package pg
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,
}
}

@ -0,0 +1,326 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
package pg
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
}

@ -0,0 +1,78 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: authrity.sql
package pga
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
}

@ -0,0 +1,116 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: comments.sql
package pga
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
}

@ -0,0 +1,35 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: contacts.sql
package pga
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
}

@ -0,0 +1,32 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
package pga
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,
}
}

@ -0,0 +1,29 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: following.sql
package pga
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
}

@ -0,0 +1,25 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: messages.sql
package pga
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
}

@ -0,0 +1,326 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
package pga
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
}

@ -0,0 +1,70 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
package pga
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)

@ -0,0 +1,37 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: security.sql
package pga
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
}

@ -0,0 +1,67 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: timeline.sql
package pga
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
}

@ -0,0 +1,290 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: topics.sql
package pga
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
}

@ -0,0 +1,45 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: tweets.sql
package pga
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
}

@ -0,0 +1,40 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: user.sql
package pga
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
}

@ -0,0 +1,46 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: wallet.sql
package pga
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
}

@ -0,0 +1,78 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: authrity.sql
package pgc
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
}

@ -0,0 +1,116 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: comments.sql
package pgc
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
}

@ -0,0 +1,35 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: contacts.sql
package pgc
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
}

@ -0,0 +1,32 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
package pgc
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,
}
}

@ -0,0 +1,29 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: following.sql
package pgc
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
}

@ -0,0 +1,25 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: messages.sql
package pgc
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
}

@ -0,0 +1,326 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
package pgc
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
}

@ -0,0 +1,70 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
package pgc
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)

@ -0,0 +1,37 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: security.sql
package pgc
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
}

@ -0,0 +1,67 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: timeline.sql
package pgc
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
}

@ -0,0 +1,290 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: topics.sql
package pgc
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
}

@ -0,0 +1,45 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: tweets.sql
package pgc
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
}

@ -0,0 +1,40 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: user.sql
package pgc
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
}

@ -0,0 +1,46 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: wallet.sql
package pgc
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
}

@ -0,0 +1,18 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
package pg
import (
"context"
)
type Querier interface {
//------------------------------------------------------------------------------
// core global sql dml
//------------------------------------------------------------------------------
IndexByAdmin(ctx context.Context, arg *IndexByAdminParams) ([]*PPost, error)
}
var _ Querier = (*Queries)(nil)

@ -0,0 +1,10 @@
--------------------------------------------------------------------------------
-- core global 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;

@ -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;

@ -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;

@ -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);

@ -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);

@ -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;

@ -0,0 +1,6 @@
--------------------------------------------------------------------------------
-- security sql dml
--------------------------------------------------------------------------------
-- name: GetLatestPhoneCaptcha :one
SELECT * FROM p_captcha WHERE phone=$1 AND is_del=0;

@ -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;

@ -0,0 +1,54 @@
-- 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;
-- 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;
-- 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;
-- 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;
-- name: InsertTags :one
INSERT INTO p_tag (user_id, tag, created_on, modified_on, quote_num)
VALUES ($1, $2, $3, $3, 1)
RETURNING id;
-- 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(@ids::BIGINT[]) AND is_del = false AND quote_num >= 1
);
-- 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(@tags::VARCHAR[])
)
RETURNING id, user_id, tag, quote_num;

@ -0,0 +1,6 @@
--------------------------------------------------------------------------------
-- tweet sql dml
--------------------------------------------------------------------------------
-- name: GetPostById :one
SELECT * FROM p_post WHERE id=$1 AND is_del=0;

@ -0,0 +1,7 @@
--------------------------------------------------------------------------------
-- user_manage sql dml
--------------------------------------------------------------------------------
-- name: GetUserById :one
SELECT * FROM p_user WHERE id=$1 AND is_del=0;

@ -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;

@ -1,12 +1,36 @@
version: '2'
sql:
- schema: postgres/schema
queries: postgres/query
queries: postgres/query_pg
engine: postgresql
gen:
go:
package: dbr
out: postgres
package: pg
out: auto
sql_package: 'pgx/v5'
emit_prepared_queries: true
emit_interface: true
emit_result_struct_pointers: true
emit_params_struct_pointers: true
- schema: postgres/schema
queries: postgres/query_pga
engine: postgresql
gen:
go:
package: pga
out: auto/pga
sql_package: 'pgx/v5'
emit_prepared_queries: true
emit_interface: true
emit_result_struct_pointers: true
emit_params_struct_pointers: true
- schema: postgres/schema
queries: postgres/query_pgc
engine: postgresql
gen:
go:
package: pgc
out: auto/pgc
sql_package: 'pgx/v5'
emit_prepared_queries: true
emit_interface: true

@ -12,7 +12,7 @@ import (
"github.com/jackc/pgx/v5"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
dbr "github.com/rocboss/paopao-ce/internal/dao/slonik/sqlc/postgres"
"github.com/rocboss/paopao-ce/internal/dao/slonik/sqlc/auto/pgc"
"github.com/rocboss/paopao-ce/pkg/debug"
)
@ -22,14 +22,16 @@ var (
type topicSrv struct {
*pgxSrv
q *pgc.Queries
}
// UpsertTags update/insert tags info.
// Assume tags slice is distinct elements.
func (s *topicSrv) UpsertTags(userId int64, tags []string) (res cs.TagInfoList, err error) {
err = s.with(func(c context.Context, q dbr.Querier) error {
err = s.with(func(c context.Context, tx pgx.Tx) error {
now := time.Now().Unix()
upTags, err := q.IncrTags(c, &dbr.IncrTagsParams{
q := s.q.WithTx(tx)
upTags, err := q.IncrTags(c, &pgc.IncrTagsParams{
Tags: tags,
ModifiedOn: now,
})
@ -55,7 +57,7 @@ func (s *topicSrv) UpsertTags(userId int64, tags []string) (res cs.TagInfoList,
}
}
for _, tag := range tags {
id, err := q.InsertTags(c, &dbr.InsertTagsParams{
id, err := q.InsertTags(c, &pgc.InsertTagsParams{
UserID: userId,
Tag: tag,
CreatedOn: now,
@ -76,7 +78,7 @@ func (s *topicSrv) UpsertTags(userId int64, tags []string) (res cs.TagInfoList,
}
func (s *topicSrv) DecrTagsById(ids []int64) error {
return s.q.DecrTagsById(context.Background(), &dbr.DecrTagsByIdParams{
return s.q.DecrTagsById(context.Background(), &pgc.DecrTagsByIdParams{
Ids: ids,
ModifiedOn: time.Now().Unix(),
})
@ -86,7 +88,7 @@ func (s *topicSrv) ListTags(typ cs.TagType, limit int, offset int) (res cs.TagLi
ctx := context.Background()
switch typ {
case cs.TagTypeHot:
tags, err := s.q.HotTags(ctx, &dbr.HotTagsParams{Limit: int32(limit), Offset: int32(offset)})
tags, err := s.q.HotTags(ctx, &pgc.HotTagsParams{Limit: int32(limit), Offset: int32(offset)})
if err != nil {
return nil, err
}
@ -107,7 +109,7 @@ func (s *topicSrv) ListTags(typ cs.TagType, limit int, offset int) (res cs.TagLi
})
}
case cs.TagTypeNew:
tags, err := s.q.NewestTags(ctx, &dbr.NewestTagsParams{Limit: int32(limit), Offset: int32(offset)})
tags, err := s.q.NewestTags(ctx, &pgc.NewestTagsParams{Limit: int32(limit), Offset: int32(offset)})
if err != nil {
return nil, err
}
@ -197,5 +199,6 @@ func (s *topicSrv) StickTopic(userId int64, topicId int64) (int8, error) {
func newTopicService(db *pgx.Conn) core.TopicService {
return &topicSrv{
pgxSrv: newPgxSrv(db),
q: pgc.New(db),
}
}

Loading…
Cancel
Save