dba

package
v0.0.0-...-f7b13be Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2016 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package dba is an singleton that manages databases as would a Database Administrator.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddMongoDB

func AddMongoDB(m *MongoDB)

AddMongoDB adds a MongoDB database object to the db package.

func AddRedisDB

func AddRedisDB(r *RedisDB)

AddRedisDB adds a Redis database client to the db package.

func AddSQL

func AddSQL(s *SQL)

AddSQL adds a sql database object to the singleton DatabaseAdmin's databases.

func BSONID

func BSONID(id string) (bson.ObjectId, error)

BSONID takes a string ID and converts it to a bson.ObjectId. If the string cannot be converted an error is returned.

func GORP

func GORP(name string) *gorp.DbMap

GORP takes a database name to search all SQL databases the db package currently maintains and returns a pointer to a gorp.DbMap instance if found. gorp.DbMap represents an SQL orm-ish driver for multiple different SQL databases (sqlite, mysql, postgres). If no database is found nil is returned.

func MGO

func MGO(name string) *mgo.Database

MGO takes a database name to search all mongodb databases the db package currently maintains and returns a pointer to a mgo.Database instance if found. mgo.Database represents a mongodb orm-ish driver for executing queries. If no database is found nil is returned.

func RedisClient

func RedisClient(db int64) *redis.Client

RedisClient takes a database name to search all redis databases the db package currently maintains and returns a pointer to a redis.Client instance if found. redis.Client represents a RedisClient client for executing queries. If no database is found nil is returned.

Types

type Database

type Database interface {
	Dial(name string) error
	Name() string
	Close()
}

Database describes a methods to connect and close database connections.

func All

func All() []Database

All returns all the databases this singleton DatabaseAdmin maintains.

type DatabaseAdmin

type DatabaseAdmin struct {
	Mongo []Database
	Redis []Database
	SQL   []Database
}

DatabaseAdmin represents a database administrator object who's duty is to maintain all database values, connections, and state.

func (*DatabaseAdmin) AddMongoDB

func (d *DatabaseAdmin) AddMongoDB(m *MongoDB)

AddMongoDB adds a MongoDB database object to the DatabaseAdmin databases.

func (*DatabaseAdmin) AddRedisDB

func (d *DatabaseAdmin) AddRedisDB(r *RedisDB)

AddRedisDB adds a Redis database object to the DatabaseAdmin databases.

func (*DatabaseAdmin) AddSQL

func (d *DatabaseAdmin) AddSQL(s *SQL)

AddSQL adds a sql database object to the DatabaseAdmin databases.

func (*DatabaseAdmin) All

func (d *DatabaseAdmin) All() []Database

All returns all the databases this DatabaseAdmin maintains.

func (DatabaseAdmin) GORP

func (d DatabaseAdmin) GORP(name string) *gorp.DbMap

GORP takes a database name to search all SQL databases DatabaseAdmin currently maintains and returns a pointer to a gorp.DbMap instance if found. gorp.DbMap represents an SQL orm-ish driver for multiple different SQL databases (sqlite, mysql, postgres). If no database is found nil is returned.

func (DatabaseAdmin) MGO

func (d DatabaseAdmin) MGO(name string) *mgo.Database

MGO takes a database name to search all mongodb databases db.DBA currently maintains and returns a pointer to a mgo.Database instance if found. mgo.Database represents a mongodb orm-ish driver for executing queries. If no database is found nil is returned.

func (DatabaseAdmin) RedisClient

func (d DatabaseAdmin) RedisClient(db int64) *redis.Client

RedisClient takes a database name to search all redis databases db.DBA currently maintains and returns a pointer to a redis.Client instance if found. redis.Client represents a redis driver for executing queries. If no database is found nil is returned.

type MongoDB

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

MongoDB describes a mongodb database object.

func NewMongoDB

func NewMongoDB(name, user, pass, addr string) (*MongoDB, error)

NewMongoDB creates a new mongodb database object.

func (*MongoDB) Close

func (m *MongoDB) Close()

Close satisfies the Database interface. The mongodb database object closes the connection the Dial method created.

func (*MongoDB) Dial

func (m *MongoDB) Dial(name string) error

Dial satisfies the Database interface. The mongodb database object attempts to dial and start a session with a local or remote MongoDB instance.

func (*MongoDB) Name

func (m *MongoDB) Name() string

Name satisfies the Database interface. The mongodb database object returns the name of the last database the Dial method attempted to connect with.

type RedisDB

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

RedisDB describes a redis database object.

func NewRedis

func NewRedis(db int64, user, pass, addr string, poolSize int) (*RedisDB, error)

NewRedis creates a new redis database object.

func (*RedisDB) Close

func (r *RedisDB) Close()

Close satisfies the Database interface. The redis database object closes the connection the Dial method created.

func (*RedisDB) Dial

func (r *RedisDB) Dial(name string) error

Dial satisfies the Database interface. The Redis database object attempts to dial and start a session with a local or remote Redis instance.

func (*RedisDB) Name

func (r *RedisDB) Name() string

Name satisfies the Database interface. The redis database object returns the name of the last database the Dial method attempted to connect with.

type SQL

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

SQL describes an sql database object.

func NewSQL

func NewSQL(name, user, pass, addr, driver string) (*SQL, error)

NewSQL creates a new sql database object.

func (*SQL) Close

func (s *SQL) Close()

Close satisfies the Database interface. The sql database object closes the connection the Dial method created.

func (*SQL) Dial

func (s *SQL) Dial(name string) error

Dial satisfies the Database interface. The sql database object attempts to dial and start a session with a local or remote sql instance.

func (*SQL) Name

func (s *SQL) Name() string

Name satisfies the Database interface. The sql database object returns the name of the last database the Dial method attempted to connect with.

Jump to

Keyboard shortcuts

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