Documentation ¶
Index ¶
- Constants
- Variables
- func BSOIdOk(bId string) bool
- func CollectionNameOk(cName string) bool
- func Int(u int) *int
- func LimitOk(limit int) bool
- func ModifiedToString(modified int) string
- func NewerOk(newer int) bool
- func Now() int
- func OffsetOk(offset int) bool
- func SortIndexOk(sortIndex int) bool
- func String(s string) *string
- func TTLOk(ttl int) bool
- func ValidateBSOId(ids ...string) bool
- type BSO
- type BatchRecord
- type CollectionInfo
- type Config
- type DB
- func (d *DB) BatchAppend(id, cId int, data string) (err error)
- func (d *DB) BatchCreate(cId int, data string) (int, error)
- func (d *DB) BatchExists(id, cId int) (bool, error)
- func (d *DB) BatchLoad(id, cId int) (*BatchRecord, error)
- func (d *DB) BatchPurge(TTL int) (int, error)
- func (d *DB) BatchRemove(id int) error
- func (d *DB) Close()
- func (d *DB) CreateCollection(name string) (cId int, err error)
- func (d *DB) DeleteBSO(cId int, bId string) (int, error)
- func (d *DB) DeleteBSOs(cId int, bIds ...string) (modified int, err error)
- func (d *DB) DeleteCollection(cId int) (int, error)
- func (d *DB) DeleteEverything() (err error)
- func (d *DB) GetBSO(cId int, bId string) (b *BSO, err error)
- func (d *DB) GetBSOModified(cId int, bId string) (modified int, err error)
- func (d *DB) GetBSOs(cId int, ids []string, older int, newer int, sort SortType, limit int, ...) (r *GetResults, err error)
- func (d *DB) GetCollectionId(name string) (id int, err error)
- func (d *DB) GetCollectionModified(cId int) (modified int, err error)
- func (d *DB) GetKey(key string) (string, error)
- func (d *DB) InfoCollectionCounts() (map[string]int, error)
- func (d *DB) InfoCollectionUsage() (map[string]int, error)
- func (d *DB) InfoCollections() (map[string]int, error)
- func (d *DB) InfoQuota() (used, quota int, err error)
- func (d *DB) LastModified() (int, error)
- func (d *DB) Open() (err error)
- func (d *DB) OpenWithConfig(conf *Config) (err error)
- func (d *DB) Optimize(thresholdPercent int) (ItHappened bool, err error)
- func (d *DB) PostBSOs(cId int, input PostBSOInput) (*PostResults, error)
- func (d *DB) PurgeExpired() (removed int, err error)
- func (d *DB) PutBSO(cId int, bId string, payload *string, sortIndex *int, ttl *int) (modified int, err error)
- func (d *DB) SetKey(key, value string) error
- func (d *DB) TouchCollection(cId, modified int) (err error)
- func (d *DB) Usage() (stats *DBPageStats, err error)
- func (d *DB) Vacuum() (err error)
- type DBPageStats
- type GetResults
- type PostBSOInput
- type PostResults
- type PutBSOInput
- type SortType
Constants ¶
const MaxTimestamp = 4070822400000
2099 ... somebody else's problem by then (I hope)
const SCHEMA_0 = `` /* 1573-byte string literal not displayed */
const SCHEMA_1 = `` /* 240-byte string literal not displayed */
Issue #72
Variables ¶
var ( ErrNotFound = errors.New("Not Found") ErrNotImplemented = errors.New("Not Implemented") ErrNothingToDo = errors.New("Nothing to do") ErrInvalidBSOId = errors.New("Invalid BSO Id") ErrInvalidCollectionId = errors.New("Invalid Collection Id") ErrInvalidCollectionName = errors.New("Invalid Collection Name") ErrInvalidPayload = errors.New("Invalid Payload") ErrInvalidSortIndex = errors.New("Invalid Sort Index") ErrInvalidTTL = errors.New("Invalid TTL") ErrInvalidLimit = errors.New("Invalid LIMIT") ErrInvalidOffset = errors.New("Invalid OFFSET") ErrInvalidNewer = errors.New("Invalid NEWER than") )
var (
ErrBatchNotFound = errors.New("Batch Not Found")
)
Functions ¶
func CollectionNameOk ¶
func LimitOk ¶
LimitOk checks limit is within the correct range. Acceptable values are -1 to max int. A limit of 0 would return 0 records
func ModifiedToString ¶
ModifiedToString turns the output of Now(), an integer of milliseconds since the epoch to the sync 1.5's seconds w/ two decimals format
func SortIndexOk ¶
SortIndexOK validates a sortIndex int, the only rule is that it is 9 digits ... :\
func ValidateBSOId ¶
ValidateBSOIds checks if all provided Is are 12 characters long and only contain url safe base64 characters
Types ¶
type BSO ¶
ref: https://docs.services.mozilla.com/storage/apis-1.5.html#basic-storage-object
func (BSO) MarshalJSON ¶
MarshalJSON builds a custom json blob since there is no way good way of turning the Modified int (in milliseconds) into seconds with two decimal places which the api defines as the correct format. meh.
type DB ¶
type DB struct { sync.RWMutex // sqlite database path Path string // contains filtered or unexported fields }
func (*DB) BatchAppend ¶
BatchAppend adds data to the BSOS column for a batch id
func (*DB) BatchCreate ¶
BatchCreate creates a new batch
func (*DB) BatchExists ¶
BatchExists checks if a batch exists without loading all the data from disk
func (*DB) BatchRemove ¶
func (*DB) DeleteBSO ¶
DeleteBSO deletes a single BSO and returns the modified timestamp for the collection
func (*DB) DeleteBSOs ¶
DeleteBSOs deletes multiple BSO. It returns the modified timestamp for the collection on success
func (*DB) DeleteEverything ¶
DeleteEverything will delete all BSOs, record when everything was deleted and vacuum to free up disk pages.
func (*DB) GetBSOModified ¶
func (*DB) GetCollectionModified ¶
func (*DB) InfoCollections ¶
InfoCollections create a map of collection names to last modified times
func (*DB) LastModified ¶
LastModified returns the top level last modified timestamp
func (*DB) OpenWithConfig ¶
func (*DB) Optimize ¶
Optimize recovers disk space by removing empty db pages if the number of free pages makes up more than `threshold` percent of the total pages
func (*DB) PostBSOs ¶
func (d *DB) PostBSOs(cId int, input PostBSOInput) (*PostResults, error)
func (*DB) PurgeExpired ¶
PurgeExpired removes all BSOs that have expired out
func (*DB) PutBSO ¶
func (d *DB) PutBSO(cId int, bId string, payload *string, sortIndex *int, ttl *int) (modified int, err error)
PutBSO creates or updates a BSO
func (*DB) TouchCollection ¶
func (*DB) Usage ¶
func (d *DB) Usage() (stats *DBPageStats, err error)
type DBPageStats ¶
func (*DBPageStats) FreePercent ¶
func (s *DBPageStats) FreePercent() int
FreePercent calculates how much of total space is used up by free pages (empty of data)
type GetResults ¶
GetResults holds search results for BSOs, this is what getBSOs() returns
func (*GetResults) String ¶
func (g *GetResults) String() string
type PostBSOInput ¶
type PostBSOInput []*PutBSOInput
type PostResults ¶
PostBSOs takes a set of BSO and performs an Insert or Update on each of them.
func NewPostResults ¶
func NewPostResults(modified int) *PostResults
func (*PostResults) AddFailure ¶
func (p *PostResults) AddFailure(bId string, reasons ...string)
func (*PostResults) AddSuccess ¶
func (p *PostResults) AddSuccess(bId ...string)
type PutBSOInput ¶
type PutBSOInput struct { Id string `json:"id"` Payload *string `json:"payload,omitempty"` TTL *int `json:"ttl,omitempty"` SortIndex *int `json:"sortindex,omitempty"` }
func NewPutBSOInput ¶
func NewPutBSOInput(id string, payload *string, sortIndex, ttl *int) *PutBSOInput