db

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DatabaseNotSupportedErrMsg is the string used to indicate the provided DB is not supported
	DatabaseNotSupportedErrMsg = "Database not supported"

	// DBSQLite is a string that indicates sqlite is supported
	DBSQLite string = "sqlite"

	// DBPostgres is a string that indicates postgres is supported
	DBPostgres string = "postgres"

	// DBMongoDB is a string that indicates MongoDB is a supported database
	DBMongoDB string = "mongodb"

	// DBMySQL is a string that indicates mysql is supported
	DBMySQL string = "mysql"

	// DefaultSQLiteDBName will be used when user indicates they
	// want to create a SQLite db but do not provide a path/name
	DefaultSQLiteDBName string = "baseball_databank.sqlite3"
)

Variables

View Source
var ErrorDBNotSupported = errors.New(DatabaseNotSupportedErrMsg)

ErrorDBNotSupported is used to inform the caller that the database type the provided is not a supporeted database

Functions

func CreateConnection

func CreateConnection(opts Options) (sqlbuilder.Database, error)

CreateConnection is the public facing function that is responsible for providing a database connection to the outside world. It acts as a proxy fo the db package using the `dbtype` to determine which database connection to return. If somehow the dbtype is value we do not support a DB Not Supported error will be returned

func CreateNoSQLConnection

func CreateNoSQLConnection(opts Options) (db.Database, error)

CreateNoSQLConnection is the public facing function that is responsible for providing a nosql database connection to the outside world. It acts as a proxy fo the db package using the `dbtype` to determine which database connection to return. If somehow the dbtype is value we do not support a DB Not Supported error will be returned

func IsSupportedDB

func IsSupportedDB(s string) bool

IsSupportedDB checks to see if the database name given is one of the dbs supported by Baseball Databank Tools

Types

type CreateDBConnFunc

type CreateDBConnFunc func(Options) (sqlbuilder.Database, error)

CreateDBConnFunc is the type of function that all supported databases must support

type InsertFunc

type InsertFunc func(string, interface{}) error

InsertFunc Inserts the data into the table specified in the first parameter

type NoSQLRepo

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

NoSQLRepo handles interaction between the database and the caller

func (NoSQLRepo) CloseConn

func (r NoSQLRepo) CloseConn() error

CloseConn closes the connection to the database

func (NoSQLRepo) Insert

func (r NoSQLRepo) Insert(tableName string, data interface{}) error

Insert takes a slice of and adds it to the given table

func (NoSQLRepo) Truncate

func (r NoSQLRepo) Truncate(tableName string) error

Truncate takes the name of the table to truncate and returns any errors that occurr

type Options

type Options struct {
	Host    string
	Name    string
	Pass    string
	Path    string
	Port    int
	Type    string
	User    string
	Verbose bool
}

Options are used to connect to the database file or server depending on the type of database being used

func (Options) String

func (o Options) String() string

type Repo

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

Repo is the struct that manages the inserting of data and closing of db connections across the supported databases

func (Repo) CloseConn

func (r Repo) CloseConn() error

CloseConn closes the connection to the database

func (Repo) Insert

func (r Repo) Insert(tableName string, data interface{}) error

Insert takes a slice of and adds it to the given table

func (Repo) Truncate

func (r Repo) Truncate(tableName string) error

Truncate takes the name of the table to truncate and returns any errors that occurr

type Repository

type Repository interface {
	CloseConn() error
	Insert(string, interface{}) error
	Truncate(string) error
}

Repository is the interface used by all of the database objects

func CreateNoSQLRepo

func CreateNoSQLRepo(sd db.Database) Repository

CreateNoSQLRepo creates a Repository object that is connected to the database.

func CreateRepo

func CreateRepo(sd sqlbuilder.Database) Repository

CreateRepo creates a Repositoryobject that is connected to the database.

Jump to

Keyboard shortcuts

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