mirror of https://github.com/rocboss/paopao-ce
parent
efde294128
commit
513bdc75fa
@ -0,0 +1,60 @@
|
|||||||
|
// 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)`
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
// 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
|
||||||
|
var postId int64
|
||||||
|
err := s.p.AddPost.Get(&postId, r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
r.ID = postId
|
||||||
|
s.cis.SendAction(core.IdxActCreatePost, r)
|
||||||
|
return r, nil
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
--------------------------------------------------------------------------------
|
||||||
|
-- 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;
|
||||||
|
|
Loading…
Reference in new issue