bboltStorage

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var (
	ErrNoFieldsChanged  = errors.New("No fields changed")
	ErrIDStringMismatch = errors.New("The IDString did not match the expected id. (Marshalling error?, wrong type?)")
)
View Source
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")
)
View Source
var (
	ErrMissingCreatedBy      = errors.New("CreatedBy was empty")
	ErrMissingOrganizationID = errors.New("OrganizationID was empty")
	ErrMissingProjectID      = errors.New("ProjectID was empty")
	ErrMissingTags           = errors.New("Missing tags")
)
View Source
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

func Get

func Get[T Identifyable](bb Datastore, bucket []byte, id string) (*T, error)

Generics function returning a single item, by its id

func NewMockDB

func NewMockDB(t *testing.T) mockDB

func Update

func Update[T Identifyable](bb *BBolter, bucket []byte, id string, merge func(t T) (T, error)) (T, error)

Updates an item in the assigned bucket

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

func (s *BBolter) Backup(w io.Writer) (int64, error)

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

func (bb *BBolter) BucketStats() map[string]interface{}

Returns BucketStats for all buckets used

func (*BBolter) CreateCategory

func (b *BBolter) CreateCategory(category types.Category) (types.Category, error)

func (*BBolter) CreateLocale

func (b *BBolter) CreateLocale(locale types.Locale) (types.Locale, error)

func (*BBolter) CreateOrganization

func (b *BBolter) CreateOrganization(organization types.Organization) (types.Organization, error)

func (*BBolter) CreateProject

func (b *BBolter) CreateProject(project types.Project) (types.Project, error)

func (*BBolter) CreateSession

func (bb *BBolter) CreateSession(key string, session types.Session) (types.Session, error)

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) CreateUser

func (b *BBolter) CreateUser(user types.User) (types.User, error)

func (*BBolter) EvictSession

func (bb *BBolter) EvictSession(key string) error

func (*BBolter) FindCategories

func (bb *BBolter) FindCategories(max int, filter ...types.CategoryFilter) (map[string]types.Category, error)

func (*BBolter) FindOneCategory

func (bb *BBolter) FindOneCategory(filter ...types.CategoryFilter) (*types.Category, error)

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 (bb *BBolter) FindOneUser(filter ...types.User) (*types.User, error)

func (*BBolter) FindOrganizationByIdOrTitle added in v0.8.0

func (bb *BBolter) FindOrganizationByIdOrTitle(titleOrID string) (*types.Organization, error)

func (*BBolter) FindProjects

func (bb *BBolter) FindProjects(max int, filter ...types.Project) (map[string]types.Project, error)

func (*BBolter) FindSnapshots

func (bb *BBolter) FindSnapshots(max int, filter ...types.ProjectSnapshot) (map[string]types.ProjectSnapshot, error)

func (*BBolter) FindUserByUserName

func (bb *BBolter) FindUserByUserName(organizationID string, userName string) (*types.User, error)

func (*BBolter) FindUsers

func (bb *BBolter) FindUsers(max int, filter ...types.User) (map[string]types.User, error)

func (*BBolter) GetCategories

func (bb *BBolter) GetCategories() (map[string]types.Category, error)

func (*BBolter) GetCategory

func (bb *BBolter) GetCategory(ID string) (*types.Category, error)

func (*BBolter) GetItem

func (s *BBolter) GetItem(bucket []byte, id string, j interface{}) error

func (*BBolter) GetLocale

func (b *BBolter) GetLocale(ID string) (types.Locale, error)

func (*BBolter) GetLocaleByFirstMatch

func (bb *BBolter) GetLocaleByFirstMatch(name string) (*types.Locale, error)

func (*BBolter) GetLocaleByIDOrShortName

func (bb *BBolter) GetLocaleByIDOrShortName(shortNameOrId string) (*types.Locale, error)

func (*BBolter) GetLocaleByShortName

func (bb *BBolter) GetLocaleByShortName(shortName string) (*types.Locale, error)

func (*BBolter) GetLocaleFilter

func (bb *BBolter) GetLocaleFilter(filter ...types.Locale) (*types.Locale, error)

func (*BBolter) GetLocales

func (bb *BBolter) GetLocales() (map[string]types.Locale, error)

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) GetProject

func (b *BBolter) GetProject(ID string) (*types.Project, error)

func (*BBolter) GetProjectByIDOrShortName

func (bb *BBolter) GetProjectByIDOrShortName(shortNameOrId string) (*types.Project, error)

func (*BBolter) GetProjectByShortName

func (bb *BBolter) GetProjectByShortName(shortName string) (*types.Project, error)

func (*BBolter) GetProjectFilter

func (bb *BBolter) GetProjectFilter(filter ...types.Project) (*types.Project, error)

func (*BBolter) GetProjects

func (bb *BBolter) GetProjects() (map[string]types.Project, error)

func (*BBolter) GetSessions

func (bb *BBolter) GetSessions() (sess map[string]types.Session, err error)

func (*BBolter) GetSnapshot

func (bb *BBolter) GetSnapshot(snapshotId string) (*types.ProjectSnapshot, error)

func (*BBolter) GetState

func (bb *BBolter) GetState() (*types.State, 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) GetUser

func (bb *BBolter) GetUser(userId string) (*types.User, error)

func (*BBolter) Iterate

func (bb *BBolter) 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

func (*BBolter) Migrate

func (bb *BBolter) Migrate(hooks ...func(state types.State, wantedMigrationPoint int) error) (types.State, error)

func (*BBolter) NewEntity

func (s *BBolter) NewEntity(base types.Entity) (e types.Entity, err error)

func (*BBolter) PublishChange

func (s *BBolter) PublishChange(kind PubType, variant PubVerb, contents interface{})

func (*BBolter) ReportMissing

func (b *BBolter) ReportMissing(key types.MissingTranslation) (*types.MissingTranslation, error)

func (*BBolter) SetState

func (bb *BBolter) SetState(newState types.State) (types.State, error)

func (*BBolter) Size

func (bb *BBolter) Size() (int64, error)

func (*BBolter) SoftDeleteTranslation

func (bb *BBolter) SoftDeleteTranslation(id string, byUser string, deleteTime *time.Time) (types.Translation, error)

func (*BBolter) UpdateCategory

func (b *BBolter) UpdateCategory(id string, payload types.Category) (types.Category, error)

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 (b *BBolter) UpdateProject(id string, project types.Project) (types.Project, error)

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 (bb *BBolter) UpdateUser(id string, payload types.UpdateUserPayload) (types.User, error)

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 Gob

type Gob struct{}

func (Gob) Marshal

func (g Gob) Marshal(j interface{}) ([]byte, error)

func (Gob) Unmarshal

func (g Gob) Unmarshal(data []byte, v interface{}) error

type IDGenerator

type IDGenerator interface {
	CreateUniqueID() string
}

type Identifyable

type Identifyable interface {
	IDString() string
	Namespace() string
	Kind() string
}

type Marshaller

type Marshaller interface {
	Unmarshal(data []byte, v interface{}) error
	Marshal(j interface{}) ([]byte, error)
}

type PubSubPublisher

type PubSubPublisher interface {
	Publish(kind, variant string, contents interface{})
}

type PubType

type PubType string

type PubVerb

type PubVerb string

type WriteStats added in v0.8.4

type WriteStats struct {
	LastWrite *time.Time
}

Jump to

Keyboard shortcuts

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