mirror of https://github.com/rocboss/paopao-ce
commit
71c7f2ee2a
@ -0,0 +1,65 @@
|
||||
// Code generated by Yesql. DO NOT EDIT.
|
||||
// versions:
|
||||
// - Yesql v1.8.5
|
||||
|
||||
package pg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/alimy/yesql"
|
||||
"github.com/bitbus/sqlx"
|
||||
)
|
||||
|
||||
var (
|
||||
_ = fmt.Errorf("error for placeholder")
|
||||
)
|
||||
|
||||
const (
|
||||
_TweetManage_AddPost = `INSERT INTO @post (user_id, tags, ip, ip_loc, attachment_price, visibility, latest_replied_on, created_on) VALUES (:user_id, :tags, :ip, :ip_loc, :attachment_price, :visibility, :latest_replied_on, :created_on) RETURNING id`
|
||||
_TweetManage_AddPostContent = `INSERT INTO @post_content (post_id, user_id, content, type, sort, created_on) VALUES (:post_id, :user_id, :content, :type, :sort, :created_on) RETURNING id`
|
||||
)
|
||||
|
||||
// PreparexContext enhances the Conn interface with context.
|
||||
type PreparexContext interface {
|
||||
// PrepareContext prepares a statement.
|
||||
// The provided context is used for the preparation of the statement, not for
|
||||
// the execution of the statement.
|
||||
PreparexContext(ctx context.Context, query string) (*sqlx.Stmt, error)
|
||||
|
||||
// PrepareNamedContext returns an sqlx.NamedStmt
|
||||
PrepareNamedContext(ctx context.Context, query string) (*sqlx.NamedStmt, error)
|
||||
|
||||
// Rebind rebind query to adapte SQL Driver
|
||||
Rebind(query string) string
|
||||
}
|
||||
|
||||
// PreparexBuilder preparex builder interface for sqlx
|
||||
type PreparexBuilder interface {
|
||||
PreparexContext
|
||||
QueryHook(query string) string
|
||||
}
|
||||
|
||||
type TweetManage struct {
|
||||
yesql.Namespace `yesql:"tweet_manage"`
|
||||
AddPost *sqlx.NamedStmt `yesql:"add_post"`
|
||||
AddPostContent *sqlx.NamedStmt `yesql:"add_post_content"`
|
||||
}
|
||||
|
||||
func BuildTweetManage(p PreparexBuilder, ctx ...context.Context) (obj *TweetManage, err error) {
|
||||
var c context.Context
|
||||
if len(ctx) > 0 && ctx[0] != nil {
|
||||
c = ctx[0]
|
||||
} else {
|
||||
c = context.Background()
|
||||
}
|
||||
obj = &TweetManage{}
|
||||
if obj.AddPost, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_TweetManage_AddPost))); err != nil {
|
||||
return nil, fmt.Errorf("prepare _TweetManage_AddPost error: %w", err)
|
||||
}
|
||||
if obj.AddPostContent, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_TweetManage_AddPostContent))); err != nil {
|
||||
return nil, fmt.Errorf("prepare _TweetManage_AddPostContent error: %w", err)
|
||||
}
|
||||
return
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
// Copyright 2023 ROC. All rights reserved.
|
||||
// Use of this source code is governed by a MIT style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package sakila
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/rocboss/paopao-ce/internal/core"
|
||||
"github.com/rocboss/paopao-ce/internal/core/ms"
|
||||
"github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr"
|
||||
"github.com/rocboss/paopao-ce/internal/dao/sakila/auto/pg"
|
||||
)
|
||||
|
||||
var (
|
||||
_ core.TweetManageService = (*pgTweetManageSrv)(nil)
|
||||
)
|
||||
|
||||
type pgTweetManageSrv struct {
|
||||
*tweetManageSrv
|
||||
p *pg.TweetManage
|
||||
}
|
||||
|
||||
func (s *pgTweetManageSrv) CreatePost(r *ms.Post) (*ms.Post, error) {
|
||||
now := time.Now().Unix()
|
||||
r.Model = &dbr.Model{CreatedOn: now}
|
||||
r.LatestRepliedOn = now
|
||||
err := s.p.AddPost.Get(&r.ID, r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.cis.SendAction(core.IdxActCreatePost, r)
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (s *pgTweetManageSrv) CreatePostContent(r *ms.PostContent) (*ms.PostContent, error) {
|
||||
r.Model = &ms.Model{CreatedOn: time.Now().Unix()}
|
||||
err := s.p.AddPostContent.Get(&r.ID, r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return r, nil
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
--------------------------------------------------------------------------------
|
||||
-- file yesql.sql
|
||||
-- this sql file contain some PostgreSQL special sql dml
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- name: add_post@tweet_manage
|
||||
-- prepare: named_stmt
|
||||
INSERT INTO @post (user_id, tags, ip, ip_loc, attachment_price, visibility, latest_replied_on, created_on)
|
||||
VALUES (:user_id, :tags, :ip, :ip_loc, :attachment_price, :visibility, :latest_replied_on, :created_on)
|
||||
RETURNING id;
|
||||
|
||||
-- name: add_post_content@tweet_manage
|
||||
-- prepare: named_stmt
|
||||
INSERT INTO @post_content (post_id, user_id, content, type, sort, created_on)
|
||||
VALUES (:post_id, :user_id, :content, :type, :sort, :created_on)
|
||||
RETURNING id;
|
Loading…
Reference in new issue