Added sub commands for doing admin stuff

This commit is contained in:
Leon Mika 2026-02-28 10:39:08 +11:00
parent 329de2f953
commit 4a6b79db17
18 changed files with 531 additions and 185 deletions

View file

@ -21,6 +21,7 @@ type Post struct {
type PublishTarget struct {
ID int64
SiteID int64
Guid string
TargetType string
Enabled int64
BaseUrl string

View file

@ -12,17 +12,19 @@ import (
const insertPublishTarget = `-- name: InsertPublishTarget :one
INSERT INTO publish_targets (
site_id,
guid,
target_type,
enabled,
base_url,
target_ref,
target_key
) VALUES (?, ?, ?, ?, ?, ?)
) VALUES (?, ?, ?, ?, ?, ?, ?)
RETURNING id
`
type InsertPublishTargetParams struct {
SiteID int64
Guid string
TargetType string
Enabled int64
BaseUrl string
@ -33,6 +35,7 @@ type InsertPublishTargetParams struct {
func (q *Queries) InsertPublishTarget(ctx context.Context, arg InsertPublishTargetParams) (int64, error) {
row := q.db.QueryRowContext(ctx, insertPublishTarget,
arg.SiteID,
arg.Guid,
arg.TargetType,
arg.Enabled,
arg.BaseUrl,
@ -45,7 +48,7 @@ func (q *Queries) InsertPublishTarget(ctx context.Context, arg InsertPublishTarg
}
const selectPublishTargetsOfSite = `-- name: SelectPublishTargetsOfSite :many
SELECT id, site_id, target_type, enabled, base_url, target_ref, target_key FROM publish_targets WHERE site_id = ?
SELECT id, site_id, guid, target_type, enabled, base_url, target_ref, target_key FROM publish_targets WHERE site_id = ?
`
func (q *Queries) SelectPublishTargetsOfSite(ctx context.Context, siteID int64) ([]PublishTarget, error) {
@ -60,6 +63,7 @@ func (q *Queries) SelectPublishTargetsOfSite(ctx context.Context, siteID int64)
if err := rows.Scan(
&i.ID,
&i.SiteID,
&i.Guid,
&i.TargetType,
&i.Enabled,
&i.BaseUrl,

View file

@ -53,6 +53,68 @@ func (q *Queries) InsertSite(ctx context.Context, arg InsertSiteParams) (int64,
return id, err
}
const selectAllSitesWithOwners = `-- name: SelectAllSitesWithOwners :many
SELECT s.id, s.guid, s.title, s.owner_id, u.username
FROM sites s
JOIN users u ON s.owner_id = u.id
ORDER BY s.title ASC
`
type SelectAllSitesWithOwnersRow struct {
ID int64
Guid string
Title string
OwnerID int64
Username string
}
func (q *Queries) SelectAllSitesWithOwners(ctx context.Context) ([]SelectAllSitesWithOwnersRow, error) {
rows, err := q.db.QueryContext(ctx, selectAllSitesWithOwners)
if err != nil {
return nil, err
}
defer rows.Close()
var items []SelectAllSitesWithOwnersRow
for rows.Next() {
var i SelectAllSitesWithOwnersRow
if err := rows.Scan(
&i.ID,
&i.Guid,
&i.Title,
&i.OwnerID,
&i.Username,
); 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 selectSiteByGUID = `-- name: SelectSiteByGUID :one
SELECT id, owner_id, guid, title, tagline, created_at FROM sites WHERE guid = ?
`
func (q *Queries) SelectSiteByGUID(ctx context.Context, guid string) (Site, error) {
row := q.db.QueryRowContext(ctx, selectSiteByGUID, guid)
var i Site
err := row.Scan(
&i.ID,
&i.OwnerID,
&i.Guid,
&i.Title,
&i.Tagline,
&i.CreatedAt,
)
return i, err
}
const selectSiteByID = `-- name: SelectSiteByID :one
SELECT id, owner_id, guid, title, tagline, created_at FROM sites WHERE id = ?
`