Started working on pages
This commit is contained in:
parent
e2f159e980
commit
ba12398d2f
30 changed files with 1391 additions and 145 deletions
81
gen/sqlc/dbq/bundles.sql.go
Normal file
81
gen/sqlc/dbq/bundles.sql.go
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.28.0
|
||||
// source: bundles.sql
|
||||
|
||||
package dbq
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const getBundleWithID = `-- name: GetBundleWithID :one
|
||||
SELECT id, site_id, name, created_at, updated_at FROM bundles WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetBundleWithID(ctx context.Context, id int64) (Bundle, error) {
|
||||
row := q.db.QueryRow(ctx, getBundleWithID, id)
|
||||
var i Bundle
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.SiteID,
|
||||
&i.Name,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertBundle = `-- name: InsertBundle :one
|
||||
INSERT INTO bundles (
|
||||
site_id,
|
||||
name,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES ($1, $2, $3, $3) RETURNING id
|
||||
`
|
||||
|
||||
type InsertBundleParams struct {
|
||||
SiteID int64
|
||||
Name string
|
||||
CreatedAt pgtype.Timestamp
|
||||
}
|
||||
|
||||
func (q *Queries) InsertBundle(ctx context.Context, arg InsertBundleParams) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, insertBundle, arg.SiteID, arg.Name, arg.CreatedAt)
|
||||
var id int64
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const listBundles = `-- name: ListBundles :many
|
||||
SELECT id, site_id, name, created_at, updated_at FROM bundles WHERE site_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) ListBundles(ctx context.Context, siteID int64) ([]Bundle, error) {
|
||||
rows, err := q.db.Query(ctx, listBundles, siteID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Bundle
|
||||
for rows.Next() {
|
||||
var i Bundle
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.SiteID,
|
||||
&i.Name,
|
||||
&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
|
||||
}
|
||||
|
|
@ -11,6 +11,49 @@ import (
|
|||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type PageNameProvenance string
|
||||
|
||||
const (
|
||||
PageNameProvenanceUser PageNameProvenance = "user"
|
||||
PageNameProvenanceTitle PageNameProvenance = "title"
|
||||
PageNameProvenanceDate PageNameProvenance = "date"
|
||||
)
|
||||
|
||||
func (e *PageNameProvenance) Scan(src interface{}) error {
|
||||
switch s := src.(type) {
|
||||
case []byte:
|
||||
*e = PageNameProvenance(s)
|
||||
case string:
|
||||
*e = PageNameProvenance(s)
|
||||
default:
|
||||
return fmt.Errorf("unsupported scan type for PageNameProvenance: %T", src)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type NullPageNameProvenance struct {
|
||||
PageNameProvenance PageNameProvenance
|
||||
Valid bool // Valid is true if PageNameProvenance is not NULL
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (ns *NullPageNameProvenance) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
ns.PageNameProvenance, ns.Valid = "", false
|
||||
return nil
|
||||
}
|
||||
ns.Valid = true
|
||||
return ns.PageNameProvenance.Scan(value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (ns NullPageNameProvenance) Value() (driver.Value, error) {
|
||||
if !ns.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return string(ns.PageNameProvenance), nil
|
||||
}
|
||||
|
||||
type PostState string
|
||||
|
||||
const (
|
||||
|
|
@ -135,15 +178,47 @@ func (ns NullTargetType) Value() (driver.Value, error) {
|
|||
return string(ns.TargetType), nil
|
||||
}
|
||||
|
||||
type Post struct {
|
||||
type Bundle struct {
|
||||
ID int64
|
||||
SiteID int64
|
||||
Title pgtype.Text
|
||||
Body string
|
||||
State PostState
|
||||
Props []byte
|
||||
PostDate pgtype.Timestamptz
|
||||
Name string
|
||||
CreatedAt pgtype.Timestamp
|
||||
UpdatedAt pgtype.Timestamp
|
||||
}
|
||||
|
||||
type Page 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
|
||||
}
|
||||
|
||||
type Post struct {
|
||||
ID int64
|
||||
SiteID int64
|
||||
Title pgtype.Text
|
||||
Role pgtype.Int8
|
||||
Body string
|
||||
State PostState
|
||||
Props []byte
|
||||
PublishDate pgtype.Timestamptz
|
||||
CreatedAt pgtype.Timestamp
|
||||
UpdatedAt pgtype.Timestamp
|
||||
}
|
||||
|
||||
type PostRole struct {
|
||||
ID int64
|
||||
SiteID int64
|
||||
LayoutName string
|
||||
}
|
||||
|
||||
type PublishTarget struct {
|
||||
|
|
|
|||
233
gen/sqlc/dbq/pages.sql.go
Normal file
233
gen/sqlc/dbq/pages.sql.go
Normal file
|
|
@ -0,0 +1,233 @@
|
|||
// 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
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ func (q *Queries) DeletePost(ctx context.Context, id int64) error {
|
|||
}
|
||||
|
||||
const getPostWithID = `-- name: GetPostWithID :one
|
||||
SELECT id, site_id, title, body, state, props, post_date, created_at FROM posts WHERE id = $1 LIMIT 1
|
||||
SELECT id, site_id, title, role, body, state, props, publish_date, created_at, updated_at FROM posts WHERE id = $1 LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetPostWithID(ctx context.Context, id int64) (Post, error) {
|
||||
|
|
@ -31,11 +31,13 @@ func (q *Queries) GetPostWithID(ctx context.Context, id int64) (Post, error) {
|
|||
&i.ID,
|
||||
&i.SiteID,
|
||||
&i.Title,
|
||||
&i.Role,
|
||||
&i.Body,
|
||||
&i.State,
|
||||
&i.Props,
|
||||
&i.PostDate,
|
||||
&i.PublishDate,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
|
@ -47,20 +49,22 @@ INSERT INTO posts (
|
|||
body,
|
||||
state,
|
||||
props,
|
||||
post_date,
|
||||
created_at
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
publish_date,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
type InsertPostParams struct {
|
||||
SiteID int64
|
||||
Title pgtype.Text
|
||||
Body string
|
||||
State PostState
|
||||
Props []byte
|
||||
PostDate pgtype.Timestamptz
|
||||
CreatedAt pgtype.Timestamp
|
||||
SiteID int64
|
||||
Title pgtype.Text
|
||||
Body string
|
||||
State PostState
|
||||
Props []byte
|
||||
PublishDate pgtype.Timestamptz
|
||||
CreatedAt pgtype.Timestamp
|
||||
UpdatedAt pgtype.Timestamp
|
||||
}
|
||||
|
||||
func (q *Queries) InsertPost(ctx context.Context, arg InsertPostParams) (int64, error) {
|
||||
|
|
@ -70,8 +74,9 @@ func (q *Queries) InsertPost(ctx context.Context, arg InsertPostParams) (int64,
|
|||
arg.Body,
|
||||
arg.State,
|
||||
arg.Props,
|
||||
arg.PostDate,
|
||||
arg.PublishDate,
|
||||
arg.CreatedAt,
|
||||
arg.UpdatedAt,
|
||||
)
|
||||
var id int64
|
||||
err := row.Scan(&id)
|
||||
|
|
@ -79,7 +84,7 @@ func (q *Queries) InsertPost(ctx context.Context, arg InsertPostParams) (int64,
|
|||
}
|
||||
|
||||
const listPosts = `-- name: ListPosts :many
|
||||
SELECT id, site_id, title, body, state, props, post_date, created_at FROM posts WHERE site_id = $1 ORDER BY post_date DESC LIMIT 25
|
||||
SELECT id, site_id, title, role, body, state, props, publish_date, created_at, updated_at FROM posts WHERE site_id = $1 ORDER BY publish_date DESC LIMIT 25
|
||||
`
|
||||
|
||||
func (q *Queries) ListPosts(ctx context.Context, siteID int64) ([]Post, error) {
|
||||
|
|
@ -95,11 +100,13 @@ func (q *Queries) ListPosts(ctx context.Context, siteID int64) ([]Post, error) {
|
|||
&i.ID,
|
||||
&i.SiteID,
|
||||
&i.Title,
|
||||
&i.Role,
|
||||
&i.Body,
|
||||
&i.State,
|
||||
&i.Props,
|
||||
&i.PostDate,
|
||||
&i.PublishDate,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -112,20 +119,20 @@ func (q *Queries) ListPosts(ctx context.Context, siteID int64) ([]Post, error) {
|
|||
}
|
||||
|
||||
const listPublishablePosts = `-- name: ListPublishablePosts :many
|
||||
SELECT id, site_id, title, body, state, props, post_date, created_at
|
||||
SELECT id, site_id, title, role, body, state, props, publish_date, created_at, updated_at
|
||||
FROM posts
|
||||
WHERE id > $1 AND site_id = $2 AND state = 'published' AND post_date <= $3
|
||||
WHERE id > $1 AND site_id = $2 AND state = 'published' AND publish_date <= $3
|
||||
ORDER BY id LIMIT 100
|
||||
`
|
||||
|
||||
type ListPublishablePostsParams struct {
|
||||
ID int64
|
||||
SiteID int64
|
||||
PostDate pgtype.Timestamptz
|
||||
ID int64
|
||||
SiteID int64
|
||||
PublishDate pgtype.Timestamptz
|
||||
}
|
||||
|
||||
func (q *Queries) ListPublishablePosts(ctx context.Context, arg ListPublishablePostsParams) ([]Post, error) {
|
||||
rows, err := q.db.Query(ctx, listPublishablePosts, arg.ID, arg.SiteID, arg.PostDate)
|
||||
rows, err := q.db.Query(ctx, listPublishablePosts, arg.ID, arg.SiteID, arg.PublishDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -137,11 +144,13 @@ func (q *Queries) ListPublishablePosts(ctx context.Context, arg ListPublishableP
|
|||
&i.ID,
|
||||
&i.SiteID,
|
||||
&i.Title,
|
||||
&i.Role,
|
||||
&i.Body,
|
||||
&i.State,
|
||||
&i.Props,
|
||||
&i.PostDate,
|
||||
&i.PublishDate,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -160,19 +169,20 @@ UPDATE posts SET
|
|||
body = $4,
|
||||
state = $5,
|
||||
props = $6,
|
||||
post_date = $7
|
||||
-- updated_at = $7
|
||||
publish_date = $7,
|
||||
updated_at = $8
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
type UpdatePostParams struct {
|
||||
ID int64
|
||||
SiteID int64
|
||||
Title pgtype.Text
|
||||
Body string
|
||||
State PostState
|
||||
Props []byte
|
||||
PostDate pgtype.Timestamptz
|
||||
ID int64
|
||||
SiteID int64
|
||||
Title pgtype.Text
|
||||
Body string
|
||||
State PostState
|
||||
Props []byte
|
||||
PublishDate pgtype.Timestamptz
|
||||
UpdatedAt pgtype.Timestamp
|
||||
}
|
||||
|
||||
func (q *Queries) UpdatePost(ctx context.Context, arg UpdatePostParams) error {
|
||||
|
|
@ -183,7 +193,8 @@ func (q *Queries) UpdatePost(ctx context.Context, arg UpdatePostParams) error {
|
|||
arg.Body,
|
||||
arg.State,
|
||||
arg.Props,
|
||||
arg.PostDate,
|
||||
arg.PublishDate,
|
||||
arg.UpdatedAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue