Did some restyling
This commit is contained in:
parent
d1e212d5e0
commit
2411e64a53
13 changed files with 172 additions and 45 deletions
|
|
@ -95,6 +95,47 @@ func (ns NullPageRole) Value() (driver.Value, error) {
|
|||
return string(ns.PageRole), nil
|
||||
}
|
||||
|
||||
type PostFormat string
|
||||
|
||||
const (
|
||||
PostFormatMarkdown PostFormat = "markdown"
|
||||
)
|
||||
|
||||
func (e *PostFormat) Scan(src interface{}) error {
|
||||
switch s := src.(type) {
|
||||
case []byte:
|
||||
*e = PostFormat(s)
|
||||
case string:
|
||||
*e = PostFormat(s)
|
||||
default:
|
||||
return fmt.Errorf("unsupported scan type for PostFormat: %T", src)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type NullPostFormat struct {
|
||||
PostFormat PostFormat
|
||||
Valid bool // Valid is true if PostFormat is not NULL
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (ns *NullPostFormat) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
ns.PostFormat, ns.Valid = "", false
|
||||
return nil
|
||||
}
|
||||
ns.Valid = true
|
||||
return ns.PostFormat.Scan(value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (ns NullPostFormat) Value() (driver.Value, error) {
|
||||
if !ns.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return string(ns.PostFormat), nil
|
||||
}
|
||||
|
||||
type PostState string
|
||||
|
||||
const (
|
||||
|
|
@ -233,6 +274,7 @@ type Page struct {
|
|||
BundleID int64
|
||||
Name string
|
||||
NameProvenance PageNameProvenance
|
||||
Format PostFormat
|
||||
Title pgtype.Text
|
||||
PostTypeID pgtype.Int8
|
||||
Body string
|
||||
|
|
@ -249,6 +291,7 @@ type Post struct {
|
|||
SiteID int64
|
||||
Title pgtype.Text
|
||||
PostTypeID pgtype.Int8
|
||||
Format PostFormat
|
||||
Body string
|
||||
State PostState
|
||||
Props []byte
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ func (q *Queries) DeletePageWithID(ctx context.Context, id int64) error {
|
|||
}
|
||||
|
||||
const getPageWithID = `-- name: GetPageWithID :one
|
||||
SELECT id, site_id, bundle_id, name, name_provenance, title, post_type_id, body, state, props, role, publish_date, created_at, updated_at FROM pages WHERE id = $1
|
||||
SELECT id, site_id, bundle_id, name, name_provenance, format, title, post_type_id, body, state, props, role, publish_date, created_at, updated_at FROM pages WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetPageWithID(ctx context.Context, id int64) (Page, error) {
|
||||
|
|
@ -33,6 +33,7 @@ func (q *Queries) GetPageWithID(ctx context.Context, id int64) (Page, error) {
|
|||
&i.BundleID,
|
||||
&i.Name,
|
||||
&i.NameProvenance,
|
||||
&i.Format,
|
||||
&i.Title,
|
||||
&i.PostTypeID,
|
||||
&i.Body,
|
||||
|
|
@ -101,7 +102,7 @@ func (q *Queries) InsertPage(ctx context.Context, arg InsertPageParams) (int64,
|
|||
}
|
||||
|
||||
const listPages = `-- name: ListPages :many
|
||||
SELECT id, site_id, bundle_id, name, name_provenance, title, post_type_id, body, state, props, role, publish_date, created_at, updated_at FROM pages WHERE site_id = $1 ORDER BY name ASC LIMIT 25
|
||||
SELECT id, site_id, bundle_id, name, name_provenance, format, title, post_type_id, body, state, props, role, 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) {
|
||||
|
|
@ -119,6 +120,7 @@ func (q *Queries) ListPages(ctx context.Context, siteID int64) ([]Page, error) {
|
|||
&i.BundleID,
|
||||
&i.Name,
|
||||
&i.NameProvenance,
|
||||
&i.Format,
|
||||
&i.Title,
|
||||
&i.PostTypeID,
|
||||
&i.Body,
|
||||
|
|
@ -140,7 +142,7 @@ func (q *Queries) ListPages(ctx context.Context, siteID int64) ([]Page, error) {
|
|||
}
|
||||
|
||||
const listPublishablePages = `-- name: ListPublishablePages :many
|
||||
SELECT id, site_id, bundle_id, name, name_provenance, title, post_type_id, body, state, props, role, publish_date, created_at, updated_at
|
||||
SELECT id, site_id, bundle_id, name, name_provenance, format, title, post_type_id, body, state, props, role, publish_date, created_at, updated_at
|
||||
FROM pages
|
||||
WHERE id > $1 AND site_id = $2 AND state = 'published'
|
||||
ORDER BY id LIMIT 100
|
||||
|
|
@ -166,6 +168,7 @@ func (q *Queries) ListPublishablePages(ctx context.Context, arg ListPublishableP
|
|||
&i.BundleID,
|
||||
&i.Name,
|
||||
&i.NameProvenance,
|
||||
&i.Format,
|
||||
&i.Title,
|
||||
&i.PostTypeID,
|
||||
&i.Body,
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ func (q *Queries) DeletePost(ctx context.Context, id int64) error {
|
|||
}
|
||||
|
||||
const getPostWithID = `-- name: GetPostWithID :one
|
||||
SELECT id, site_id, title, post_type_id, body, state, props, publish_date, created_at, updated_at FROM posts WHERE id = $1 LIMIT 1
|
||||
SELECT id, site_id, title, post_type_id, format, 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) {
|
||||
|
|
@ -32,6 +32,7 @@ func (q *Queries) GetPostWithID(ctx context.Context, id int64) (Post, error) {
|
|||
&i.SiteID,
|
||||
&i.Title,
|
||||
&i.PostTypeID,
|
||||
&i.Format,
|
||||
&i.Body,
|
||||
&i.State,
|
||||
&i.Props,
|
||||
|
|
@ -84,7 +85,7 @@ func (q *Queries) InsertPost(ctx context.Context, arg InsertPostParams) (int64,
|
|||
}
|
||||
|
||||
const listPosts = `-- name: ListPosts :many
|
||||
SELECT id, site_id, title, post_type_id, body, state, props, publish_date, created_at, updated_at FROM posts WHERE site_id = $1 ORDER BY publish_date DESC LIMIT 25
|
||||
SELECT id, site_id, title, post_type_id, format, 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) {
|
||||
|
|
@ -101,6 +102,7 @@ func (q *Queries) ListPosts(ctx context.Context, siteID int64) ([]Post, error) {
|
|||
&i.SiteID,
|
||||
&i.Title,
|
||||
&i.PostTypeID,
|
||||
&i.Format,
|
||||
&i.Body,
|
||||
&i.State,
|
||||
&i.Props,
|
||||
|
|
@ -119,7 +121,7 @@ func (q *Queries) ListPosts(ctx context.Context, siteID int64) ([]Post, error) {
|
|||
}
|
||||
|
||||
const listPublishablePosts = `-- name: ListPublishablePosts :many
|
||||
SELECT id, site_id, title, post_type_id, body, state, props, publish_date, created_at, updated_at
|
||||
SELECT id, site_id, title, post_type_id, format, body, state, props, publish_date, created_at, updated_at
|
||||
FROM posts
|
||||
WHERE id > $1 AND site_id = $2 AND state = 'published' AND publish_date <= $3
|
||||
ORDER BY id LIMIT 100
|
||||
|
|
@ -145,6 +147,7 @@ func (q *Queries) ListPublishablePosts(ctx context.Context, arg ListPublishableP
|
|||
&i.SiteID,
|
||||
&i.Title,
|
||||
&i.PostTypeID,
|
||||
&i.Format,
|
||||
&i.Body,
|
||||
&i.State,
|
||||
&i.Props,
|
||||
|
|
|
|||
|
|
@ -27,22 +27,35 @@ func (q *Queries) GetSiteWithID(ctx context.Context, id int64) (Site, error) {
|
|||
return i, err
|
||||
}
|
||||
|
||||
const listSites = `-- name: ListSites :one
|
||||
const listSites = `-- name: ListSites :many
|
||||
SELECT id, owner_user_id, name, title, theme, props FROM sites
|
||||
`
|
||||
|
||||
func (q *Queries) ListSites(ctx context.Context) (Site, error) {
|
||||
row := q.db.QueryRow(ctx, listSites)
|
||||
var i Site
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerUserID,
|
||||
&i.Name,
|
||||
&i.Title,
|
||||
&i.Theme,
|
||||
&i.Props,
|
||||
)
|
||||
return i, err
|
||||
func (q *Queries) ListSites(ctx context.Context) ([]Site, error) {
|
||||
rows, err := q.db.Query(ctx, listSites)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Site
|
||||
for rows.Next() {
|
||||
var i Site
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerUserID,
|
||||
&i.Name,
|
||||
&i.Title,
|
||||
&i.Theme,
|
||||
&i.Props,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const newSite = `-- name: NewSite :one
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue