Files
insertr/internal/db/sqlite/collections.sql.go
Joakim 2315ba4750 Implement complete collection persistence with database-backed survival across server restarts
• Add full multi-table schema for collections with normalized design (collections, collection_templates, collection_items, collection_item_versions)
• Implement collection detection and processing in enhancement pipeline for .insertr-add elements
• Add template extraction and storage from existing HTML children with multi-variant support
• Enable collection reconstruction from database on server restart with proper DOM rebuilding
• Extend ContentClient interface with collection operations and full database integration
• Update enhance command to use engine.DatabaseClient for collection persistence support
2025-09-22 18:29:58 +02:00

200 lines
4.7 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: collections.sql
package sqlite
import (
"context"
)
const createCollection = `-- name: CreateCollection :one
INSERT INTO collections (id, site_id, container_html, last_edited_by)
VALUES (?1, ?2, ?3, ?4)
RETURNING id, site_id, container_html, created_at, updated_at, last_edited_by
`
type CreateCollectionParams struct {
ID string `json:"id"`
SiteID string `json:"site_id"`
ContainerHtml string `json:"container_html"`
LastEditedBy string `json:"last_edited_by"`
}
func (q *Queries) CreateCollection(ctx context.Context, arg CreateCollectionParams) (Collection, error) {
row := q.db.QueryRowContext(ctx, createCollection,
arg.ID,
arg.SiteID,
arg.ContainerHtml,
arg.LastEditedBy,
)
var i Collection
err := row.Scan(
&i.ID,
&i.SiteID,
&i.ContainerHtml,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastEditedBy,
)
return i, err
}
const deleteAllSiteCollections = `-- name: DeleteAllSiteCollections :exec
DELETE FROM collections
WHERE site_id = ?1
`
func (q *Queries) DeleteAllSiteCollections(ctx context.Context, siteID string) error {
_, err := q.db.ExecContext(ctx, deleteAllSiteCollections, siteID)
return err
}
const deleteCollection = `-- name: DeleteCollection :exec
DELETE FROM collections
WHERE id = ?1 AND site_id = ?2
`
type DeleteCollectionParams struct {
ID string `json:"id"`
SiteID string `json:"site_id"`
}
func (q *Queries) DeleteCollection(ctx context.Context, arg DeleteCollectionParams) error {
_, err := q.db.ExecContext(ctx, deleteCollection, arg.ID, arg.SiteID)
return err
}
const getAllCollections = `-- name: GetAllCollections :many
SELECT id, site_id, container_html, created_at, updated_at, last_edited_by
FROM collections
WHERE site_id = ?1
ORDER BY updated_at DESC
`
func (q *Queries) GetAllCollections(ctx context.Context, siteID string) ([]Collection, error) {
rows, err := q.db.QueryContext(ctx, getAllCollections, siteID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Collection
for rows.Next() {
var i Collection
if err := rows.Scan(
&i.ID,
&i.SiteID,
&i.ContainerHtml,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastEditedBy,
); 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 getCollection = `-- name: GetCollection :one
SELECT id, site_id, container_html, created_at, updated_at, last_edited_by
FROM collections
WHERE id = ?1 AND site_id = ?2
`
type GetCollectionParams struct {
ID string `json:"id"`
SiteID string `json:"site_id"`
}
// Collections table queries
func (q *Queries) GetCollection(ctx context.Context, arg GetCollectionParams) (Collection, error) {
row := q.db.QueryRowContext(ctx, getCollection, arg.ID, arg.SiteID)
var i Collection
err := row.Scan(
&i.ID,
&i.SiteID,
&i.ContainerHtml,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastEditedBy,
)
return i, err
}
const updateCollection = `-- name: UpdateCollection :one
UPDATE collections
SET container_html = ?1, last_edited_by = ?2
WHERE id = ?3 AND site_id = ?4
RETURNING id, site_id, container_html, created_at, updated_at, last_edited_by
`
type UpdateCollectionParams struct {
ContainerHtml string `json:"container_html"`
LastEditedBy string `json:"last_edited_by"`
ID string `json:"id"`
SiteID string `json:"site_id"`
}
func (q *Queries) UpdateCollection(ctx context.Context, arg UpdateCollectionParams) (Collection, error) {
row := q.db.QueryRowContext(ctx, updateCollection,
arg.ContainerHtml,
arg.LastEditedBy,
arg.ID,
arg.SiteID,
)
var i Collection
err := row.Scan(
&i.ID,
&i.SiteID,
&i.ContainerHtml,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastEditedBy,
)
return i, err
}
const upsertCollection = `-- name: UpsertCollection :one
INSERT INTO collections (id, site_id, container_html, last_edited_by)
VALUES (?1, ?2, ?3, ?4)
ON CONFLICT(id, site_id) DO UPDATE SET
container_html = EXCLUDED.container_html,
last_edited_by = EXCLUDED.last_edited_by
RETURNING id, site_id, container_html, created_at, updated_at, last_edited_by
`
type UpsertCollectionParams struct {
ID string `json:"id"`
SiteID string `json:"site_id"`
ContainerHtml string `json:"container_html"`
LastEditedBy string `json:"last_edited_by"`
}
func (q *Queries) UpsertCollection(ctx context.Context, arg UpsertCollectionParams) (Collection, error) {
row := q.db.QueryRowContext(ctx, upsertCollection,
arg.ID,
arg.SiteID,
arg.ContainerHtml,
arg.LastEditedBy,
)
var i Collection
err := row.Scan(
&i.ID,
&i.SiteID,
&i.ContainerHtml,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastEditedBy,
)
return i, err
}