postgres

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package postgres provides the PostgreSQL data layer for the CMS core.

Index

Constants

This section is empty.

Variables

View Source
var Migrations embed.FS

Migrations holds the core schema migration files applied by goose.

Functions

func Migrate

func Migrate(ctx context.Context, databaseURL string) error

Migrate applies the core schema migrations to the database at databaseURL.

Types

type ContentStore added in v0.4.0

type ContentStore struct {
	// contains filtered or unexported fields
}

ContentStore persists content items in the core schema.

func NewContentStore added in v0.4.0

func NewContentStore(pool *pgxpool.Pool) *ContentStore

NewContentStore returns a ContentStore backed by pool.

func (*ContentStore) Autosave added in v0.4.0

func (s *ContentStore) Autosave(ctx context.Context, contentID, authorID uuid.UUID) (content.Revision, error)

Autosave returns the author's autosave of the item, or content.ErrRevisionNotFound.

func (*ContentStore) ByID added in v0.4.0

func (s *ContentStore) ByID(ctx context.Context, id uuid.UUID) (content.Content, error)

ByID returns the content item with the given id, or content.ErrNotFound.

func (*ContentStore) Children added in v0.4.0

func (s *ContentStore) Children(ctx context.Context, id uuid.UUID) (int, error)

Children returns how many items nest directly under the item.

func (*ContentStore) Counts added in v0.4.0

func (s *ContentStore) Counts(ctx context.Context, contentType string) (map[content.Status]int, error)

Counts returns the number of items of the type in each status.

func (*ContentStore) Create added in v0.4.0

Create stores a new content item, suffixing its slug until its address is free.

func (*ContentStore) Delete added in v0.4.0

func (s *ContentStore) Delete(ctx context.Context, id uuid.UUID) error

Delete removes the content item, or reports content.ErrNotFound.

func (*ContentStore) DeleteAutosave added in v0.4.0

func (s *ContentStore) DeleteAutosave(ctx context.Context, contentID, authorID uuid.UUID) error

DeleteAutosave removes the author's autosave of the item.

func (*ContentStore) DeleteRevision added in v0.4.0

func (s *ContentStore) DeleteRevision(ctx context.Context, contentID, revisionID uuid.UUID) error

DeleteRevision removes the item's revision, or reports content.ErrRevisionNotFound.

func (*ContentStore) Depth added in v0.4.0

func (s *ContentStore) Depth(ctx context.Context, id uuid.UUID) (int, error)

Depth returns how many levels of content nest below the item.

func (*ContentStore) List added in v0.4.0

List returns the items matching the filter without their content, and the total number matching it.

func (*ContentStore) PublishedByPath added in v0.4.0

func (s *ContentStore) PublishedByPath(ctx context.Context, path string) (content.Content, error)

PublishedByPath returns the published item at the address, or content.ErrNotFound.

func (*ContentStore) RelatedTo added in v0.5.0

func (s *ContentStore) RelatedTo(
	ctx context.Context, target uuid.UUID, page, perPage int,
) ([]content.Content, int, error)

RelatedTo returns the published content of active types pointing at the target, newest first.

func (*ContentStore) Restore added in v0.4.0

func (s *ContentStore) Restore(ctx context.Context, id uuid.UUID, updatedAt time.Time) (content.Content, error)

Restore returns a trashed content item to draft. It recovers the original slug, or leaves the trashed one in place when the original is taken.

func (*ContentStore) RevisionByID added in v0.4.0

func (s *ContentStore) RevisionByID(ctx context.Context, contentID, revisionID uuid.UUID) (content.Revision, error)

RevisionByID returns the item's revision, or content.ErrRevisionNotFound.

func (*ContentStore) Revisions added in v0.4.0

func (s *ContentStore) Revisions(ctx context.Context, contentID uuid.UUID) ([]content.Revision, error)

Revisions returns the item's revisions newest first, without their content.

func (*ContentStore) SaveAutosave added in v0.4.0

func (s *ContentStore) SaveAutosave(ctx context.Context, autosave content.Revision) (content.Revision, error)

SaveAutosave stores the author's autosave of the item, replacing any earlier one.

func (*ContentStore) TargetsOf added in v0.5.0

func (s *ContentStore) TargetsOf(ctx context.Context, from uuid.UUID) (content.Targets, error)

TargetsOf returns the published targets of active types the item points at, keyed by field key.

func (*ContentStore) Trash added in v0.4.0

func (s *ContentStore) Trash(ctx context.Context, id uuid.UUID, updatedAt time.Time) (content.Content, error)

Trash marks the content item trashed and frees its address for reuse.

func (*ContentStore) Update added in v0.4.0

func (s *ContentStore) Update(
	ctx context.Context, c content.Content, expectedUpdatedAt time.Time, snapshot *content.Revision,
	revisionCap int,
) (content.Content, error)

Update stores the item's editable fields and any snapshot, settling its address among its siblings.

type MediaStore added in v0.3.0

type MediaStore struct {
	// contains filtered or unexported fields
}

MediaStore persists the media library in the core schema.

func NewMediaStore added in v0.3.0

func NewMediaStore(pool *pgxpool.Pool) *MediaStore

NewMediaStore returns a MediaStore backed by pool.

func (*MediaStore) ByID added in v0.3.0

func (s *MediaStore) ByID(ctx context.Context, id int64) (media.Media, error)

ByID returns the media item with the given id, or media.ErrNotFound.

func (*MediaStore) Create added in v0.3.0

func (s *MediaStore) Create(ctx context.Context, m media.Media) (media.Media, error)

Create stores a new media item and returns it with its assigned identifier.

func (*MediaStore) Delete added in v0.3.0

func (s *MediaStore) Delete(ctx context.Context, id int64) (media.Media, error)

Delete removes the media item and returns it, or reports media.ErrNotFound.

func (*MediaStore) List added in v0.3.0

func (s *MediaStore) List(ctx context.Context, f media.Filter) ([]media.Media, int, error)

List returns the media items matching the filter, newest first, and the total number matching it.

func (*MediaStore) Update added in v0.3.0

func (s *MediaStore) Update(ctx context.Context, m media.Media, expectedUpdatedAt time.Time) (media.Media, error)

Update stores the media item's descriptions, or reports a missing item or a stale edit.

type SettingStore added in v0.2.0

type SettingStore struct {
	// contains filtered or unexported fields
}

SettingStore persists named values in the core schema.

func NewSettingStore added in v0.2.0

func NewSettingStore(pool *pgxpool.Pool) *SettingStore

NewSettingStore returns a SettingStore backed by pool.

func (*SettingStore) Lookup added in v0.2.0

func (s *SettingStore) Lookup(ctx context.Context, key string) (string, bool, error)

Lookup returns the value stored under key and whether the key is set at all.

func (*SettingStore) Save added in v0.2.0

func (s *SettingStore) Save(ctx context.Context, values map[string]string) error

Save stores every given value, or stores none of them.

type TypeStore added in v0.4.0

type TypeStore struct {
	// contains filtered or unexported fields
}

TypeStore persists the content type registry in the core schema.

func NewTypeStore added in v0.4.0

func NewTypeStore(pool *pgxpool.Pool) *TypeStore

NewTypeStore returns a TypeStore backed by pool.

func (*TypeStore) ByKey added in v0.4.0

func (s *TypeStore) ByKey(ctx context.Context, key string) (content.Type, error)

ByKey returns the type carrying the key with its fields, or content.ErrTypeNotFound.

func (*TypeStore) Create added in v0.4.0

func (s *TypeStore) Create(ctx context.Context, t content.Type) (content.Type, error)

Create stores a new content type, or reports the key or route word already in use.

func (*TypeStore) CreateField added in v0.5.0

func (s *TypeStore) CreateField(ctx context.Context, f content.Field) (content.Field, error)

CreateField declares the field on its type, or reports why the schema refused it.

func (*TypeStore) Delete added in v0.4.0

func (s *TypeStore) Delete(ctx context.Context, key string) error

Delete removes the type, or reports it missing or still in use.

func (*TypeStore) DeleteField added in v0.5.0

func (s *TypeStore) DeleteField(ctx context.Context, typeKey, key string) error

DeleteField removes the definition and sweeps its values in one transaction.

func (*TypeStore) List added in v0.4.0

func (s *TypeStore) List(ctx context.Context) ([]content.Type, error)

List returns every registered type in registration order with its fields attached.

func (*TypeStore) Update added in v0.4.0

func (s *TypeStore) Update(ctx context.Context, t content.Type) (content.Type, error)

Update stores the type's editable fields and carries its content to the route word, or reports content.ErrTypeNotFound.

func (*TypeStore) UpdateField added in v0.5.0

func (s *TypeStore) UpdateField(ctx context.Context, f content.Field) (content.Field, error)

UpdateField stores the field's label and required flag, or reports it missing.

type UserSettingStore added in v0.6.0

type UserSettingStore struct {
	// contains filtered or unexported fields
}

UserSettingStore persists one reader's own preferences in the core schema.

func NewUserSettingStore added in v0.6.0

func NewUserSettingStore(pool *pgxpool.Pool) *UserSettingStore

NewUserSettingStore returns a UserSettingStore backed by pool.

func (*UserSettingStore) Lookup added in v0.6.0

func (s *UserSettingStore) Lookup(
	ctx context.Context, userID uuid.UUID, key string,
) (string, bool, error)

Lookup returns the value the reader stored under key, and whether it is set at all.

func (*UserSettingStore) Save added in v0.6.0

func (s *UserSettingStore) Save(ctx context.Context, userID uuid.UUID, key, value string) error

Save stores the value under the reader's key.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL