connectors

package
v0.0.0-...-96f772b Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2016 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Postgres is the postgres string
	Postgres = "postgres"
	// MySql is the mysql string
	MySql = "mysql"
	// SQLite is the sqlite3 string
	SQLite = "sqlite3"
)

Variables

This section is empty.

Functions

func Open

func Open(o Opener) (*sqlx.DB, error)

Open takes an Opener interface and attempts to open a connection to a database.

Types

type Config

type Config struct {
	Encoding string `yaml:"encoding" json:"encoding"`
	Adapter  string `yaml:"adapter" json:"adapter"`
	Database string `yaml:"database" json:"database"`
	Host     string `yaml:"host" json:"host"`
	Username string `yaml:"username" json:"username"`
	Password string `yaml:"password" json:"password"`
	Port     int    `yaml:"port" json:"port"`
	Socket   string `yaml:"socket" json:"socket"`
	Name     string `yaml:"name" json:"name"`
}

Config is the base configuration struct for all database configurations. It is embedded in the more specific config types, PGConfig, MySqlConfig, and SQLiteConfig

func (*Config) GetAdapter

func (c *Config) GetAdapter() string

GetAdapter returns the adapter being used for this configuration.

func (*Config) GetName

func (c *Config) GetName() string

GetName returns the name of the database configuration.

type DB

type DB struct {
	DB      *sqlx.DB
	Adapter string
}

DB wraps a *sqlx.DB and an Adapter string

func NewDB

func NewDB(db *sqlx.DB, adapter string) *DB

NewDB returns a new DB wrapper struct

func (*DB) GetSchema

func (db *DB) GetSchema() (*models.Schema, error)

GetSchema returns a schema based on the adapter being used

type MySQLConfig

type MySQLConfig struct {
	Config   `yaml:",inline"`
	Protocol string `yaml:"protocol" json:"protocol"`
}

MySQLConfig represents a MySql database configuration struct

func MySqlConfigFromConfig

func MySqlConfigFromConfig(config Config) *MySQLConfig

MySqlConfigFromConfig returns a pointer to a MySQLConfig with default values

func NewMySqlConfig

func NewMySqlConfig() *MySQLConfig

NewMySqlConfig returns a pointer to a MySql configuration struct with UseDefaults set to true

func (*MySQLConfig) Open

func (m *MySQLConfig) Open() (*sqlx.DB, error)

open assembles a datasource string and attempts to open a connection to a MySQL server

func (*MySQLConfig) SetDefaults

func (m *MySQLConfig) SetDefaults()

SetDefaults sets default MySQL settings

type Opener

type Opener interface {
	// Sets all defaults for the particular type of database configuration
	SetDefaults()
	// Opens a connection to a database
	Open() (*sqlx.DB, error)
	// Returns the Name of the current database configuration
	GetName() string
	// Returns the Adapter of the interface
	GetAdapter() string
}

Opener is an interface that can open a connection to a database

func GetOpener

func GetOpener(config Config) (Opener, error)

GetOpener returns an Opener interface based on the config given

type PGConfig

type PGConfig struct {
	Config            `yaml:",inline"`
	SSLMode           string `yaml:"ssl_mode" json:"ssl_mode"`
	ConnectionTimeout int    `yaml:"connection_timeout" json:"connection_timeout"`
}

PGConfig represents a Postgres configuration struct

func NewPGConfig

func NewPGConfig() *PGConfig

NewPGConfig returns a pointer to a postgres configuration struct with UseDefaults set to true

func PGConfigFromConfig

func PGConfigFromConfig(config Config) *PGConfig

PGConfigFromConfig sets defaults specific to postgres.

func (*PGConfig) Open

func (pg *PGConfig) Open() (*sqlx.DB, error)

open assembles a datasource string and attempts to open a connection to a postgres/redshift server

func (*PGConfig) SetDefaults

func (pg *PGConfig) SetDefaults()

SetDefaults sets defaults specific to postgres.

type SQLiteConfig

type SQLiteConfig struct {
	Config `yaml:",inline"`
}

SQLiteConfig represents a SQLite configuration

func NewSQLiteConfig

func NewSQLiteConfig() *SQLiteConfig

NewSQLiteConfig returns a SQliteConfig struct with UseDefaults set to true

func SQLiteConfigFromConfig

func SQLiteConfigFromConfig(config Config) *SQLiteConfig

SQLiteConfigFromConfig returns a *SQLiteConfig with defaults

func (*SQLiteConfig) Open

func (lite *SQLiteConfig) Open() (*sqlx.DB, error)

open pens a connection to the SQLite database

func (*SQLiteConfig) SetDefaults

func (lite *SQLiteConfig) SetDefaults()

SetDefaults sets SQLite default settings

type TableNames

type TableNames []string

TableNames is a list of tables in a schema

Jump to

Keyboard shortcuts

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