Documentation
¶
Overview ¶
Package contentstore runs the content store's steps over the statements any database engine lends it.
Index ¶
- type AuthorCount
- type Backend
- type ContentRow
- type DefinitionQueries
- type ItemQueries
- type ListQueries
- type ListedRow
- type LockQueries
- type Narrowing
- type Page
- type ParentRow
- type Pointing
- type Queries
- type RelationQueries
- type RelationRow
- type RevisionQueries
- type RevisionRow
- type SiblingSlug
- type Store
- func (s *Store) Autosave(ctx context.Context, contentID, authorID uuid.UUID) (content.Revision, error)
- func (s *Store) ByID(ctx context.Context, id uuid.UUID) (content.Content, error)
- func (s *Store) Children(ctx context.Context, id uuid.UUID) (int, error)
- func (s *Store) CountsByAuthor(ctx context.Context, contentType string) (map[uuid.UUID]int, error)
- func (s *Store) Create(ctx context.Context, c content.Content) (content.Content, error)
- func (s *Store) Delete(ctx context.Context, id uuid.UUID) error
- func (s *Store) DeleteAutosave(ctx context.Context, contentID, authorID uuid.UUID) error
- func (s *Store) DeleteRevision(ctx context.Context, contentID, revisionID uuid.UUID) error
- func (s *Store) Depth(ctx context.Context, id uuid.UUID) (int, error)
- func (s *Store) EmptyTrash(ctx context.Context, contentType string, author *uuid.UUID) (int, int, error)
- func (s *Store) List(ctx context.Context, f content.Filter) ([]content.ListedItem, int, error)
- func (s *Store) PointingAt(ctx context.Context, target uuid.UUID, field, page, perPage int) ([]content.Pointer, int, error)
- func (s *Store) PublishedByPath(ctx context.Context, path string) (content.Content, error)
- func (s *Store) RelatedTo(ctx context.Context, target uuid.UUID, page, perPage int) ([]content.Content, int, error)
- func (s *Store) Restore(ctx context.Context, id uuid.UUID, updatedAt time.Time) (content.Content, error)
- func (s *Store) RevisionByID(ctx context.Context, contentID, revisionID uuid.UUID) (content.Revision, error)
- func (s *Store) Revisions(ctx context.Context, contentID uuid.UUID) ([]content.Revision, error)
- func (s *Store) SaveAutosave(ctx context.Context, autosave content.Revision) (content.Revision, error)
- func (s *Store) TargetsByIDs(ctx context.Context, ids []uuid.UUID) ([]content.Target, error)
- func (s *Store) Trash(ctx context.Context, id uuid.UUID, updatedAt time.Time) (content.Content, error)
- func (s *Store) Update(ctx context.Context, c content.Content, expectedUpdatedAt time.Time, ...) (content.Content, error)
- type Transactor
- type Tx
- type TypedItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthorCount ¶
AuthorCount is how many listed items one author wrote.
type Backend ¶
type Backend struct {
Engine dbkit.Engine
Pool Queries
InTx Transactor
Rules []typestore.Rule
ReadError func(err error) (typestore.Failure, bool)
}
Backend holds what one database engine lends the content store.
type ContentRow ¶
type ContentRow struct {
ID, AuthorID uuid.UUID
ParentID *uuid.UUID
Type, Status, Slug, Title, Content, Excerpt, Path string
Fields content.Values
PublishedAt *time.Time
CreatedAt, UpdatedAt time.Time
}
ContentRow is one stored content item as every engine reads and writes it.
type DefinitionQueries ¶
type DefinitionQueries interface {
ListFieldGroups(ctx context.Context) ([]typestore.GroupRow, error)
ListContentFields(ctx context.Context) ([]typestore.FieldRow, error)
}
DefinitionQueries sends the field definition reads a content write checks its values against.
type ItemQueries ¶
type ItemQueries interface {
CreateContent(ctx context.Context, c ContentRow) (ContentRow, error)
GetContent(ctx context.Context, id uuid.UUID) (ContentRow, error)
GetPublishedContentByPath(ctx context.Context, path string) (ContentRow, error)
UpdateContent(ctx context.Context, c ContentRow, expected time.Time) (ContentRow, error)
SiblingSlugTaken(ctx context.Context, s SiblingSlug) (bool, error)
CountChildren(ctx context.Context, id uuid.UUID) (int64, error)
ContentDepth(ctx context.Context, id uuid.UUID) (int64, error)
ValuesOfContent(ctx context.Context, id uuid.UUID) (content.Values, error)
TrashContent(ctx context.Context, id uuid.UUID, suffix string, at time.Time) (ContentRow, error)
RestoreContent(ctx context.Context, id uuid.UUID, at time.Time) (ContentRow, error)
RestoreContentKeepingSlug(ctx context.Context, id uuid.UUID, at time.Time) (ContentRow, error)
DeleteContent(ctx context.Context, id uuid.UUID) (int64, error)
DeleteTrash(ctx context.Context, typeKey string, author *uuid.UUID) (int64, error)
CountTrash(ctx context.Context, typeKey string) (int64, error)
CountContentByAuthor(ctx context.Context, typeKey string) ([]AuthorCount, error)
}
ItemQueries sends the statements that read and write one content item.
type ListQueries ¶
type ListQueries interface {
CountContent(ctx context.Context, n Narrowing) (int64, error)
ListContent(ctx context.Context, p Page) ([]ListedRow, error)
ListNestedContent(ctx context.Context, p Page) ([]ListedRow, error)
}
ListQueries sends the statements that count and page a narrowed listing.
type ListedRow ¶
type ListedRow struct {
ContentRow
AuthorName, ParentTitle string
}
ListedRow is one listed item beside its author's name and its parent's title.
type LockQueries ¶
type LockQueries interface {
LockContent(ctx context.Context, id uuid.UUID) (ContentRow, error)
LockTypeNesting(ctx context.Context, typeKey string) (bool, error)
LockTypeForMove(ctx context.Context, typeKey string) (bool, error)
LockAncestors(ctx context.Context, id uuid.UUID) error
LockParent(ctx context.Context, id, child uuid.UUID) (ParentRow, error)
LockDescendants(ctx context.Context, id uuid.UUID) error
MoveDescendants(ctx context.Context, id uuid.UUID, path string, at time.Time) ([]string, error)
LockDeclaredFieldKeys(ctx context.Context) ([]string, error)
DeferAddressCheck(ctx context.Context) error
}
LockQueries sends the statements that hold rows, walk the tree and settle addresses.
type Narrowing ¶
type Narrowing struct {
Type, Search string
FieldFilter []byte
Statuses []string
Authors, ExcludedAuthors []uuid.UUID
Before, After *time.Time
}
Narrowing holds what the list and count statements narrow by, its field terms already encoded as JSON.
type ParentRow ¶
ParentRow is the parent an item files under, and whether the item already stands above it.
type Queries ¶
type Queries interface {
ItemQueries
ListQueries
LockQueries
RevisionQueries
RelationQueries
DefinitionQueries
}
Queries sends every statement the content store is built from, one call per statement.
type RelationQueries ¶
type RelationQueries interface {
TypesOfContent(ctx context.Context, ids []uuid.UUID) ([]TypedItem, error)
ClearRelationsOfField(ctx context.Context, from uuid.UUID, fieldID int) error
AddRelation(ctx context.Context, r RelationRow) error
RefreshRelationVisibility(ctx context.Context, id uuid.UUID) error
CountRelatedContent(ctx context.Context, target uuid.UUID) (int64, error)
ListRelatedContent(ctx context.Context, target uuid.UUID, limit, offset int) ([]ContentRow, error)
CountPointingAt(ctx context.Context, target uuid.UUID, fieldID int) (int64, error)
PointingAt(ctx context.Context, p Pointing) ([]content.Pointer, error)
SummariesOfTargets(ctx context.Context, ids []uuid.UUID) ([]content.Target, error)
}
RelationQueries sends the statements that check, index and read what relation fields point at.
type RelationRow ¶
RelationRow is one row of the index a relation field writes.
type RevisionQueries ¶
type RevisionQueries interface {
CreateRevision(ctx context.Context, r RevisionRow) error
ListRevisions(ctx context.Context, contentID uuid.UUID) ([]RevisionRow, error)
GetRevision(ctx context.Context, contentID, id uuid.UUID) (RevisionRow, error)
DeleteRevision(ctx context.Context, contentID, id uuid.UUID) (int64, error)
PruneRevisions(ctx context.Context, contentID uuid.UUID, keep int) error
UpsertAutosave(ctx context.Context, r RevisionRow) (RevisionRow, error)
GetAutosave(ctx context.Context, contentID, authorID uuid.UUID) (RevisionRow, error)
DeleteAutosave(ctx context.Context, contentID, authorID uuid.UUID) error
DeleteAutosavesOfContent(ctx context.Context, contentID uuid.UUID) error
}
RevisionQueries sends the statements that read and write revisions and autosaves.
type RevisionRow ¶
type RevisionRow struct {
ID, ContentID, AuthorID uuid.UUID
Kind, Title, Content, Excerpt string
Fields content.Values
CreatedAt time.Time
}
RevisionRow is one stored revision or autosave.
type SiblingSlug ¶
SiblingSlug names the slug an item would carry beside its siblings.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store keeps content items, their revisions and their relations through one backend.
func (*Store) Autosave ¶
func (s *Store) Autosave(ctx context.Context, contentID, authorID uuid.UUID) (content.Revision, error)
Autosave returns the author's autosave of the item, or content.ErrRevisionNotFound.
func (*Store) ByID ¶
ByID returns the content item with the given id, or content.ErrNotFound.
func (*Store) CountsByAuthor ¶
CountsByAuthor returns how many published and private items of the type each author wrote.
func (*Store) Create ¶
Create stores a new content item, suffixing its slug until its address is free.
func (*Store) Delete ¶
Delete removes the content item, or reports content.ErrNotFound.
func (*Store) DeleteAutosave ¶
DeleteAutosave removes the author's autosave of the item.
func (*Store) DeleteRevision ¶
DeleteRevision removes the item's revision, reporting content.ErrRevisionNotFound or content.ErrTrashed.
func (*Store) EmptyTrash ¶
func (s *Store) 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 (*Store) List ¶
List returns the items matching the filter without content, with author names and parent titles, and their total.
func (*Store) PointingAt ¶
func (s *Store) 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 (*Store) PublishedByPath ¶
PublishedByPath returns the published item at the address, or content.ErrNotFound.
func (*Store) RelatedTo ¶
func (s *Store) 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 (*Store) Restore ¶
func (s *Store) 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 (*Store) RevisionByID ¶
func (s *Store) RevisionByID(ctx context.Context, contentID, revisionID uuid.UUID) (content.Revision, error)
RevisionByID returns the item's revision, or content.ErrRevisionNotFound.
func (*Store) Revisions ¶
Revisions returns the item's revisions newest first, without their content.
func (*Store) SaveAutosave ¶
func (s *Store) 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 (*Store) TargetsByIDs ¶
TargetsByIDs returns the published items of active types the identities name.
type Transactor ¶
Transactor runs write on one transaction, committing when write returns nil.