weiro/providers/db/gen/sqlgen/posts.sql.go

231 lines
4.5 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: posts.sql
package sqlgen
import (
"context"
)
const hardDeletePost = `-- name: HardDeletePost :exec
DELETE FROM posts WHERE id = ?
`
func (q *Queries) HardDeletePost(ctx context.Context, id int64) error {
_, err := q.db.ExecContext(ctx, hardDeletePost, id)
return err
}
const insertPost = `-- name: InsertPost :one
INSERT INTO posts (
site_id,
state,
guid,
title,
body,
slug,
created_at,
updated_at,
published_at,
deleted_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
RETURNING id
`
type InsertPostParams struct {
SiteID int64
State int64
Guid string
Title string
Body string
Slug string
CreatedAt int64
UpdatedAt int64
PublishedAt int64
DeletedAt int64
}
func (q *Queries) InsertPost(ctx context.Context, arg InsertPostParams) (int64, error) {
row := q.db.QueryRowContext(ctx, insertPost,
arg.SiteID,
arg.State,
arg.Guid,
arg.Title,
arg.Body,
arg.Slug,
arg.CreatedAt,
arg.UpdatedAt,
arg.PublishedAt,
arg.DeletedAt,
)
var id int64
err := row.Scan(&id)
return id, err
}
const restorePost = `-- name: RestorePost :exec
UPDATE posts SET deleted_at = 0 WHERE id = ?
`
func (q *Queries) RestorePost(ctx context.Context, id int64) error {
_, err := q.db.ExecContext(ctx, restorePost, id)
return err
}
const selectPost = `-- name: SelectPost :one
SELECT id, site_id, state, guid, title, body, slug, created_at, updated_at, published_at, deleted_at FROM posts WHERE id = ? LIMIT 1
`
func (q *Queries) SelectPost(ctx context.Context, id int64) (Post, error) {
row := q.db.QueryRowContext(ctx, selectPost, id)
var i Post
err := row.Scan(
&i.ID,
&i.SiteID,
&i.State,
&i.Guid,
&i.Title,
&i.Body,
&i.Slug,
&i.CreatedAt,
&i.UpdatedAt,
&i.PublishedAt,
&i.DeletedAt,
)
return i, err
}
const selectPostByGUID = `-- name: SelectPostByGUID :one
SELECT id, site_id, state, guid, title, body, slug, created_at, updated_at, published_at, deleted_at FROM posts WHERE guid = ? LIMIT 1
`
func (q *Queries) SelectPostByGUID(ctx context.Context, guid string) (Post, error) {
row := q.db.QueryRowContext(ctx, selectPostByGUID, guid)
var i Post
err := row.Scan(
&i.ID,
&i.SiteID,
&i.State,
&i.Guid,
&i.Title,
&i.Body,
&i.Slug,
&i.CreatedAt,
&i.UpdatedAt,
&i.PublishedAt,
&i.DeletedAt,
)
return i, err
}
const selectPostsOfSite = `-- name: SelectPostsOfSite :many
SELECT id, site_id, state, guid, title, body, slug, created_at, updated_at, published_at, deleted_at
FROM posts
WHERE site_id = ?1 AND (
CASE CAST (?2 AS TEXT)
WHEN 'deleted' THEN deleted_at > 0
ELSE deleted_at = 0
END
) ORDER BY created_at DESC LIMIT ?4 OFFSET ?3
`
type SelectPostsOfSiteParams struct {
SiteID int64
PostFilter string
Offset int64
Limit int64
}
func (q *Queries) SelectPostsOfSite(ctx context.Context, arg SelectPostsOfSiteParams) ([]Post, error) {
rows, err := q.db.QueryContext(ctx, selectPostsOfSite,
arg.SiteID,
arg.PostFilter,
arg.Offset,
arg.Limit,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Post
for rows.Next() {
var i Post
if err := rows.Scan(
&i.ID,
&i.SiteID,
&i.State,
&i.Guid,
&i.Title,
&i.Body,
&i.Slug,
&i.CreatedAt,
&i.UpdatedAt,
&i.PublishedAt,
&i.DeletedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const softDeletePost = `-- name: SoftDeletePost :exec
UPDATE posts SET deleted_at = ? WHERE id = ?
`
type SoftDeletePostParams struct {
DeletedAt int64
ID int64
}
func (q *Queries) SoftDeletePost(ctx context.Context, arg SoftDeletePostParams) error {
_, err := q.db.ExecContext(ctx, softDeletePost, arg.DeletedAt, arg.ID)
return err
}
const updatePost = `-- name: UpdatePost :exec
UPDATE posts SET
title = ?,
state = ?,
body = ?,
slug = ?,
updated_at = ?,
published_at = ?,
deleted_at = ?
WHERE id = ?
`
type UpdatePostParams struct {
Title string
State int64
Body string
Slug string
UpdatedAt int64
PublishedAt int64
DeletedAt int64
ID int64
}
func (q *Queries) UpdatePost(ctx context.Context, arg UpdatePostParams) error {
_, err := q.db.ExecContext(ctx, updatePost,
arg.Title,
arg.State,
arg.Body,
arg.Slug,
arg.UpdatedAt,
arg.PublishedAt,
arg.DeletedAt,
arg.ID,
)
return err
}