package module
Version: v0.0.0-...-3641db6 Latest Latest

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

Go to latest
Published: Nov 3, 2014 License: MIT Imports: 10 Imported by: 16



Simple file based storage and querying package.



Package filedb provides simple low-performance file-based storage amd querying.



View Source
const Ext string = ".filedb"

Ext is the extension for filedb files.


View Source
var (
	// CNameFormat represents the collection name format.
	CNameFormat = "%s" + Ext
View Source
var (
	// ErrDBNotFound occurs when a database could not be found.
	ErrDBNotFound = errors.New("database not found; expected existing directory")


This section is empty.


type C

type C struct {
	// contains filtered or unexported fields

C represents a collection of JSON objects.

func (*C) DB

func (c *C) DB() *DB

DB gets the database for this collection.

func (*C) Drop

func (c *C) Drop() error

Drop drops the collection.

func (*C) ForEach

func (c *C) ForEach(fn func(int, []byte) bool) error

ForEach iterates over every item in the collection calling the function for each row. The function should return true if ForEach is to break (stop iterating) at any time.

func (*C) Insert

func (c *C) Insert(o []byte) error

Insert adds a new object to the collection.

func (*C) InsertJSON

func (c *C) InsertJSON(obj interface{}) error

InsertJSON inserts a JSON encoded version of the specified object.

func (*C) Path

func (c *C) Path() string

Path gets the full filepath of the storage for this collection.

func (*C) RemoveEach

func (c *C) RemoveEach(fn func(int, []byte) (bool, bool)) error

RemoveEach calls fn for each record in the collection, removing any for which fn returns true. If stop is returned, processing ceases after the current record has been processed.

func (*C) SelectEach

func (c *C) SelectEach(fn func(int, []byte) (include bool, data []byte, stop bool)) error

SelectEach calls fn for each item in the collection replacing the data if include is true.

    c.SelectEach(func(i int, data []byte) {
	     include := true
      stop := false
      return include, data, stop

If include is false, the record will be omitted. If stop is true, processing will cease after the current record has been processed.

type DB

type DB struct {
	// contains filtered or unexported fields

DB represents a database of collections.

func Dial

func Dial(d string) (*DB, error)

Dial initiates communication with a database.

func (*DB) C

func (db *DB) C(name string) (*C, error)

C refers to a collection of JSON objects.

func (*DB) Close

func (db *DB) Close()

Close closes the database and any open collection files.

func (*DB) ColNames

func (db *DB) ColNames() ([]string, error)

ColNames gets a list of all collections in the database.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL