drivers

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2016 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildQueryString

func BuildQueryString(user, pass, dbname, host string, port int, sslmode string) string

BuildQueryString for Postgres

Types

type MockDriver

type MockDriver struct{}

MockDriver is a mock implementation of the bdb driver Interface

func (*MockDriver) Close

func (m *MockDriver) Close()

Close mimics a database close call

func (*MockDriver) Columns

func (m *MockDriver) Columns(tableName string) ([]bdb.Column, error)

Columns returns a list of mock columns

func (*MockDriver) ForeignKeyInfo

func (m *MockDriver) ForeignKeyInfo(tableName string) ([]bdb.ForeignKey, error)

ForeignKeyInfo returns a list of mock foreignkeys

func (*MockDriver) Open

func (m *MockDriver) Open() error

Open mimics a database open call and returns nil for no error

func (*MockDriver) PrimaryKeyInfo

func (m *MockDriver) PrimaryKeyInfo(tableName string) (*bdb.PrimaryKey, error)

PrimaryKeyInfo returns mock primary key info for the passed in table name

func (*MockDriver) TableNames

func (m *MockDriver) TableNames(exclude []string) ([]string, error)

TableNames returns a list of mock table names

func (*MockDriver) TranslateColumnType

func (m *MockDriver) TranslateColumnType(c bdb.Column) bdb.Column

TranslateColumnType converts a column to its "null." form if it is nullable

func (*MockDriver) UseLastInsertID

func (m *MockDriver) UseLastInsertID() bool

UseLastInsertID returns a database mock LastInsertID compatability flag

type PostgresDriver

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

PostgresDriver holds the database connection string and a handle to the database connection.

func NewPostgresDriver

func NewPostgresDriver(user, pass, dbname, host string, port int, sslmode string) *PostgresDriver

NewPostgresDriver takes the database connection details as parameters and returns a pointer to a PostgresDriver object. Note that it is required to call PostgresDriver.Open() and PostgresDriver.Close() to open and close the database connection once an object has been obtained.

func (*PostgresDriver) Close

func (p *PostgresDriver) Close()

Close closes the database connection

func (*PostgresDriver) Columns

func (p *PostgresDriver) Columns(tableName string) ([]bdb.Column, error)

Columns takes a table name and attempts to retrieve the table information from the database information_schema.columns. It retrieves the column names and column types and returns those as a []Column after TranslateColumnType() converts the SQL types to Go types, for example: "varchar" to "string"

func (*PostgresDriver) ForeignKeyInfo

func (p *PostgresDriver) ForeignKeyInfo(tableName string) ([]bdb.ForeignKey, error)

ForeignKeyInfo retrieves the foreign keys for a given table name.

func (*PostgresDriver) Open

func (p *PostgresDriver) Open() error

Open opens the database connection using the connection string

func (*PostgresDriver) PrimaryKeyInfo

func (p *PostgresDriver) PrimaryKeyInfo(tableName string) (*bdb.PrimaryKey, error)

PrimaryKeyInfo looks up the primary key for a table.

func (*PostgresDriver) TableNames

func (p *PostgresDriver) TableNames(exclude []string) ([]string, error)

TableNames connects to the postgres database and retrieves all table names from the information_schema where the table schema is public. It excludes common migration tool tables such as gorp_migrations

func (*PostgresDriver) TranslateColumnType

func (p *PostgresDriver) TranslateColumnType(c bdb.Column) bdb.Column

TranslateColumnType converts postgres database types to Go types, for example "varchar" to "string" and "bigint" to "int64". It returns this parsed data as a Column object.

func (*PostgresDriver) UseLastInsertID

func (p *PostgresDriver) UseLastInsertID() bool

UseLastInsertID returns false for postgres

Jump to

Keyboard shortcuts

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