Enshi/enshi_back/db/go_queries/posts_queries.sql.go
2024-11-09 22:51:36 +03:00

184 lines
4.0 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.27.0
// source: posts_queries.sql
package db_repo
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const createPost = `-- name: CreatePost :one
INSERT INTO public.posts
(post_id, blog_id, user_id, title, "content", created_at, updated_at)
VALUES($1, $2, $3, $4, $5, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
RETURNING post_id, blog_id, user_id, title, content, created_at, updated_at
`
type CreatePostParams struct {
PostID int64 `json:"post_id"`
BlogID pgtype.Int8 `json:"blog_id"`
UserID int64 `json:"user_id"`
Title pgtype.Text `json:"title"`
Content pgtype.Text `json:"content"`
}
func (q *Queries) CreatePost(ctx context.Context, arg CreatePostParams) (Post, error) {
row := q.db.QueryRow(ctx, createPost,
arg.PostID,
arg.BlogID,
arg.UserID,
arg.Title,
arg.Content,
)
var i Post
err := row.Scan(
&i.PostID,
&i.BlogID,
&i.UserID,
&i.Title,
&i.Content,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deletePostByPostId = `-- name: DeletePostByPostId :exec
DELETE FROM public.posts
WHERE post_id=$1
`
func (q *Queries) DeletePostByPostId(ctx context.Context, postID int64) error {
_, err := q.db.Exec(ctx, deletePostByPostId, postID)
return err
}
const getPostsByBlogId = `-- name: GetPostsByBlogId :many
SELECT post_id, blog_id, user_id, title, content, created_at, updated_at
FROM public.posts posts
where posts.blog_id = $1
`
func (q *Queries) GetPostsByBlogId(ctx context.Context, blogID pgtype.Int8) ([]Post, error) {
rows, err := q.db.Query(ctx, getPostsByBlogId, blogID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Post
for rows.Next() {
var i Post
if err := rows.Scan(
&i.PostID,
&i.BlogID,
&i.UserID,
&i.Title,
&i.Content,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getPostsByPostId = `-- name: GetPostsByPostId :one
SELECT post_id, blog_id, user_id, title, content, created_at, updated_at
FROM public.posts posts
where posts.post_id = $1
`
func (q *Queries) GetPostsByPostId(ctx context.Context, postID int64) (Post, error) {
row := q.db.QueryRow(ctx, getPostsByPostId, postID)
var i Post
err := row.Scan(
&i.PostID,
&i.BlogID,
&i.UserID,
&i.Title,
&i.Content,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getPostsByUserId = `-- name: GetPostsByUserId :many
SELECT post_id, blog_id, user_id, title, content, created_at, updated_at
FROM public.posts posts
where posts.user_id = $1
`
func (q *Queries) GetPostsByUserId(ctx context.Context, userID int64) ([]Post, error) {
rows, err := q.db.Query(ctx, getPostsByUserId, userID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Post
for rows.Next() {
var i Post
if err := rows.Scan(
&i.PostID,
&i.BlogID,
&i.UserID,
&i.Title,
&i.Content,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updatePostByPostId = `-- name: UpdatePostByPostId :one
UPDATE public.posts
SET blog_id=$1, user_id=$2, title=$3, "content"=$4, updated_at=CURRENT_TIMESTAMP
WHERE post_id = $5
RETURNING post_id, blog_id, user_id, title, content, created_at, updated_at
`
type UpdatePostByPostIdParams struct {
BlogID pgtype.Int8 `json:"blog_id"`
UserID int64 `json:"user_id"`
Title pgtype.Text `json:"title"`
Content pgtype.Text `json:"content"`
PostID int64 `json:"post_id"`
}
func (q *Queries) UpdatePostByPostId(ctx context.Context, arg UpdatePostByPostIdParams) (Post, error) {
row := q.db.QueryRow(ctx, updatePostByPostId,
arg.BlogID,
arg.UserID,
arg.Title,
arg.Content,
arg.PostID,
)
var i Post
err := row.Scan(
&i.PostID,
&i.BlogID,
&i.UserID,
&i.Title,
&i.Content,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}