-- import "github.com/autom8ter/mappy"
var DefaultOpts = &Opts{
Path: "/tmp/mappy",
Restore: true,
}
var Done = errors.New("mappy: done")
type BackupOpts struct {
Dest io.Writer
}
type Bucket interface {
Key() interface{}
Path() []interface{}
NewRecord(opts *RecordOpts) *Record
Nest(key interface{}) Bucket
NestedBuckets() []Bucket
Del(opts *DelOpts) error
Flush(opts *FlushOpts) error
Count(opts *LenOpts) int
Get(opts *GetOpts) (value *Record, ok bool)
Set(opts *SetOpts) (*Record, error)
View(opts *ViewOpts) error
OnChange(fns ...ChangeHandlerFunc)
}
type BucketOpts struct {
Path []string
GlobalId string
}
type ChangeHandlerFunc func(bucket Bucket, log *Log) error
type CloseOpts struct {
}
type DelOpts struct {
Key interface{}
}
type DestroyOpts struct {
}
type FlushOpts struct {
}
type GetOpts struct {
Key interface{}
}
type LenOpts struct {
}
type Log struct {
Sequence int
Op Op
Record *Record
CreatedAt time.Time
}
type Mappy interface {
Bucket
GetRecord(globalId string) (*Record, bool)
GetBucket(path []interface{}) Bucket
Close(opts *CloseOpts) error
DestroyLogs(opts *DestroyOpts) error
ReplayLogs(opts *ReplayOpts) error
BackupLogs(opts *BackupOpts) (int64, error)
}
func Open(opts *Opts) (Mappy, error)
type Op int
const (
DELETE Op = 2
SET Op = 3
)
type Opts struct {
Path string
Restore bool
}
type Record struct {
Key interface{} `json:"key"`
Val interface{} `json:"val"`
BucketPath []interface{} `json:"bucketPath"`
GloablId string `json:"globalId"`
UpdatedAt time.Time `json:"updatedAt"`
}
func NewRecord(opts *RecordOpts) *Record
type RecordOpts struct {
Key interface{}
Val interface{}
}
type ReplayFunc func(bucket Bucket, lg *Log) error
type ReplayOpts struct {
Min int
Max int
Fn ReplayFunc
}
type RestoreOpts struct {
}
type SetOpts struct {
Record *Record
}
type ViewFunc func(bucket Bucket, record *Record) error
type ViewOpts struct {
ViewFn ViewFunc
}