nim/nimdb/query.sql.go

490 lines
12 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// source: query.sql
package nimdb
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const addCommentHeart = `-- name: AddCommentHeart :one
UPDATE comment SET heart = heart + 1 WHERE id=$1 RETURNING heart
`
func (q *Queries) AddCommentHeart(ctx context.Context, id int32) (int32, error) {
row := q.db.QueryRow(ctx, addCommentHeart, id)
var heart int32
err := row.Scan(&heart)
return heart, err
}
const addPostHeart = `-- name: AddPostHeart :one
UPDATE posts SET heart = heart + 1 WHERE id=$1 RETURNING heart
`
func (q *Queries) AddPostHeart(ctx context.Context, id int32) (int32, error) {
row := q.db.QueryRow(ctx, addPostHeart, id)
var heart int32
err := row.Scan(&heart)
return heart, err
}
const adminCreateAccount = `-- name: AdminCreateAccount :exec
INSERT INTO admin (username, password, totp) VALUES ($1, $2,$3)
`
type AdminCreateAccountParams struct {
Username string `json:"username"`
Password string `json:"password"`
Totp string `json:"totp"`
}
func (q *Queries) AdminCreateAccount(ctx context.Context, arg AdminCreateAccountParams) error {
_, err := q.db.Exec(ctx, adminCreateAccount, arg.Username, arg.Password, arg.Totp)
return err
}
const adminGetMedia = `-- name: AdminGetMedia :many
SELECT url from media WHERE post_id = $1
`
func (q *Queries) AdminGetMedia(ctx context.Context, postID pgtype.Int4) ([]string, error) {
rows, err := q.db.Query(ctx, adminGetMedia, postID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []string
for rows.Next() {
var url string
if err := rows.Scan(&url); err != nil {
return nil, err
}
items = append(items, url)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const adminGetPost = `-- name: AdminGetPost :many
SELECT id, content, signing, post_at FROM posts WHERE phase = 'pending' ORDER BY id DESC LIMIT 100
`
type AdminGetPostRow struct {
ID int32 `json:"id"`
Content string `json:"content"`
Signing pgtype.Text `json:"signing"`
PostAt pgtype.Timestamptz `json:"post_at"`
}
func (q *Queries) AdminGetPost(ctx context.Context) ([]AdminGetPostRow, error) {
rows, err := q.db.Query(ctx, adminGetPost)
if err != nil {
return nil, err
}
defer rows.Close()
var items []AdminGetPostRow
for rows.Next() {
var i AdminGetPostRow
if err := rows.Scan(
&i.ID,
&i.Content,
&i.Signing,
&i.PostAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const adminLoginGetTOTP = `-- name: AdminLoginGetTOTP :one
SELECT totp, super FROM admin WHERE username = $1 AND password = $2
`
type AdminLoginGetTOTPParams struct {
Username string `json:"username"`
Password string `json:"password"`
}
type AdminLoginGetTOTPRow struct {
Totp string `json:"totp"`
Super bool `json:"super"`
}
func (q *Queries) AdminLoginGetTOTP(ctx context.Context, arg AdminLoginGetTOTPParams) (AdminLoginGetTOTPRow, error) {
row := q.db.QueryRow(ctx, adminLoginGetTOTP, arg.Username, arg.Password)
var i AdminLoginGetTOTPRow
err := row.Scan(&i.Totp, &i.Super)
return i, err
}
const adminUpdateImage = `-- name: AdminUpdateImage :exec
UPDATE media SET visible = false WHERE post_id=$1
`
func (q *Queries) AdminUpdateImage(ctx context.Context, postID pgtype.Int4) error {
_, err := q.db.Exec(ctx, adminUpdateImage, postID)
return err
}
const adminVerify = `-- name: AdminVerify :one
UPDATE posts SET phase = $1 WHERE id=$2 AND phase = 'pending' RETURNING id
`
type AdminVerifyParams struct {
Phase PostPhase `json:"phase"`
ID int32 `json:"id"`
}
func (q *Queries) AdminVerify(ctx context.Context, arg AdminVerifyParams) (int32, error) {
row := q.db.QueryRow(ctx, adminVerify, arg.Phase, arg.ID)
var id int32
err := row.Scan(&id)
return id, err
}
const deletePost = `-- name: DeletePost :exec
UPDATE posts SET phase = 'deleted' WHERE id = $1 AND hash=$2
`
type DeletePostParams struct {
ID int32 `json:"id"`
Hash string `json:"hash"`
}
func (q *Queries) DeletePost(ctx context.Context, arg DeletePostParams) error {
_, err := q.db.Exec(ctx, deletePost, arg.ID, arg.Hash)
return err
}
const getComment = `-- name: GetComment :many
SELECT id, content, signing, post_at
FROM comment
WHERE phase = 'ok' AND post_id = $1
ORDER BY id DESC
LIMIT $2
`
type GetCommentParams struct {
PostID int32 `json:"post_id"`
Limit int32 `json:"limit"`
}
type GetCommentRow struct {
ID int32 `json:"id"`
Content string `json:"content"`
Signing pgtype.Text `json:"signing"`
PostAt pgtype.Timestamptz `json:"post_at"`
}
func (q *Queries) GetComment(ctx context.Context, arg GetCommentParams) ([]GetCommentRow, error) {
rows, err := q.db.Query(ctx, getComment, arg.PostID, arg.Limit)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetCommentRow
for rows.Next() {
var i GetCommentRow
if err := rows.Scan(
&i.ID,
&i.Content,
&i.Signing,
&i.PostAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getCommentWithCursor = `-- name: GetCommentWithCursor :many
SELECT id, content, signing, post_at
FROM comment
WHERE id <= $1 AND phase = 'ok' AND post_id = $2
ORDER BY id DESC
LIMIT $3
`
type GetCommentWithCursorParams struct {
ID int32 `json:"id"`
PostID int32 `json:"post_id"`
Limit int32 `json:"limit"`
}
type GetCommentWithCursorRow struct {
ID int32 `json:"id"`
Content string `json:"content"`
Signing pgtype.Text `json:"signing"`
PostAt pgtype.Timestamptz `json:"post_at"`
}
func (q *Queries) GetCommentWithCursor(ctx context.Context, arg GetCommentWithCursorParams) ([]GetCommentWithCursorRow, error) {
rows, err := q.db.Query(ctx, getCommentWithCursor, arg.ID, arg.PostID, arg.Limit)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetCommentWithCursorRow
for rows.Next() {
var i GetCommentWithCursorRow
if err := rows.Scan(
&i.ID,
&i.Content,
&i.Signing,
&i.PostAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getPost = `-- name: GetPost :many
SELECT id, content, signing, post_at, heart, igid, array_agg(url) as enclosure
FROM posts
LEFT JOIN media ON post_id is not null AND post_id = id AND visible
WHERE phase = 'ok'
GROUP BY id
ORDER BY id DESC
LIMIT $1
`
type GetPostRow struct {
ID int32 `json:"id"`
Content string `json:"content"`
Signing pgtype.Text `json:"signing"`
PostAt pgtype.Timestamptz `json:"post_at"`
Heart int32 `json:"heart"`
Igid pgtype.Text `json:"igid"`
Enclosure interface{} `json:"enclosure"`
}
func (q *Queries) GetPost(ctx context.Context, limit int32) ([]GetPostRow, error) {
rows, err := q.db.Query(ctx, getPost, limit)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetPostRow
for rows.Next() {
var i GetPostRow
if err := rows.Scan(
&i.ID,
&i.Content,
&i.Signing,
&i.PostAt,
&i.Heart,
&i.Igid,
&i.Enclosure,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getPostWithCursor = `-- name: GetPostWithCursor :many
SELECT id, content, signing, post_at, heart, igid, array_agg(url) as enclosure
FROM posts
LEFT JOIN media ON post_id is not null AND post_id = id AND visible
WHERE id <= $1 AND phase = 'ok'
GROUP BY id
ORDER BY id DESC
LIMIT $2
`
type GetPostWithCursorParams struct {
ID int32 `json:"id"`
Limit int32 `json:"limit"`
}
type GetPostWithCursorRow struct {
ID int32 `json:"id"`
Content string `json:"content"`
Signing pgtype.Text `json:"signing"`
PostAt pgtype.Timestamptz `json:"post_at"`
Heart int32 `json:"heart"`
Igid pgtype.Text `json:"igid"`
Enclosure interface{} `json:"enclosure"`
}
func (q *Queries) GetPostWithCursor(ctx context.Context, arg GetPostWithCursorParams) ([]GetPostWithCursorRow, error) {
rows, err := q.db.Query(ctx, getPostWithCursor, arg.ID, arg.Limit)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetPostWithCursorRow
for rows.Next() {
var i GetPostWithCursorRow
if err := rows.Scan(
&i.ID,
&i.Content,
&i.Signing,
&i.PostAt,
&i.Heart,
&i.Igid,
&i.Enclosure,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const insertCommentImage = `-- name: InsertCommentImage :exec
INSERT INTO media (url, comment_id) VALUES ($1, $2)
`
type InsertCommentImageParams struct {
Url string `json:"url"`
CommentID pgtype.Int4 `json:"comment_id"`
}
func (q *Queries) InsertCommentImage(ctx context.Context, arg InsertCommentImageParams) error {
_, err := q.db.Exec(ctx, insertCommentImage, arg.Url, arg.CommentID)
return err
}
const insertPost = `-- name: InsertPost :one
INSERT INTO posts (content,signing,hash)
VALUES ($1, $2 ,$3)
RETURNING id,hash
`
type InsertPostParams struct {
Content string `json:"content"`
Signing pgtype.Text `json:"signing"`
Hash string `json:"hash"`
}
type InsertPostRow struct {
ID int32 `json:"id"`
Hash string `json:"hash"`
}
func (q *Queries) InsertPost(ctx context.Context, arg InsertPostParams) (InsertPostRow, error) {
row := q.db.QueryRow(ctx, insertPost, arg.Content, arg.Signing, arg.Hash)
var i InsertPostRow
err := row.Scan(&i.ID, &i.Hash)
return i, err
}
const insertPostImage = `-- name: InsertPostImage :exec
INSERT INTO media (url, post_id) VALUES ($1, $2)
`
type InsertPostImageParams struct {
Url string `json:"url"`
PostID pgtype.Int4 `json:"post_id"`
}
func (q *Queries) InsertPostImage(ctx context.Context, arg InsertPostImageParams) error {
_, err := q.db.Exec(ctx, insertPostImage, arg.Url, arg.PostID)
return err
}
const invalidateMedia = `-- name: InvalidateMedia :exec
UPDATE media SET visible = false WHERE post_id = $1
`
func (q *Queries) InvalidateMedia(ctx context.Context, postID pgtype.Int4) error {
_, err := q.db.Exec(ctx, invalidateMedia, postID)
return err
}
const superAdminGetPost = `-- name: SuperAdminGetPost :many
SELECT id, content, signing, post_at, phase FROM posts WHERE phase = 'pending' OR phase = 'rejected' ORDER BY id DESC LIMIT 100
`
type SuperAdminGetPostRow struct {
ID int32 `json:"id"`
Content string `json:"content"`
Signing pgtype.Text `json:"signing"`
PostAt pgtype.Timestamptz `json:"post_at"`
Phase PostPhase `json:"phase"`
}
func (q *Queries) SuperAdminGetPost(ctx context.Context) ([]SuperAdminGetPostRow, error) {
rows, err := q.db.Query(ctx, superAdminGetPost)
if err != nil {
return nil, err
}
defer rows.Close()
var items []SuperAdminGetPostRow
for rows.Next() {
var i SuperAdminGetPostRow
if err := rows.Scan(
&i.ID,
&i.Content,
&i.Signing,
&i.PostAt,
&i.Phase,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const superAdminVerify = `-- name: SuperAdminVerify :one
UPDATE posts SET phase = $1 WHERE id=$2 AND (phase = 'pending' OR phase = 'rejected') RETURNING id
`
type SuperAdminVerifyParams struct {
Phase PostPhase `json:"phase"`
ID int32 `json:"id"`
}
func (q *Queries) SuperAdminVerify(ctx context.Context, arg SuperAdminVerifyParams) (int32, error) {
row := q.db.QueryRow(ctx, superAdminVerify, arg.Phase, arg.ID)
var id int32
err := row.Scan(&id)
return id, err
}
const updatePostIGID = `-- name: UpdatePostIGID :exec
UPDATE posts set igid = $1 WHERE id = $2
`
type UpdatePostIGIDParams struct {
Igid pgtype.Text `json:"igid"`
ID int32 `json:"id"`
}
func (q *Queries) UpdatePostIGID(ctx context.Context, arg UpdatePostIGIDParams) error {
_, err := q.db.Exec(ctx, updatePostIGID, arg.Igid, arg.ID)
return err
}