dbox

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2016 License: MIT Imports: 13 Imported by: 5

README

dbox

abstraction layer for store any objects to use same api

Build Status Go Report Card

Status. In pursuit of the ideal architecture and internal api.

TODO: example of using

Object

Any object implements the interface.

  • ID() string - the object identifier
  • SetID(string)
  • IsNew() bool
  • Bytes() []byte - the data of the object
  • Write([]byte)
  • Decode() error - decode the object. Object data are decoded
  • Encode() error - encode the object, updated data of the object
  • Sync() error - to update data in the store

Helper objects

  • MapObject - object with structured data
  • RawObject - object with raw data
  • RefObject - a special object to store links files (e.g. a reference file by file name)

File

Implements an MapObject. Any file refers to bucket. Bucket defines how file storage (sets stores for internal objects of file).

  • Delete() error - remove file in the store
  • RawData() Object - raw data file
  • Meta() map[string]interface{} - meta data file
  • MapData() map[string]interface{} - structured data file
  • Name() string - file name
  • SetName() string - file name
  • Bucket() - bucket name (bucket must exist)
  • EntityType() EntityType - type of file (for high-level logic).
  • CreatedAt() time.Time - file creation date
  • UpdatedAt() time.Time - file creation date
  • SetMapDataStore(Store) - set a repository for structured data file
  • SetRawDataStore(Store) - set a repository for raw data file

The best guide is the test.

TODO: Simple examples for quick start.

Storages

Change log

changed the logic of preserving objects associated with a new file

new file is saved all at once that would not be large delays

see commit

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound       = fmt.Errorf("not_found")
	ErrNotFoundBucket = fmt.Errorf("not_found_bucket")
	ErrInvalidData    = fmt.Errorf("invalid_data")

	ErrEmptyName = fmt.Errorf("empty_name")
	ErrEmptyID   = fmt.Errorf("empty_id")
)
View Source
var (
	NameKey          = "NameKey"
	MapDataIDMetaKey = "MapDataID"
	RawDataIDMetaKey = "RawDataID"
	CreatedAtKey     = "CreatedAt"
	UpdatedAtKey     = "UpdatedAt"

	BucketKey                = "BucketKey"
	MapDataStoreNameKey      = "MapDataStoreNameKey"
	RawDataStoreNameKey      = "RawDataStoreNameKey"
	MetaDataFileStoreNameKey = "MetaDataFileStoreNameKey"
)
View Source
var LocalStoreDefaultStorePath = "./workspaces.dbox/"

Functions

func InitDefaultBuckets

func InitDefaultBuckets()

func InitDefaultStores

func InitDefaultStores()

func NewUUID

func NewUUID() string

func RegistryStore

func RegistryStore(name string, store Store)

Types

type BoltDBStore

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

func NewBoltDBStore

func NewBoltDBStore(db *bolt.DB, bucketname string) *BoltDBStore

func (*BoltDBStore) Delete

func (s *BoltDBStore) Delete(obj Object) (err error)

func (BoltDBStore) Get

func (s BoltDBStore) Get(id string, obj Object) error

func (BoltDBStore) GetByName

func (s BoltDBStore) GetByName(name string, obj Object) error

GetByName Get object by name (via ReObject)

func (*BoltDBStore) Save

func (s *BoltDBStore) Save(obj Object) (err error)

func (BoltDBStore) Type

func (s BoltDBStore) Type() StoreType

type Bucket

type Bucket struct {
	File
}

func BucketByName

func BucketByName(name string) (file *Bucket, err error)

BucketByName return bucket from name if not exist file, file accepts values nil, err accepts values ErrNotFound

func NewBucket

func NewBucket() *Bucket

func (Bucket) Bytes

func (o Bucket) Bytes() []byte

func (Bucket) ID

func (o Bucket) ID() string

func (Bucket) IsNew

func (o Bucket) IsNew() bool

func (Bucket) MapDataStoreName

func (b Bucket) MapDataStoreName() string

func (Bucket) MetaDataStoreName

func (b Bucket) MetaDataStoreName() string

func (Bucket) RawDataStoreName

func (b Bucket) RawDataStoreName() string

func (Bucket) SetID

func (o Bucket) SetID(id string)

func (Bucket) SetMapDataStoreName

func (b Bucket) SetMapDataStoreName(v string)

func (Bucket) SetMetaDataStoreName

func (b Bucket) SetMetaDataStoreName(v string)

func (Bucket) SetRawDataStoreName

func (b Bucket) SetRawDataStoreName(v string)

func (Bucket) Type

func (Bucket) Type() EntityType

func (Bucket) Write

func (o Bucket) Write(p []byte)

type EntityType

type EntityType string
var (
	FileEntityType   EntityType = "file"
	BucketEntityType EntityType = "bucket"
)

type File

type File struct {
	*MapObject
	// contains filtered or unexported fields
}

func LoadOrNewFile

func LoadOrNewFile(bucketName string, fileName string) (file *File, err error)

LoadOrNewFile return file by bucket name and filename. If not exist bucket, file accepts values nil, err accepts values ErrNotFoundBucket. If not exist file, file accepts values nil, err accepts values ErrNotFound. In cases where file not exist, file name and file bucket name accepts values from arguments.

func NewFile

func NewFile(store Store) *File

func NewFileID

func NewFileID(id string, store Store) (file *File, err error)

func NewFileName

func NewFileName(name string, store Store) (file *File, err error)

NewFileName return file by filename. In cases where file not exist, file name accepts values from arguments.

func (*File) BeforeCreate

func (f *File) BeforeCreate()

func (*File) BeforeUpdate

func (f *File) BeforeUpdate()

func (File) Bucket

func (f File) Bucket() string

func (File) Bytes

func (o File) Bytes() []byte

func (File) CreatedAt

func (f File) CreatedAt() time.Time

func (*File) Delete

func (f *File) Delete() error

func (File) Export

func (f File) Export() ([]byte, error)

func (File) ID

func (o File) ID() string

func (*File) Import

func (f *File) Import(b []byte) error

func (File) IsNew

func (o File) IsNew() bool

func (*File) MapData

func (f *File) MapData() map[string]interface{}

MapData struct data file

func (*File) Meta

func (f *File) Meta() map[string]interface{}

Meta meta data file

func (File) Name

func (f File) Name() string

func (*File) RawData

func (f *File) RawData() Object

RawData raw data file

func (File) SetBucket

func (f File) SetBucket(v string)

func (File) SetID

func (o File) SetID(id string)

func (*File) SetMapDataStore

func (f *File) SetMapDataStore(s Store)

func (File) SetName

func (f File) SetName(v string)

func (*File) SetRawDataStore

func (f *File) SetRawDataStore(s Store)

func (File) String

func (f File) String() string

func (*File) Sync

func (f *File) Sync() error

func (File) Type

func (File) Type() EntityType

func (File) UpdatedAt

func (f File) UpdatedAt() time.Time

func (File) Write

func (o File) Write(p []byte)

type FileStore

type FileStore interface {
	Store

	GetByName(name string, obj Object) error
}

FileStore implements store data of files

type LocalStore

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

func NewLocalStore

func NewLocalStore(path string) *LocalStore

func (*LocalStore) Delete

func (s *LocalStore) Delete(obj Object) (err error)

func (LocalStore) Get

func (s LocalStore) Get(id string, obj Object) error

func (LocalStore) GetByName

func (s LocalStore) GetByName(name string, obj Object) error

func (*LocalStore) Save

func (s *LocalStore) Save(obj Object) (err error)

func (LocalStore) Type

func (s LocalStore) Type() StoreType

type MapObject

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

func NewMapObject

func NewMapObject(store Store) *MapObject

func (MapObject) Bytes

func (o MapObject) Bytes() []byte

func (MapObject) Decode

func (f MapObject) Decode() error

func (*MapObject) Encode

func (f *MapObject) Encode() (err error)

func (MapObject) ID

func (o MapObject) ID() string

func (MapObject) IsNew

func (o MapObject) IsNew() bool

func (MapObject) Map

func (f MapObject) Map() map[string]interface{}

func (*MapObject) SetID

func (o *MapObject) SetID(id string)

func (*MapObject) Sync

func (f *MapObject) Sync() error

func (*MapObject) Write

func (o *MapObject) Write(p []byte)

type MemoryStore

type MemoryStore struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func NewMemoryStoreName

func NewMemoryStoreName(name string) *MemoryStore

func (*MemoryStore) Delete

func (s *MemoryStore) Delete(obj Object) (err error)

func (MemoryStore) Get

func (s MemoryStore) Get(id string, obj Object) error

func (MemoryStore) GetByName

func (s MemoryStore) GetByName(name string, obj Object) error

func (MemoryStore) Name

func (s MemoryStore) Name() string

func (*MemoryStore) Save

func (s *MemoryStore) Save(obj Object) (err error)

func (MemoryStore) Type

func (s MemoryStore) Type() StoreType

type Object

type Object interface {
	ID() string
	SetID(string)

	Sync() error

	Bytes() []byte
	Write(p []byte)

	Decode() error
	Encode() error
}

type Objects

type Objects struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (Objects) HasNext

func (o Objects) HasNext() bool

func (Objects) Len

func (o Objects) Len() int

func (Objects) MarshalJSON

func (o Objects) MarshalJSON() ([]byte, error)

func (Objects) NextPage

func (o Objects) NextPage() int

func (Objects) Total

func (o Objects) Total() int

type RawObject

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

func NewRawObject

func NewRawObject(store Store) *RawObject

func (RawObject) Bytes

func (o RawObject) Bytes() []byte

func (RawObject) Decode

func (f RawObject) Decode() error

func (*RawObject) Encode

func (f *RawObject) Encode() error

func (RawObject) ID

func (o RawObject) ID() string

func (RawObject) IsNew

func (o RawObject) IsNew() bool

func (*RawObject) SetID

func (o *RawObject) SetID(id string)

func (*RawObject) Sync

func (f *RawObject) Sync() error

func (*RawObject) Write

func (o *RawObject) Write(p []byte)

type RefObject

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

RefObject link filename to a file id

func NewRefObject

func NewRefObject(store Store) *RefObject

func (RefObject) Bytes

func (o RefObject) Bytes() []byte

func (RefObject) Decode

func (f RefObject) Decode() error

func (*RefObject) Encode

func (f *RefObject) Encode() error

func (RefObject) ID

func (f RefObject) ID() string

ID file id as data value

func (RefObject) IsNew

func (o RefObject) IsNew() bool

func (RefObject) RefID

func (f RefObject) RefID() string

Name file name as id

func (*RefObject) SetID

func (f *RefObject) SetID(v string)

func (*RefObject) SetRefID

func (f *RefObject) SetRefID(v string)

func (*RefObject) Sync

func (f *RefObject) Sync() error

func (*RefObject) Write

func (o *RefObject) Write(p []byte)

type Store

type Store interface {
	Get(id string, obj Object) error
	Save(Object) error
	Delete(Object) error

	Type() StoreType
}

Store implements store data of objects

var BucketStore Store

BucketStore a store of information about the buckets

func MustStore

func MustStore(name string) Store

type StoreType

type StoreType string
const (
	MemoryStoreType StoreType = "memory"
	LocalStoreType  StoreType = "local"
	BoltDBStoreType StoreType = "boltdb"
)

Jump to

Keyboard shortcuts

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