Help us shape the future of Go! Take the 2026 Go Developer Survey

postgres

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 28 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, reporting content.ErrRevisionNotFound or content.ErrTrashed.

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) EmptyTrash added in v0.19.0

func (s *ContentStore) EmptyTrash(ctx context.Context, contentType string, author *uuid.UUID) (int, int, error)

EmptyTrash deletes the type's trash, only the author's when one is named, and counts what it deleted and left.

func (*ContentStore) List added in v0.4.0

List returns the items matching the filter without content, with author names and parent titles, and their total.

func (*ContentStore) PointingAt added in v0.12.0

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

PointingAt returns the published items pointing at the target through the field, and how many there are.

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 item to draft under its original slug when free, and refuses one out of the trash.

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, unless the item is in the trash.

func (*ContentStore) TargetsByIDs added in v0.13.0

func (s *ContentStore) TargetsByIDs(ctx context.Context, ids []uuid.UUID) ([]content.Target, error)

TargetsByIDs returns the published items of active types the identities name.

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, frees its address for reuse and drops its parked words.

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 CronStore added in v0.19.0

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

CronStore keeps the site's cron jobs and their leases in the core schema.

func NewCronStore added in v0.19.0

func NewCronStore(pool *pgxpool.Pool) *CronStore

NewCronStore returns a CronStore backed by pool.

func (*CronStore) Settle added in v0.19.0

func (s *CronStore) Settle(ctx context.Context, lease cron.Lease, outcome cron.Outcome) error

Settle frees the job and records how its run ended, refusing a lease another run took over.

func (*CronStore) Slots added in v0.19.0

func (s *CronStore) Slots(ctx context.Context) ([]cron.Slot, error)

Slots returns where every stored job stands.

func (*CronStore) Take added in v0.19.0

func (s *CronStore) Take(ctx context.Context, lease cron.Lease) (cron.Lease, bool, error)

Take claims the job for the lease when it is due and free, reporting whether it did.

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) ByIDs added in v0.11.0

func (s *MediaStore) ByIDs(ctx context.Context, ids []int64) ([]media.Media, error)

ByIDs returns the media items stored under the identities, leaving out any that are gone.

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.Listed, int, error)

List returns the media items the filter matches, sorted as it names, beside their authors' names, with their total.

func (*MediaStore) Saved added in v0.18.0

func (s *MediaStore) Saved(ctx context.Context, files []string) (map[string]bool, error)

Saved reports which of the files a stored item holds as its own file.

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 {
	*typestore.Store
}

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.

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