hyperdb

package
v0.0.0-...-6e72739 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2014 License: MIT Imports: 11 Imported by: 0

README

HyperDB

Documentation

godoc.org/github.com/apokalyptik/go/database/hyperdb

Example Usage

var hdb *hyperdb.DB
var dbHandle *sql.DB
hdb = hyperdb.New("dc1")
hdb.AddServer(hyperdb.Server{
  Dataset: "users",
  Datacenter: "dc1",
  // etc...
})
dbh = hyperdb.Read("users")

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidConfigType = errors.New("Invalid configuration type")

ErrInvalidConfigType tells you that you specified a configuration type which is invalid. Helpful, I know. At the time of this writing all that is supported is json, and so you probably intend (or have) to use that.

Functions

This section is empty.

Types

type DB

type DB struct {
	CacheReadServerFor time.Duration
	// contains filtered or unexported fields
}

DB consumes Server structs for configuration, and uses the contained information to provide a lookup mechanism for getting *sql.DB pointers that allows for multi datacenter, weighted read, and write server support

func New

func New(datacenter string) *DB

New returns a new HyperDB object

func ReadFile

func ReadFile(datacenter, path string, kind ...string) (*DB, error)

ReadFile accepts a path and optional kind in additional to the stantard New function and its datacenter parameter. The path should be a path to a real file that is readable and contains the proper data in the proper format. The only "kind" that is supported right now is "json".

For json the config file should be formatted as follows:

 { ds: "users", dc: "dfw" [...] }
 { ds: "users", dc: "dfw" [...] }
	[...]

func (*DB) AddServer

func (d *DB) AddServer(server Server)

AddServer tells HyperDB to consume a server and add it to the lookup lists

func (*DB) Read

func (d *DB) Read(dataset string) *sql.DB

Look up a read server, and hand back a pointer to a query-able interface.

func (*DB) Write

func (d *DB) Write(dataset string) *sql.DB

Look up the write server, and hand back a pointer to a query-able interface

type Server

type Server struct {
	Dataset       string `json:"ds"`
	Datacenter    string `json:"dc"`
	ReadPriority  int    `json:"read"`
	WritePriority int    `json:"write"`
	WANAddress    string `json:"wan"`
	LANAddress    string `json:"lan"`
	Database      string `json:"db"`
	Username      string `json:"user"`
	Password      string `json:"pw"`
	// contains filtered or unexported fields
}

Server is the unit of configuration for HyperDB. From this structure we can determine which servers in which locations you can, or should, run your query against.

Jump to

Keyboard shortcuts

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