examples

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: MIT Imports: 9 Imported by: 1

README

Example datastore implementations

This directory contains simple implementation of the datastore interface

THE CODE IN THIS DIRECTORY IS NOT SAFE TO USE IN ANY APPLICATION!

If you are looking for a more complete persistent implementation of the go-datastore interface, there are several implementations you can choose from:

Documentation

Overview

Package fs is a simple Datastore implementation that stores keys as directories and files, mirroring the key. That is, the key "/foo/bar" is stored as file "PATH/foo/bar/.dsobject".

This means key some segments will not work. For example, the following keys will result in unwanted behavior:

  • "/foo/./bar"
  • "/foo/../bar"
  • "/foo\x00bar"

Keys that only differ in case may be confused with each other on case insensitive file systems, for example in OS X.

This package is intended for exploratory use, where the user would examine the file system manually, and should only be used with human-friendly, trusted keys. You have been warned.

Index

Constants

This section is empty.

Variables

View Source
var ObjectKeySuffix = ".dsobject"

Functions

func NewDatastore

func NewDatastore(path string) (ds.Datastore, error)

NewDatastore returns a new fs Datastore at given `path`

Types

type Datastore

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

Datastore uses a uses a file per key to store values.

func (*Datastore) Batch

func (d *Datastore) Batch(ctx context.Context) (ds.Batch, error)

func (*Datastore) Close

func (d *Datastore) Close() error

func (*Datastore) Delete

func (d *Datastore) Delete(ctx context.Context, key ds.Key) (err error)

Delete removes the value for given key

func (*Datastore) DiskUsage

func (d *Datastore) DiskUsage(ctx context.Context) (uint64, error)

DiskUsage returns the disk size used by the datastore in bytes.

func (*Datastore) Get

func (d *Datastore) Get(ctx context.Context, key ds.Key) (value []byte, err error)

Get returns the value for given key

func (*Datastore) GetSize

func (d *Datastore) GetSize(ctx context.Context, key ds.Key) (size int, err error)

func (*Datastore) Has

func (d *Datastore) Has(ctx context.Context, key ds.Key) (exists bool, err error)

Has returns whether the datastore has a value for a given key

func (*Datastore) KeyFilename

func (d *Datastore) KeyFilename(key ds.Key) string

KeyFilename returns the filename associated with `key`

func (*Datastore) Put

func (d *Datastore) Put(ctx context.Context, key ds.Key, value []byte) (err error)

Put stores the given value.

func (*Datastore) Query

func (d *Datastore) Query(ctx context.Context, q query.Query) (query.Results, error)

Query implements Datastore.Query

func (*Datastore) Sync added in v0.3.0

func (d *Datastore) Sync(ctx context.Context, prefix ds.Key) error

Sync would ensure that any previous Puts under the prefix are written to disk. However, they already are.

Jump to

Keyboard shortcuts

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