234 lines
4.7 KiB
Go
234 lines
4.7 KiB
Go
|
// Code generated by sqlc. DO NOT EDIT.
|
||
|
// versions:
|
||
|
// sqlc v1.28.0
|
||
|
// source: pages.sql
|
||
|
|
||
|
package dbq
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"github.com/jackc/pgx/v5/pgtype"
|
||
|
)
|
||
|
|
||
|
const deletePageWithID = `-- name: DeletePageWithID :exec
|
||
|
DELETE FROM pages WHERE id = $1
|
||
|
`
|
||
|
|
||
|
func (q *Queries) DeletePageWithID(ctx context.Context, id int64) error {
|
||
|
_, err := q.db.Exec(ctx, deletePageWithID, id)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const getPageWithID = `-- name: GetPageWithID :one
|
||
|
SELECT id, site_id, bundle_id, name, name_provenance, title, role, body, state, props, publish_date, created_at, updated_at FROM pages WHERE id = $1
|
||
|
`
|
||
|
|
||
|
func (q *Queries) GetPageWithID(ctx context.Context, id int64) (Page, error) {
|
||
|
row := q.db.QueryRow(ctx, getPageWithID, id)
|
||
|
var i Page
|
||
|
err := row.Scan(
|
||
|
&i.ID,
|
||
|
&i.SiteID,
|
||
|
&i.BundleID,
|
||
|
&i.Name,
|
||
|
&i.NameProvenance,
|
||
|
&i.Title,
|
||
|
&i.Role,
|
||
|
&i.Body,
|
||
|
&i.State,
|
||
|
&i.Props,
|
||
|
&i.PublishDate,
|
||
|
&i.CreatedAt,
|
||
|
&i.UpdatedAt,
|
||
|
)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const insertPage = `-- name: InsertPage :one
|
||
|
INSERT INTO pages (
|
||
|
site_id,
|
||
|
bundle_id,
|
||
|
name,
|
||
|
name_provenance,
|
||
|
title,
|
||
|
role,
|
||
|
body,
|
||
|
state,
|
||
|
props,
|
||
|
publish_date,
|
||
|
created_at,
|
||
|
updated_at
|
||
|
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $11)
|
||
|
RETURNING id
|
||
|
`
|
||
|
|
||
|
type InsertPageParams struct {
|
||
|
SiteID int64
|
||
|
BundleID int64
|
||
|
Name string
|
||
|
NameProvenance PageNameProvenance
|
||
|
Title pgtype.Text
|
||
|
Role pgtype.Int8
|
||
|
Body string
|
||
|
State PostState
|
||
|
Props []byte
|
||
|
PublishDate pgtype.Timestamptz
|
||
|
CreatedAt pgtype.Timestamp
|
||
|
}
|
||
|
|
||
|
func (q *Queries) InsertPage(ctx context.Context, arg InsertPageParams) (int64, error) {
|
||
|
row := q.db.QueryRow(ctx, insertPage,
|
||
|
arg.SiteID,
|
||
|
arg.BundleID,
|
||
|
arg.Name,
|
||
|
arg.NameProvenance,
|
||
|
arg.Title,
|
||
|
arg.Role,
|
||
|
arg.Body,
|
||
|
arg.State,
|
||
|
arg.Props,
|
||
|
arg.PublishDate,
|
||
|
arg.CreatedAt,
|
||
|
)
|
||
|
var id int64
|
||
|
err := row.Scan(&id)
|
||
|
return id, err
|
||
|
}
|
||
|
|
||
|
const listPages = `-- name: ListPages :many
|
||
|
SELECT id, site_id, bundle_id, name, name_provenance, title, role, body, state, props, publish_date, created_at, updated_at FROM pages WHERE site_id = $1 ORDER BY name ASC LIMIT 25
|
||
|
`
|
||
|
|
||
|
func (q *Queries) ListPages(ctx context.Context, siteID int64) ([]Page, error) {
|
||
|
rows, err := q.db.Query(ctx, listPages, siteID)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
var items []Page
|
||
|
for rows.Next() {
|
||
|
var i Page
|
||
|
if err := rows.Scan(
|
||
|
&i.ID,
|
||
|
&i.SiteID,
|
||
|
&i.BundleID,
|
||
|
&i.Name,
|
||
|
&i.NameProvenance,
|
||
|
&i.Title,
|
||
|
&i.Role,
|
||
|
&i.Body,
|
||
|
&i.State,
|
||
|
&i.Props,
|
||
|
&i.PublishDate,
|
||
|
&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 listPublishablePages = `-- name: ListPublishablePages :many
|
||
|
SELECT id, site_id, bundle_id, name, name_provenance, title, role, body, state, props, publish_date, created_at, updated_at
|
||
|
FROM pages
|
||
|
WHERE id > $1 AND site_id = $2 AND state = 'published'
|
||
|
ORDER BY id LIMIT 100
|
||
|
`
|
||
|
|
||
|
type ListPublishablePagesParams struct {
|
||
|
ID int64
|
||
|
SiteID int64
|
||
|
}
|
||
|
|
||
|
func (q *Queries) ListPublishablePages(ctx context.Context, arg ListPublishablePagesParams) ([]Page, error) {
|
||
|
rows, err := q.db.Query(ctx, listPublishablePages, arg.ID, arg.SiteID)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
var items []Page
|
||
|
for rows.Next() {
|
||
|
var i Page
|
||
|
if err := rows.Scan(
|
||
|
&i.ID,
|
||
|
&i.SiteID,
|
||
|
&i.BundleID,
|
||
|
&i.Name,
|
||
|
&i.NameProvenance,
|
||
|
&i.Title,
|
||
|
&i.Role,
|
||
|
&i.Body,
|
||
|
&i.State,
|
||
|
&i.Props,
|
||
|
&i.PublishDate,
|
||
|
&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 updatePage = `-- name: UpdatePage :exec
|
||
|
UPDATE pages SET
|
||
|
site_id = $2,
|
||
|
bundle_id = $3,
|
||
|
name = $4,
|
||
|
name_provenance = $5,
|
||
|
title = $6,
|
||
|
role = $7,
|
||
|
body = $8,
|
||
|
state = $9,
|
||
|
props = $10,
|
||
|
publish_date = $11,
|
||
|
created_at = $12,
|
||
|
updated_at = $13
|
||
|
WHERE id = $1
|
||
|
`
|
||
|
|
||
|
type UpdatePageParams struct {
|
||
|
ID int64
|
||
|
SiteID int64
|
||
|
BundleID int64
|
||
|
Name string
|
||
|
NameProvenance PageNameProvenance
|
||
|
Title pgtype.Text
|
||
|
Role pgtype.Int8
|
||
|
Body string
|
||
|
State PostState
|
||
|
Props []byte
|
||
|
PublishDate pgtype.Timestamptz
|
||
|
CreatedAt pgtype.Timestamp
|
||
|
UpdatedAt pgtype.Timestamp
|
||
|
}
|
||
|
|
||
|
func (q *Queries) UpdatePage(ctx context.Context, arg UpdatePageParams) error {
|
||
|
_, err := q.db.Exec(ctx, updatePage,
|
||
|
arg.ID,
|
||
|
arg.SiteID,
|
||
|
arg.BundleID,
|
||
|
arg.Name,
|
||
|
arg.NameProvenance,
|
||
|
arg.Title,
|
||
|
arg.Role,
|
||
|
arg.Body,
|
||
|
arg.State,
|
||
|
arg.Props,
|
||
|
arg.PublishDate,
|
||
|
arg.CreatedAt,
|
||
|
arg.UpdatedAt,
|
||
|
)
|
||
|
return err
|
||
|
}
|