Documentation ¶
Overview ¶
Package thing provides an example demonstrating a way of using the versionary package. It includes a simple struct, Thing, and a few methods that operate on it. It also includes a Table and a Service that can be used to manage Things.
Index ¶
- func NewMemTable(table v.Table[Thing]) v.MemTable[Thing]
- func NewTable(dbClient *dynamodb.Client, env string) v.Table[Thing]
- type Service
- func (s Service) CountThings(ctx context.Context) (int64, error)
- func (s Service) Create(ctx context.Context, t Thing) (Thing, []string, error)
- func (s Service) Delete(ctx context.Context, id string) (Thing, error)
- func (s Service) DeleteVersion(ctx context.Context, id, versionID string) (Thing, error)
- func (s Service) Exists(ctx context.Context, id string) bool
- func (s Service) FilterMessagesByTag(ctx context.Context, tag string, contains string, anyMatch bool) ([]v.TextValue, error)
- func (s Service) FilterThingMessages(ctx context.Context, contains string, anyMatch bool) ([]v.TextValue, error)
- func (s Service) Read(ctx context.Context, id string) (Thing, error)
- func (s Service) ReadAllCountsByTag(ctx context.Context, tag string, sortByValue bool) ([]v.NumValue, error)
- func (s Service) ReadAllDates(ctx context.Context) ([]string, error)
- func (s Service) ReadAllMessagesByTag(ctx context.Context, tag string, sortByValue bool) ([]v.TextValue, error)
- func (s Service) ReadAllTags(ctx context.Context) ([]string, error)
- func (s Service) ReadAllThingIDs(ctx context.Context) ([]string, error)
- func (s Service) ReadAllThingMessages(ctx context.Context, sortByValue bool) ([]v.TextValue, error)
- func (s Service) ReadAllThingsByDate(ctx context.Context, day string) ([]Thing, error)
- func (s Service) ReadAllThingsByDateAsJSON(ctx context.Context, day string) ([]byte, error)
- func (s Service) ReadAllThingsByTag(ctx context.Context, tag string) ([]Thing, error)
- func (s Service) ReadAllThingsByTagAsJSON(ctx context.Context, tag string) ([]byte, error)
- func (s Service) ReadAllVersions(ctx context.Context, id string) ([]Thing, error)
- func (s Service) ReadAllVersionsAsJSON(ctx context.Context, id string) ([]byte, error)
- func (s Service) ReadAsJSON(ctx context.Context, id string) ([]byte, error)
- func (s Service) ReadCountsByTag(ctx context.Context, tag string, reverse bool, limit int, offset string) ([]v.NumValue, error)
- func (s Service) ReadDates(ctx context.Context, reverse bool, limit int, offset string) ([]string, error)
- func (s Service) ReadMessageRangeByTag(ctx context.Context, tag string, from, to string, reverse bool) ([]v.TextValue, error)
- func (s Service) ReadMessagesByTag(ctx context.Context, tag string, reverse bool, limit int, offset string) ([]v.TextValue, error)
- func (s Service) ReadTags(ctx context.Context, reverse bool, limit int, offset string) ([]string, error)
- func (s Service) ReadThingIDs(ctx context.Context, reverse bool, limit int, offset string) ([]string, error)
- func (s Service) ReadThingMessageRange(ctx context.Context, from, to string, reverse bool) ([]v.TextValue, error)
- func (s Service) ReadThingMessages(ctx context.Context, reverse bool, limit int, offset string) ([]v.TextValue, error)
- func (s Service) ReadThingsByDate(ctx context.Context, day string, reverse bool, limit int, offset string) ([]Thing, error)
- func (s Service) ReadThingsByDateAsJSON(ctx context.Context, day string, reverse bool, limit int, offset string) ([]byte, error)
- func (s Service) ReadThingsByTag(ctx context.Context, tag string, reverse bool, limit int, offset string) ([]Thing, error)
- func (s Service) ReadThingsByTagAsJSON(ctx context.Context, tag string, reverse bool, limit int, offset string) ([]byte, error)
- func (s Service) ReadVersion(ctx context.Context, id, versionID string) (Thing, error)
- func (s Service) ReadVersionAsJSON(ctx context.Context, id, versionID string) ([]byte, error)
- func (s Service) ReadVersions(ctx context.Context, id string, reverse bool, limit int, offset string) ([]Thing, error)
- func (s Service) ReadVersionsAsJSON(ctx context.Context, id string, reverse bool, limit int, offset string) ([]byte, error)
- func (s Service) SumCountsByTag(ctx context.Context, tag string) (float64, error)
- func (s Service) Update(ctx context.Context, t Thing) (Thing, []string, error)
- func (s Service) VersionExists(ctx context.Context, id, versionID string) bool
- type Thing
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMemTable ¶
NewMemTable creates an in-memory Thing table for testing purposes.
Types ¶
type Service ¶
type Service struct { EntityType string Table v.TableReadWriter[Thing] }
Service is used to manage a Thing database.
func NewMemService ¶
NewMemService returns a new Thing Service backed by an in-memory table for testing.
func NewService ¶
NewService returns a new Thing Service for the specified operating environment.
func (Service) CountThings ¶
CountThings returns the number of Things in the Thing table.
func (Service) DeleteVersion ¶
Delete a Thing version from the Thing table. The deleted Thing is returned.
func (Service) FilterMessagesByTag ¶
func (s Service) FilterMessagesByTag(ctx context.Context, tag string, contains string, anyMatch bool) ([]v.TextValue, error)
FilterMessagesByTag returns a filtered list of Thing IDs and messages for a specified tag. The case-insensitive contains query is split into words, and the words are compared with the value in the TextValue. If anyMatch is true, then a TextValue is included in the results if any of the words are found (OR filter). If anyMatch is false, then the TextValue must contain all the words in the query string (AND filter). The filtered results are sorted alphabetically by value, not by ID.
func (Service) FilterThingMessages ¶
func (s Service) FilterThingMessages(ctx context.Context, contains string, anyMatch bool) ([]v.TextValue, error)
FilterThingMessages returns a filtered list of Thing IDs and messages. The case-insensitive contains query is split into words, and the words are compared with the message. If anyMatch is true, then a TextValue is included in the results if any of the words are found (OR filter). If anyMatch is false, then the TextValue must contain all the words in the query string (AND filter). The filtered results are sorted alphabetically by message, not by ID.
func (Service) ReadAllCountsByTag ¶
func (s Service) ReadAllCountsByTag(ctx context.Context, tag string, sortByValue bool) ([]v.NumValue, error)
ReadAllCountsByTag returns a complete list of Thing IDs and counts for a specified tag, optionally sorted by ascending count. The default order is chronological (sorted by ID).
func (Service) ReadAllDates ¶
ReadAllDates returns a complete chronological list of all days for which there are Things in the table.
func (Service) ReadAllMessagesByTag ¶
func (s Service) ReadAllMessagesByTag(ctx context.Context, tag string, sortByValue bool) ([]v.TextValue, error)
ReadAllMessagesByTag returns a complete list of Thing IDs and messages for a specified tag, optionally sorted by message. The default order is chronological (sorted by ID).
func (Service) ReadAllTags ¶
ReadAllTags returns a complete alphabetical list of all tags for which there are Things in the table.
func (Service) ReadAllThingIDs ¶
ReadAllThingIDs returns a complete chronological list of all Thing IDs in the Thing table.
func (Service) ReadAllThingMessages ¶
ReadAllThingMessages returns all Thing IDs and messages in the Thing table, optionally sorted by message (the default is sorted by ID). Caution: this may be a LOT of data!
func (Service) ReadAllThingsByDate ¶
ReadAllThingsByDate returns a complete chronological list of all Things for a specified day.
func (Service) ReadAllThingsByDateAsJSON ¶
ReadAllThingsByDateAsJSON returns a complete chronological list of all Things for a specified day, serialized as JSON.
func (Service) ReadAllThingsByTag ¶
ReadAllThingsByTag returns a complete chronological list of all Things for a specified tag.
func (Service) ReadAllThingsByTagAsJSON ¶
ReadAllThingsByTagAsJSON returns a complete chronological list of all Things for a specified tag, serialized as JSON.
func (Service) ReadAllVersions ¶
ReadAllVersions returns all versions of the specified Thing in chronological order. Caution: this may be a LOT of data!
func (Service) ReadAllVersionsAsJSON ¶
ReadAllVersionsAsJSON returns all versions of the specified Thing, serialized as JSON. Caution: this may be a LOT of data!
func (Service) ReadAsJSON ¶
ReadAsJSON gets a specified Thing from the Thing table, serialized as JSON.
func (Service) ReadCountsByTag ¶
func (s Service) ReadCountsByTag(ctx context.Context, tag string, reverse bool, limit int, offset string) ([]v.NumValue, error)
ReadCountsByTag returns a paginated list of Thing IDs and counts for a specified tag. Sorting is chronological (or reverse). The offset is the last ID returned in a previous request.
func (Service) ReadDates ¶
func (s Service) ReadDates(ctx context.Context, reverse bool, limit int, offset string) ([]string, error)
ReadDates returns a paginated list of days for which there are Things in the table. Sorting is chronological (or reverse). The offset is the last day returned in a previous request.
func (Service) ReadMessageRangeByTag ¶
func (s Service) ReadMessageRangeByTag(ctx context.Context, tag string, from, to string, reverse bool) ([]v.TextValue, error)
ReadMessageRangeByTag returns a range of Thing IDs with associated messages for a specified tag. The 'from' and 'to' parameters are inclusive. If omitted, they're replaced with sentinel values.
func (Service) ReadMessagesByTag ¶
func (s Service) ReadMessagesByTag(ctx context.Context, tag string, reverse bool, limit int, offset string) ([]v.TextValue, error)
ReadMessagesByTag returns a paginated list of Thing IDs and messages for a specified tag. Sorting is chronological (or reverse). The offset is the last ID returned in a previous request.
func (Service) ReadTags ¶
func (s Service) ReadTags(ctx context.Context, reverse bool, limit int, offset string) ([]string, error)
ReadTags returns a paginated list of tags for which there are Things in the table. Sorting is alphabetical (or reverse). The offset is the last tag returned in a previous request.
func (Service) ReadThingIDs ¶
func (s Service) ReadThingIDs(ctx context.Context, reverse bool, limit int, offset string) ([]string, error)
ReadThingIDs returns a paginated list of Thing IDs in the Thing table. Sorting is chronological (or reverse). The offset is the last ID returned in a previous request.
func (Service) ReadThingMessageRange ¶
func (s Service) ReadThingMessageRange(ctx context.Context, from, to string, reverse bool) ([]v.TextValue, error)
ReadThingMessageRange returns a range of Thing IDs with associated messages. The 'from' and 'to' parameters are inclusive. If omitted, they're replaced with sentinel values.
func (Service) ReadThingMessages ¶
func (s Service) ReadThingMessages(ctx context.Context, reverse bool, limit int, offset string) ([]v.TextValue, error)
ReadThingMessages returns a paginated list of Thing IDs and messages in the Thing table. Sorting is chronological (or reverse). The offset is the last ID returned in a previous request.
func (Service) ReadThingsByDate ¶
func (s Service) ReadThingsByDate(ctx context.Context, day string, reverse bool, limit int, offset string) ([]Thing, error)
ReadThingsByDate returns a paginated list of Things for a specified day. Sorting is chronological (or reverse). The offset is the last ID returned in a previous request.
func (Service) ReadThingsByDateAsJSON ¶
func (s Service) ReadThingsByDateAsJSON(ctx context.Context, day string, reverse bool, limit int, offset string) ([]byte, error)
ReadThingsByDateAsJSON returns a paginated list of Things for a specified day, serialized as JSON. Sorting is chronological (or reverse). The offset is the last ID returned in a previous request.
func (Service) ReadThingsByTag ¶
func (s Service) ReadThingsByTag(ctx context.Context, tag string, reverse bool, limit int, offset string) ([]Thing, error)
ReadThingsByTag returns a paginated list of Things for a specified tag. Sorting is chronological (or reverse). The offset is the last ID returned in a previous request.
func (Service) ReadThingsByTagAsJSON ¶
func (s Service) ReadThingsByTagAsJSON(ctx context.Context, tag string, reverse bool, limit int, offset string) ([]byte, error)
ReadThingsByTagAsJSON returns a paginated list of Things for a specified tag, serialized as JSON. Sorting is chronological (or reverse). The offset is the last ID returned in a previous request.
func (Service) ReadVersion ¶
ReadVersion gets a specified Thing version from the Thing table.
func (Service) ReadVersionAsJSON ¶
ReadVersionAsJSON gets a specified Thing version from the Thing table, serialized as JSON.
func (Service) ReadVersions ¶
func (s Service) ReadVersions(ctx context.Context, id string, reverse bool, limit int, offset string) ([]Thing, error)
ReadVersions returns paginated versions of the specified Thing. Sorting is chronological (or reverse). The offset is the last ID returned in a previous request.
func (Service) ReadVersionsAsJSON ¶
func (s Service) ReadVersionsAsJSON(ctx context.Context, id string, reverse bool, limit int, offset string) ([]byte, error)
ReadVersionsAsJSON returns paginated versions of the specified Thing, serialized as JSON. Sorting is chronological (or reverse). The offset is the last ID returned in a previous request.
func (Service) SumCountsByTag ¶
SumCountsByTag returns the sum of all counts for a specified tag.
type Thing ¶
type Thing struct { ID string `json:"id"` VersionID string `json:"versionId"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` ExpiresAt time.Time `json:"expiresAt"` Tags []string `json:"tags"` Count int `json:"count"` Message string `json:"message"` }
Thing is a simple example struct that demonstrates how to use the versionary package.
func (Thing) CompressedJSON ¶
CompressedJSON returns a compressed JSON representation of the Thing. It fails silently, returning nil, if the JSON cannot be generated.