144 lines
3.2 KiB
Go
144 lines
3.2 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.27.0
|
|
// source: blogs_queries.sql
|
|
|
|
package db_repo
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createBlogByUserId = `-- name: CreateBlogByUserId :one
|
|
INSERT INTO public.blogs
|
|
(blog_id, user_id, title, description, category_id, created_at)
|
|
VALUES($1, $2, $3, $4, $5, CURRENT_TIMESTAMP)
|
|
RETURNING blog_id, user_id, title, description, category_id, created_at
|
|
`
|
|
|
|
type CreateBlogByUserIdParams struct {
|
|
BlogID int64 `json:"blog_id"`
|
|
UserID int64 `json:"user_id"`
|
|
Title pgtype.Text `json:"title" validate:"required"`
|
|
Description pgtype.Text `json:"description"`
|
|
CategoryID pgtype.Int4 `json:"category_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateBlogByUserId(ctx context.Context, arg CreateBlogByUserIdParams) (Blog, error) {
|
|
row := q.db.QueryRow(ctx, createBlogByUserId,
|
|
arg.BlogID,
|
|
arg.UserID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.CategoryID,
|
|
)
|
|
var i Blog
|
|
err := row.Scan(
|
|
&i.BlogID,
|
|
&i.UserID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.CategoryID,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteBlogByBlogId = `-- name: DeleteBlogByBlogId :exec
|
|
DELETE FROM public.blogs
|
|
WHERE blog_id=$1
|
|
`
|
|
|
|
func (q *Queries) DeleteBlogByBlogId(ctx context.Context, blogID int64) error {
|
|
_, err := q.db.Exec(ctx, deleteBlogByBlogId, blogID)
|
|
return err
|
|
}
|
|
|
|
const getBlogByBlogId = `-- name: GetBlogByBlogId :one
|
|
SELECT blog_id, user_id, title, description, category_id, created_at
|
|
FROM public.blogs
|
|
WHERE blog_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetBlogByBlogId(ctx context.Context, blogID int64) (Blog, error) {
|
|
row := q.db.QueryRow(ctx, getBlogByBlogId, blogID)
|
|
var i Blog
|
|
err := row.Scan(
|
|
&i.BlogID,
|
|
&i.UserID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.CategoryID,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getBlogsByUserId = `-- name: GetBlogsByUserId :many
|
|
SELECT blog_id, user_id, title, description, category_id, created_at
|
|
FROM public.blogs
|
|
WHERE user_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetBlogsByUserId(ctx context.Context, userID int64) ([]Blog, error) {
|
|
rows, err := q.db.Query(ctx, getBlogsByUserId, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Blog
|
|
for rows.Next() {
|
|
var i Blog
|
|
if err := rows.Scan(
|
|
&i.BlogID,
|
|
&i.UserID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.CategoryID,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateBlogInfoByBlogId = `-- name: UpdateBlogInfoByBlogId :one
|
|
UPDATE public.blogs
|
|
SET title=$1, description=$2, category_id=$3
|
|
WHERE blog_id=$4
|
|
RETURNING blog_id, user_id, title, description, category_id, created_at
|
|
`
|
|
|
|
type UpdateBlogInfoByBlogIdParams struct {
|
|
Title pgtype.Text `json:"title" validate:"required"`
|
|
Description pgtype.Text `json:"description"`
|
|
CategoryID pgtype.Int4 `json:"category_id"`
|
|
BlogID int64 `json:"blog_id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBlogInfoByBlogId(ctx context.Context, arg UpdateBlogInfoByBlogIdParams) (Blog, error) {
|
|
row := q.db.QueryRow(ctx, updateBlogInfoByBlogId,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.CategoryID,
|
|
arg.BlogID,
|
|
)
|
|
var i Blog
|
|
err := row.Scan(
|
|
&i.BlogID,
|
|
&i.UserID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.CategoryID,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|