Documentation ¶
Index ¶
- Constants
- Variables
- func Create[T Identifyable](bb *BBolter, bucket []byte, item T) error
- func Find[T Identifyable](bb Datastore, bucket []byte, max int, shouldAdd func(t T) bool) (map[string]T, error)
- func FindOne[T Identifyable](bb Datastore, bucket []byte, isMatch func(t T) bool) (*T, error)
- func Get[T Identifyable](bb Datastore, bucket []byte, id string) (*T, error)
- func NewMockDB(t *testing.T) mockDB
- func Update[T Identifyable](bb *BBolter, bucket []byte, id string, merge func(t T) (T, error)) (T, error)
- type BBoltOptions
- type BBolter
- func (s *BBolter) Backup(w io.Writer) (int64, error)
- func (bb *BBolter) BucketStats() map[string]interface{}
- func (b *BBolter) CreateCategory(category types.Category) (types.Category, error)
- func (b *BBolter) CreateLocale(locale types.Locale) (types.Locale, error)
- func (b *BBolter) CreateOrganization(organization types.Organization) (types.Organization, error)
- func (b *BBolter) CreateProject(project types.Project) (types.Project, error)
- func (bb *BBolter) CreateSession(key string, session types.Session) (types.Session, error)
- func (b *BBolter) CreateSnapshot(snapshot types.ProjectSnapshot) (types.ProjectSnapshot, error)
- func (b *BBolter) CreateTranslation(translation types.Translation) (types.Translation, error)
- func (b *BBolter) CreateTranslationValue(tv types.TranslationValue) (types.TranslationValue, error)
- func (b *BBolter) CreateUser(user types.User) (types.User, error)
- func (bb *BBolter) EvictSession(key string) error
- func (bb *BBolter) FindCategories(max int, filter ...types.CategoryFilter) (map[string]types.Category, error)
- func (bb *BBolter) FindOneCategory(filter ...types.CategoryFilter) (*types.Category, error)
- func (bb *BBolter) FindOneOrganization(filter ...types.Organization) (*types.Organization, error)
- func (bb *BBolter) FindOneSnapshot(filter ...types.ProjectSnapshot) (*types.ProjectSnapshot, error)
- func (bb *BBolter) FindOneUser(filter ...types.User) (*types.User, error)
- func (bb *BBolter) FindOrganizationByIdOrTitle(titleOrID string) (*types.Organization, error)
- func (bb *BBolter) FindProjects(max int, filter ...types.Project) (map[string]types.Project, error)
- func (bb *BBolter) FindSnapshots(max int, filter ...types.ProjectSnapshot) (map[string]types.ProjectSnapshot, error)
- func (bb *BBolter) FindUserByUserName(organizationID string, userName string) (*types.User, error)
- func (bb *BBolter) FindUsers(max int, filter ...types.User) (map[string]types.User, error)
- func (bb *BBolter) GetCategories() (map[string]types.Category, error)
- func (bb *BBolter) GetCategory(ID string) (*types.Category, error)
- func (s *BBolter) GetItem(bucket []byte, id string, j interface{}) error
- func (b *BBolter) GetLocale(ID string) (types.Locale, error)
- func (bb *BBolter) GetLocaleByFirstMatch(name string) (*types.Locale, error)
- func (bb *BBolter) GetLocaleByIDOrShortName(shortNameOrId string) (*types.Locale, error)
- func (bb *BBolter) GetLocaleByShortName(shortName string) (*types.Locale, error)
- func (bb *BBolter) GetLocaleFilter(filter ...types.Locale) (*types.Locale, error)
- func (bb *BBolter) GetLocales() (map[string]types.Locale, error)
- func (bb *BBolter) GetMissingKeysFilter(max int, filter ...types.MissingTranslation) (map[string]types.MissingTranslation, error)
- func (b *BBolter) GetOrganization(ID string) (*types.Organization, error)
- func (bb *BBolter) GetOrganizations() (map[string]types.Organization, error)
- func (b *BBolter) GetProject(ID string) (*types.Project, error)
- func (bb *BBolter) GetProjectByIDOrShortName(shortNameOrId string) (*types.Project, error)
- func (bb *BBolter) GetProjectByShortName(shortName string) (*types.Project, error)
- func (bb *BBolter) GetProjectFilter(filter ...types.Project) (*types.Project, error)
- func (bb *BBolter) GetProjects() (map[string]types.Project, error)
- func (bb *BBolter) GetSessions() (sess map[string]types.Session, err error)
- func (bb *BBolter) GetSnapshot(snapshotId string) (*types.ProjectSnapshot, error)
- func (bb *BBolter) GetState() (*types.State, error)
- func (b *BBolter) GetTranslation(ID string) (*types.Translation, error)
- func (bb *BBolter) GetTranslationFilter(filter ...types.Translation) (*types.Translation, error)
- func (b *BBolter) GetTranslationValue(ID string) (*types.TranslationValue, error)
- func (bb *BBolter) GetTranslationValueFilter(filter ...types.TranslationValue) (*types.TranslationValue, error)
- func (bb *BBolter) GetTranslationValues() (map[string]types.TranslationValue, error)
- func (bb *BBolter) GetTranslationValuesFilter(max int, filter ...types.TranslationValue) (map[string]types.TranslationValue, error)
- func (bb *BBolter) GetTranslations() (map[string]types.Translation, error)
- func (bb *BBolter) GetTranslationsFilter(max int, filter ...types.Translation) (map[string]types.Translation, error)
- func (bb *BBolter) GetUser(userId string) (*types.User, error)
- func (bb *BBolter) Iterate(bucket []byte, f func(key, b []byte) bool) error
- func (bb *BBolter) Migrate(hooks ...func(state types.State, wantedMigrationPoint int) error) (types.State, error)
- func (s *BBolter) NewEntity(base types.Entity) (e types.Entity, err error)
- func (s *BBolter) PublishChange(kind PubType, variant PubVerb, contents interface{})
- func (b *BBolter) ReportMissing(key types.MissingTranslation) (*types.MissingTranslation, error)
- func (bb *BBolter) SetState(newState types.State) (types.State, error)
- func (bb *BBolter) Size() (int64, error)
- func (bb *BBolter) SoftDeleteTranslation(id string, byUser string, deleteTime *time.Time) (types.Translation, error)
- func (b *BBolter) UpdateCategory(id string, payload types.Category) (types.Category, error)
- func (bb *BBolter) UpdateMissingWithNewIds(payload types.MissingTranslation) (map[string]types.MissingTranslation, error)
- func (bb *BBolter) UpdateOrganization(id string, payload types.UpdateOrganizationPayload) (types.Organization, error)
- func (b *BBolter) UpdateProject(id string, project types.Project) (types.Project, error)
- func (bb *BBolter) UpdateSnapshot(id string, payload types.ProjectSnapshot) (types.ProjectSnapshot, error)
- func (b *BBolter) UpdateTranslation(id string, payload types.Translation) (types.Translation, error)
- func (bb *BBolter) UpdateTranslationValue(tv types.TranslationValue) (types.TranslationValue, error)
- func (bb *BBolter) UpdateUser(id string, payload types.UpdateUserPayload) (types.User, error)
- func (s *BBolter) WriteState() WriteStats
- type Datastore
- type Gob
- type IDGenerator
- type Identifyable
- type Marshaller
- type PubSubPublisher
- type PubType
- type PubVerb
- type WriteStats
Constants ¶
const ( // PubTypeUser PubType = "user" PubTypeTranslation PubType = "translation" PubTypeMissingTranslation PubType = "missingTranslation" PubTypeTranslationValue PubType = "translationValue" PubTypeCategory PubType = "category" PubTypeLocale PubType = "locale" PubTypeProject PubType = "project" PubTypeOrganization PubType = "organization" PubVerbCreate PubVerb = "create" PubVerbUpdate PubVerb = "update" // Marks the item as deleted in the database, but does not delete it PubVerbSoftDelete PubVerb = "soft-delete" // Removes all items permanently PubVerbClean PubVerb = "clean" PubVerbConnectItem PubVerb = "connect" )
TODO: move these to types.
Variables ¶
var ( ErrNoFieldsChanged = errors.New("No fields changed") ErrIDStringMismatch = errors.New("The IDString did not match the expected id. (Marshalling error?, wrong type?)") )
var ( ErrDuplicate = errors.New("Duplication of entities is disallowed") ErrMissingIdArg = errors.New("Missing id as argument") ErrMissingProject = errors.New("Missing ProjectID as argument") // deprecated. return pointer instead ErrNotFound = errors.New("Not found") ErrMissingBucket = errors.New("Bucket not found") )
var ( ErrMissingCreatedBy = errors.New("CreatedBy was empty") ErrMissingOrganizationID = errors.New("OrganizationID was empty") ErrMissingProjectID = errors.New("ProjectID was empty") ErrMissingTags = errors.New("Missing tags") )
var ( BucketSession = []byte("sessions") BucketUser = []byte("users") BucketSys = []byte("sys") BucketLocale = []byte("locales") BucketSnapshot = []byte("snapshot") BucketTranslation = []byte("translations") BucketProject = []byte("projects") BucketOrganization = []byte("organizations") BucketTranslationValue = []byte("translationValues") BucketCategory = []byte("categories") BucketMissing = []byte("missing") )
Functions ¶
func Create ¶
func Create[T Identifyable](bb *BBolter, bucket []byte, item T) error
Creates an item in the assigned bucket
func Find ¶
func Find[T Identifyable](bb Datastore, bucket []byte, max int, shouldAdd func(t T) bool) (map[string]T, error)
Returning a list of items, up to max-count. The in-function should return a boolean indicating if that item should be added to the map or not.
func FindOne ¶
func FindOne[T Identifyable](bb Datastore, bucket []byte, isMatch func(t T) bool) (*T, error)
Returns a single item by iterating. Mostly used for searching If you are attempting to find by ID, see Get instead
Types ¶
type BBoltOptions ¶
type BBoltOptions struct {
IDGenerator IDGenerator
}
type BBolter ¶
type BBolter struct { *bolt.DB Marshaller // contains filtered or unexported fields }
func NewBbolt ¶
func NewBbolt(l logger.AppLogger, path string, pubsub PubSubPublisher, options ...BBoltOptions) (bb BBolter, err error)
Caller must call close when ending
func (*BBolter) Backup ¶ added in v0.8.4
Backups the database to a writer. Note that bbolt seems to always change the file (statistics?), so creating a hash of the the database does not
func (*BBolter) BucketStats ¶
Returns BucketStats for all buckets used
func (*BBolter) CreateCategory ¶
func (*BBolter) CreateLocale ¶
func (*BBolter) CreateOrganization ¶
func (b *BBolter) CreateOrganization(organization types.Organization) (types.Organization, error)
func (*BBolter) CreateProject ¶
func (*BBolter) CreateSession ¶
func (*BBolter) CreateSnapshot ¶
func (b *BBolter) CreateSnapshot(snapshot types.ProjectSnapshot) (types.ProjectSnapshot, error)
func (*BBolter) CreateTranslation ¶
func (b *BBolter) CreateTranslation(translation types.Translation) (types.Translation, error)
func (*BBolter) CreateTranslationValue ¶
func (b *BBolter) CreateTranslationValue(tv types.TranslationValue) (types.TranslationValue, error)
func (*BBolter) EvictSession ¶
func (*BBolter) FindCategories ¶
func (*BBolter) FindOneCategory ¶
func (*BBolter) FindOneOrganization ¶ added in v0.8.0
func (bb *BBolter) FindOneOrganization(filter ...types.Organization) (*types.Organization, error)
func (*BBolter) FindOneSnapshot ¶
func (bb *BBolter) FindOneSnapshot(filter ...types.ProjectSnapshot) (*types.ProjectSnapshot, error)
func (*BBolter) FindOneUser ¶
func (*BBolter) FindOrganizationByIdOrTitle ¶ added in v0.8.0
func (bb *BBolter) FindOrganizationByIdOrTitle(titleOrID string) (*types.Organization, error)
func (*BBolter) FindProjects ¶
func (*BBolter) FindSnapshots ¶
func (bb *BBolter) FindSnapshots(max int, filter ...types.ProjectSnapshot) (map[string]types.ProjectSnapshot, error)
func (*BBolter) FindUserByUserName ¶
func (*BBolter) GetCategories ¶
func (*BBolter) GetLocaleByFirstMatch ¶
func (*BBolter) GetLocaleByIDOrShortName ¶
func (*BBolter) GetLocaleByShortName ¶
func (*BBolter) GetLocaleFilter ¶
func (*BBolter) GetMissingKeysFilter ¶
func (bb *BBolter) GetMissingKeysFilter(max int, filter ...types.MissingTranslation) (map[string]types.MissingTranslation, error)
func (*BBolter) GetOrganization ¶
func (b *BBolter) GetOrganization(ID string) (*types.Organization, error)
func (*BBolter) GetOrganizations ¶
func (bb *BBolter) GetOrganizations() (map[string]types.Organization, error)
func (*BBolter) GetProjectByIDOrShortName ¶
func (*BBolter) GetProjectByShortName ¶
func (*BBolter) GetProjectFilter ¶
func (*BBolter) GetSessions ¶
func (*BBolter) GetSnapshot ¶
func (bb *BBolter) GetSnapshot(snapshotId string) (*types.ProjectSnapshot, error)
func (*BBolter) GetTranslation ¶
func (b *BBolter) GetTranslation(ID string) (*types.Translation, error)
func (*BBolter) GetTranslationFilter ¶
func (bb *BBolter) GetTranslationFilter(filter ...types.Translation) (*types.Translation, error)
func (*BBolter) GetTranslationValue ¶
func (b *BBolter) GetTranslationValue(ID string) (*types.TranslationValue, error)
func (*BBolter) GetTranslationValueFilter ¶
func (bb *BBolter) GetTranslationValueFilter(filter ...types.TranslationValue) (*types.TranslationValue, error)
func (*BBolter) GetTranslationValues ¶
func (bb *BBolter) GetTranslationValues() (map[string]types.TranslationValue, error)
func (*BBolter) GetTranslationValuesFilter ¶
func (bb *BBolter) GetTranslationValuesFilter(max int, filter ...types.TranslationValue) (map[string]types.TranslationValue, error)
func (*BBolter) GetTranslations ¶
func (bb *BBolter) GetTranslations() (map[string]types.Translation, error)
func (*BBolter) GetTranslationsFilter ¶
func (bb *BBolter) GetTranslationsFilter(max int, filter ...types.Translation) (map[string]types.Translation, error)
func (*BBolter) Iterate ¶
iterates over objects within a bucket. The function-parameter will receive each item as key/value Returning true within this function will stop the iteration
func (*BBolter) PublishChange ¶
func (*BBolter) ReportMissing ¶
func (b *BBolter) ReportMissing(key types.MissingTranslation) (*types.MissingTranslation, error)
func (*BBolter) SoftDeleteTranslation ¶
func (*BBolter) UpdateCategory ¶
TODO: complete implementation
func (*BBolter) UpdateMissingWithNewIds ¶
func (bb *BBolter) UpdateMissingWithNewIds(payload types.MissingTranslation) (map[string]types.MissingTranslation, error)
Updates all MissingTranslations with Project/ProjectID TODO: do the same for Category, Translation and Localization
func (*BBolter) UpdateOrganization ¶ added in v0.8.0
func (bb *BBolter) UpdateOrganization(id string, payload types.UpdateOrganizationPayload) (types.Organization, error)
func (*BBolter) UpdateProject ¶
func (*BBolter) UpdateSnapshot ¶
func (bb *BBolter) UpdateSnapshot(id string, payload types.ProjectSnapshot) (types.ProjectSnapshot, error)
func (*BBolter) UpdateTranslation ¶
func (b *BBolter) UpdateTranslation(id string, payload types.Translation) (types.Translation, error)
TODO: complete implementation
func (*BBolter) UpdateTranslationValue ¶
func (bb *BBolter) UpdateTranslationValue(tv types.TranslationValue) (types.TranslationValue, error)
func (*BBolter) UpdateUser ¶
func (*BBolter) WriteState ¶ added in v0.8.4
func (s *BBolter) WriteState() WriteStats
type Datastore ¶
type Datastore interface { GetItem([]byte, string, interface{}) error Iterate(bucket []byte, f func(key, b []byte) bool) error // iterates over objects within a bucket. // The function-parameter will receive each item as key/value // Returning true within this function will stop the iteration Marshaller PublishChange(kind PubType, variant PubVerb, contents interface{}) }
type IDGenerator ¶
type IDGenerator interface {
CreateUniqueID() string
}
type Identifyable ¶
type Marshaller ¶
type PubSubPublisher ¶
type PubSubPublisher interface {
Publish(kind, variant string, contents interface{})
}