tartara

package module
v0.0.0-...-2da1ed0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2015 License: GPL-2.0 Imports: 4 Imported by: 0

README

tartara

Object oriented database

WARNING: Ultra beta prototype

Getting started

// Define a document:
type Fruit struct {
	Document
	Name  string
	Color string
}

// Define a collection:
var Fruits = &Collection{
	Name: "Fruits",
	Path: "/tartara/db1/fruits/",
	Index: make(map[string]DocumentInterface),
}

// Insert a document:
var apple = &Fruit{
	Name:  "Apple",
	Color: "Green",
}

Fruits.Insert(apple)

// Retrieve a document:
fruit := Fruits.FindById("8264535c0c4e9c6c335635c4026a8022").(*Fruit)

Extending collection

Good to avoid type cast: Users.Find("j9983") instead of Users.Find("j9983").(*User)

type User struct {
	Document
	Nick        string
	Email       string
	Password    string
}

type UsersCollection struct {
	Collection
}

// Extension:
func (this *UsersCollection) FindById(id string) *User {
	return Users.Collection.FindById(id).(*User)
}

// Instanciate collection:
var Users = UsersCollection{
	Collection{
		Path:  "/tartara/db1/users/",
		Index: make(map[string]DocumentInterface),
	},
}


Documentation

Index

Constants

View Source
const (
	MOD = os.FileMode(0744)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

type Collection struct {
	Path     string
	Document DocumentInterface
	Index    map[string]DocumentInterface
}

func (*Collection) FindById

func (this *Collection) FindById(id string) DocumentInterface

func (*Collection) Insert

func (this *Collection) Insert(document DocumentInterface) bool

type CollectionInterface

type CollectionInterface interface {
	FindById(id string) DocumentInterface
	Insert(document DocumentInterface) bool
}

type Document

type Document struct {
	Id string
}

func (*Document) GenerateId

func (this *Document) GenerateId() bool

func (*Document) Get

func (this *Document) Get(key string) string

func (*Document) GetId

func (this *Document) GetId() string

func (*Document) Inc

func (this *Document) Inc(key string, value int)

func (*Document) Set

func (this *Document) Set(key string, value string)

type DocumentInterface

type DocumentInterface interface {
	Set(key string, value string)
	Get(key string) string
	Inc(key string, value int)
	GenerateId() bool
	GetId() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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