feat(pages): add pages table schema and sqlc queries
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
620ab6c6fa
commit
f17597e4b8
|
|
@ -15,6 +15,20 @@ type Category struct {
|
|||
UpdatedAt int64
|
||||
}
|
||||
|
||||
type Page struct {
|
||||
ID int64
|
||||
SiteID int64
|
||||
Guid string
|
||||
Title string
|
||||
Slug string
|
||||
Body string
|
||||
PageType int64
|
||||
ShowInNav int64
|
||||
SortOrder int64
|
||||
CreatedAt int64
|
||||
UpdatedAt int64
|
||||
}
|
||||
|
||||
type PendingUpload struct {
|
||||
ID int64
|
||||
SiteID int64
|
||||
|
|
|
|||
219
providers/db/gen/sqlgen/pages.sql.go
Normal file
219
providers/db/gen/sqlgen/pages.sql.go
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.28.0
|
||||
// source: pages.sql
|
||||
|
||||
package sqlgen
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const deletePage = `-- name: DeletePage :exec
|
||||
DELETE FROM pages WHERE id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) DeletePage(ctx context.Context, id int64) error {
|
||||
_, err := q.db.ExecContext(ctx, deletePage, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const insertPage = `-- name: InsertPage :one
|
||||
INSERT INTO pages (
|
||||
site_id, guid, title, slug, body, page_type, show_in_nav, sort_order, created_at, updated_at
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
type InsertPageParams struct {
|
||||
SiteID int64
|
||||
Guid string
|
||||
Title string
|
||||
Slug string
|
||||
Body string
|
||||
PageType int64
|
||||
ShowInNav int64
|
||||
SortOrder int64
|
||||
CreatedAt int64
|
||||
UpdatedAt int64
|
||||
}
|
||||
|
||||
func (q *Queries) InsertPage(ctx context.Context, arg InsertPageParams) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, insertPage,
|
||||
arg.SiteID,
|
||||
arg.Guid,
|
||||
arg.Title,
|
||||
arg.Slug,
|
||||
arg.Body,
|
||||
arg.PageType,
|
||||
arg.ShowInNav,
|
||||
arg.SortOrder,
|
||||
arg.CreatedAt,
|
||||
arg.UpdatedAt,
|
||||
)
|
||||
var id int64
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const selectPage = `-- name: SelectPage :one
|
||||
SELECT id, site_id, guid, title, slug, body, page_type, show_in_nav, sort_order, created_at, updated_at FROM pages WHERE id = ? LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) SelectPage(ctx context.Context, id int64) (Page, error) {
|
||||
row := q.db.QueryRowContext(ctx, selectPage, id)
|
||||
var i Page
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.SiteID,
|
||||
&i.Guid,
|
||||
&i.Title,
|
||||
&i.Slug,
|
||||
&i.Body,
|
||||
&i.PageType,
|
||||
&i.ShowInNav,
|
||||
&i.SortOrder,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const selectPageByGUID = `-- name: SelectPageByGUID :one
|
||||
SELECT id, site_id, guid, title, slug, body, page_type, show_in_nav, sort_order, created_at, updated_at FROM pages WHERE guid = ? LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) SelectPageByGUID(ctx context.Context, guid string) (Page, error) {
|
||||
row := q.db.QueryRowContext(ctx, selectPageByGUID, guid)
|
||||
var i Page
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.SiteID,
|
||||
&i.Guid,
|
||||
&i.Title,
|
||||
&i.Slug,
|
||||
&i.Body,
|
||||
&i.PageType,
|
||||
&i.ShowInNav,
|
||||
&i.SortOrder,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const selectPageBySlugAndSite = `-- name: SelectPageBySlugAndSite :one
|
||||
SELECT id, site_id, guid, title, slug, body, page_type, show_in_nav, sort_order, created_at, updated_at FROM pages WHERE site_id = ? AND slug = ? LIMIT 1
|
||||
`
|
||||
|
||||
type SelectPageBySlugAndSiteParams struct {
|
||||
SiteID int64
|
||||
Slug string
|
||||
}
|
||||
|
||||
func (q *Queries) SelectPageBySlugAndSite(ctx context.Context, arg SelectPageBySlugAndSiteParams) (Page, error) {
|
||||
row := q.db.QueryRowContext(ctx, selectPageBySlugAndSite, arg.SiteID, arg.Slug)
|
||||
var i Page
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.SiteID,
|
||||
&i.Guid,
|
||||
&i.Title,
|
||||
&i.Slug,
|
||||
&i.Body,
|
||||
&i.PageType,
|
||||
&i.ShowInNav,
|
||||
&i.SortOrder,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const selectPagesOfSite = `-- name: SelectPagesOfSite :many
|
||||
SELECT id, site_id, guid, title, slug, body, page_type, show_in_nav, sort_order, created_at, updated_at FROM pages
|
||||
WHERE site_id = ? ORDER BY sort_order ASC
|
||||
`
|
||||
|
||||
func (q *Queries) SelectPagesOfSite(ctx context.Context, siteID int64) ([]Page, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectPagesOfSite, 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.Guid,
|
||||
&i.Title,
|
||||
&i.Slug,
|
||||
&i.Body,
|
||||
&i.PageType,
|
||||
&i.ShowInNav,
|
||||
&i.SortOrder,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); 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 updatePage = `-- name: UpdatePage :exec
|
||||
UPDATE pages SET
|
||||
title = ?,
|
||||
slug = ?,
|
||||
body = ?,
|
||||
page_type = ?,
|
||||
show_in_nav = ?,
|
||||
updated_at = ?
|
||||
WHERE id = ?
|
||||
`
|
||||
|
||||
type UpdatePageParams struct {
|
||||
Title string
|
||||
Slug string
|
||||
Body string
|
||||
PageType int64
|
||||
ShowInNav int64
|
||||
UpdatedAt int64
|
||||
ID int64
|
||||
}
|
||||
|
||||
func (q *Queries) UpdatePage(ctx context.Context, arg UpdatePageParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updatePage,
|
||||
arg.Title,
|
||||
arg.Slug,
|
||||
arg.Body,
|
||||
arg.PageType,
|
||||
arg.ShowInNav,
|
||||
arg.UpdatedAt,
|
||||
arg.ID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const updatePageSortOrder = `-- name: UpdatePageSortOrder :exec
|
||||
UPDATE pages SET sort_order = ? WHERE id = ?
|
||||
`
|
||||
|
||||
type UpdatePageSortOrderParams struct {
|
||||
SortOrder int64
|
||||
ID int64
|
||||
}
|
||||
|
||||
func (q *Queries) UpdatePageSortOrder(ctx context.Context, arg UpdatePageSortOrderParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updatePageSortOrder, arg.SortOrder, arg.ID)
|
||||
return err
|
||||
}
|
||||
34
sql/queries/pages.sql
Normal file
34
sql/queries/pages.sql
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
-- name: SelectPagesOfSite :many
|
||||
SELECT * FROM pages
|
||||
WHERE site_id = ? ORDER BY sort_order ASC;
|
||||
|
||||
-- name: SelectPage :one
|
||||
SELECT * FROM pages WHERE id = ? LIMIT 1;
|
||||
|
||||
-- name: SelectPageByGUID :one
|
||||
SELECT * FROM pages WHERE guid = ? LIMIT 1;
|
||||
|
||||
-- name: SelectPageBySlugAndSite :one
|
||||
SELECT * FROM pages WHERE site_id = ? AND slug = ? LIMIT 1;
|
||||
|
||||
-- name: InsertPage :one
|
||||
INSERT INTO pages (
|
||||
site_id, guid, title, slug, body, page_type, show_in_nav, sort_order, created_at, updated_at
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
RETURNING id;
|
||||
|
||||
-- name: UpdatePage :exec
|
||||
UPDATE pages SET
|
||||
title = ?,
|
||||
slug = ?,
|
||||
body = ?,
|
||||
page_type = ?,
|
||||
show_in_nav = ?,
|
||||
updated_at = ?
|
||||
WHERE id = ?;
|
||||
|
||||
-- name: UpdatePageSortOrder :exec
|
||||
UPDATE pages SET sort_order = ? WHERE id = ?;
|
||||
|
||||
-- name: DeletePage :exec
|
||||
DELETE FROM pages WHERE id = ?;
|
||||
17
sql/schema/06_pages.up.sql
Normal file
17
sql/schema/06_pages.up.sql
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
CREATE TABLE pages (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
site_id INTEGER NOT NULL,
|
||||
guid TEXT NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
slug TEXT NOT NULL,
|
||||
body TEXT NOT NULL,
|
||||
page_type INTEGER NOT NULL DEFAULT 0,
|
||||
show_in_nav INTEGER NOT NULL DEFAULT 0,
|
||||
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL,
|
||||
FOREIGN KEY (site_id) REFERENCES sites (id) ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX idx_pages_site ON pages (site_id);
|
||||
CREATE UNIQUE INDEX idx_pages_guid ON pages (guid);
|
||||
CREATE UNIQUE INDEX idx_pages_site_slug ON pages (site_id, slug);
|
||||
Loading…
Reference in a new issue