Documentation
¶
Overview ¶
Package dataset is a go package for managing JSON documents stored on disc
@author R. S. Doiel, <rsdoiel@caltech.edu>
Copyright (c) 2017, Caltech All rights not granted herein are expressly reserved by Caltech.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Examples:
// Create a collection
collection, err := dataset.Create("mystuff", "dataset", GenerateBucketNames("abc", 3))
if err != nil {
log.Fatalf("%s", err)
}
defer collection.Close()
// Add a record
record := map[string]string{"name":"freda","email":"freda@inverness.example.org"}
if err := collection.Create("freda", record); err != nil {
log.Fatalf("%s", err)
}
// Read a record
if err := collection.Read("freda", record); err != nil {
log.Fatalf("%s", err)
}
// Update a record
record["email"] = "freda@zbs.example.org"
if err := collection.Update("freda", record); err != nil {
log.Fatalf("%s", err)
}
// Delete a record
if err := collection.Delete("freda"); err != nil {
log.Fatalf("%s", err)
}
Index ¶
- Constants
- func Delete(name string) error
- func GenerateBucketNames(alphabet string, length int) []string
- type Collection
- func (c *Collection) Close() error
- func (c *Collection) Create(name string, data interface{}) error
- func (c *Collection) CreateAsJSON(name string, src []byte) error
- func (c *Collection) Delete(name string) error
- func (c *Collection) Keys() []string
- func (c *Collection) Read(name string, data interface{}) error
- func (c *Collection) ReadAsJSON(name string) ([]byte, error)
- func (c *Collection) Update(name string, data interface{}) error
- func (c *Collection) UpdateAsJSON(name string, src []byte) error
Constants ¶
const ( Version = "v0.0.1-alpha" License = `` /* 1530-byte string literal not displayed */ )
Variables ¶
This section is empty.
Functions ¶
func GenerateBucketNames ¶
GenerateBucketNames provides a list of permutations of requested length to use as bucket names
Types ¶
type Collection ¶
type Collection struct {
// Version of collection being stored
Version string `json:"verison"`
// Name of collection
Name string `json:"name"`
// Dataset is a directory name that holds collections
Dataset string `json:"dataset"`
// Buckets is a list of bucket names used by collection
Buckets []string `json:"buckets"`
// KeyMap holds the document name to bucket map for the collection
KeyMap map[string]string `json:"keymap"`
}
Collection is the container holding buckets which in turn hold JSON docs
func Create ¶
func Create(name string, bucketNames []string) (*Collection, error)
CreateCollection - create a new collection structure on disc name should be filesystem friendly
func Open ¶
func Open(name string) (*Collection, error)
Open reads in a collection's metadata and returns and new collection structure and err
func (*Collection) Close ¶
func (c *Collection) Close() error
Close closes a collection, writing the updated keys to disc
func (*Collection) Create ¶
func (c *Collection) Create(name string, data interface{}) error
Create a JSON doc from an interface{} and adds it to a collection, if problem returns an error name must be unique
func (*Collection) CreateAsJSON ¶
func (c *Collection) CreateAsJSON(name string, src []byte) error
CreateAsJSON adds a JSON doc to a collection, if problem returns an error name must be unique (treated like a key in a key/value store)
func (*Collection) Delete ¶
func (c *Collection) Delete(name string) error
Delete removes a JSON doc from a collection
func (*Collection) Keys ¶
func (c *Collection) Keys() []string
Keys returns a list of keys in a collection
func (*Collection) Read ¶
func (c *Collection) Read(name string, data interface{}) error
Read finds the record in a collection, updates the data interface provide and if problem returns an error name must exist or an error is returned
func (*Collection) ReadAsJSON ¶
func (c *Collection) ReadAsJSON(name string) ([]byte, error)
ReadAsJSON finds a the record in the collection and returns the JSON source
func (*Collection) Update ¶
func (c *Collection) Update(name string, data interface{}) error
Update JSON doc in a collection from the provided data interface (note: JSON doc must exist or returns an error )
func (*Collection) UpdateAsJSON ¶
func (c *Collection) UpdateAsJSON(name string, src []byte) error
UpdateAsJSON takes a JSON doc and writes it to a collection (note: Record must exist or returns an error)