ivy

package module
v0.0.0-...-65c56e4 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2015 License: MIT Imports: 8 Imported by: 3

README

Keywords: Golang, go, database, DBMS, JSON

Ivy - A simple, file-based Database Management System (DBMS) for Go

Ivy is a database management system that stores each record as a JSON file. It can be embedded into your program and is safe to use in goroutines (it uses mutexes) as long as each goroutine shares the database connection. This makes it ok to use in a web application.

Features

  • Pure Go
  • Goroutine safe (as long as each goroutine shares the database connection)
  • Can utilize indexes for faster queries
  • Embeddable
  • Database records are stored as json files, making for easy external access

How to install

go get github.com/jameycribbs/ivy

How to use

Check out example.go in the examples directory. For a more comprehensive example of how to use Ivy in a web application, check out Pythia.

Contributions welcome!

Pull requests/forks/bug reports all welcome, and please share your thoughts, questions and feature requests in the Issues section or via Email.

Documentation

Overview

Package ivy provides a simple, file-based Database Management System (DBMS) that can be used in Go programs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

Type DB is a struct representing the database connection.

func OpenDB

func OpenDB(dbPath string, fieldsToIndex map[string][]string) (*DB, error)

OpenDB initializes an ivy database. It returns a pointer to a DB struct and any error encountered.

func (*DB) Close

func (db *DB) Close()

Close closes an ivy database.

func (*DB) Create

func (db *DB) Create(tblName string, rec interface{}) (string, error)

Create creates a new record for the specified table. It takes a table name, and a struct representing the record data. It returns the id of the newly created record and any error encountered.

func (*DB) Delete

func (db *DB) Delete(tblName string, fileId string) error

Delete deletes a record for the specified table. It takes a table name and the record id of the record to be deleted.. It returns any error encountered.

func (*DB) Find

func (db *DB) Find(tblName string, rec Record, fileId string) error

Find loads up a Record struct with the record corresponding to a supplied id. It takes a table name, a pointer to a Record struct, and an id specifying the record to find. It populates the Record struct attributes with values from the found record. It returns any error encountered.

func (*DB) FindAllIds

func (db *DB) FindAllIds(tblName string) ([]string, error)

FindAllIds return all ids for the specified table name. It takes a table name. It returns a slice of ids and any error encountered.

func (*DB) FindAllIdsForField

func (db *DB) FindAllIdsForField(tblName string, searchField string, searchValue string) ([]string, error)

FindAllIdsForField returns all record ids that match the supplied search criteria. It takes a table name, a field name to search on, and a value to search for. It returns a slice of record ids and any error encountered.

func (*DB) FindAllIdsForTags

func (db *DB) FindAllIdsForTags(tblName string, searchTags []string) ([]string, error)

FindAllIdsForTag returns all record ids that match the all of the supplied search tags. It takes a table name, and a slice of tags to search for. It returns a slice of record ids and any error encountered.

func (*DB) FindFirstIdForField

func (db *DB) FindFirstIdForField(tblName string, searchField string, searchValue string) (string, error)

FindFirstIdForField returns the first record id that matches the supplied search criteria. It takes a table name, a field name to search on, and a value to search for. It returns a record id and any error encountered.

func (*DB) Update

func (db *DB) Update(tblName string, rec interface{}, fileId string) error

Update updates a record for the specified table. It takes a table name, a struct representing the record data, and the record id of the record to be changed. It returns any error encountered.

type Record

type Record interface {
	AfterFind(*DB, string)
}

Type Record is an interface that your table model needs to implement. The AfterFind method is a callback that will run inside the Find method, right after the record is found and populated. This method will be passed the database connection and the record id of the record just found. In your implementation of this method, you should convert the record interface back to it's original type. Take a look at example.go in the examples directory for a look at how to do this.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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