drivers

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Index

Examples

Constants

View Source
const (
	PSQLDescribeTemplate   = "" /* 172-byte string literal not displayed */
	PSQLConnectionTemplate = "host=%s port=%s user=%s password=%s dbname=%s sslmode=disable"
	PSQLInsertTemplate     = `INSERT INTO %s("%s") VALUES(%s)`
	PSQLShowTablesQuery    = "SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname != 'pg_catalog' AND schemaname != 'information_schema';"
)
View Source
const CreateTable = `` /* 1246-byte string literal not displayed */

Below columns are not yet implemented and removed from table. Add these once implemented. col20 cidr col24 inet col30 line col31 macaddr col32 money

View Source
const (
	DefaultTableCreateQueryKey = ""
)
View Source
const (
	MySQLDescribeTableQuery = "SHOW TABLES;"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver interface {
	ShowTables(db *sql.DB) ([]string, error)
	Connection() string
	Driver() string
	Insert(fields []string, table string) string
	MapField(descriptor FieldDescriptor) Field
	Describe(table string, db *sql.DB) ([]FieldDescriptor, error)
	MultiDescribe(tables []string, db *sql.DB) (map[string][]FieldDescriptor, []string, error)
	GetLatestColumnValue(table, column string, db *sql.DB) (interface{}, error)
}

Driver is the interface should satisfied by a certain driver

func New

func New(f Flags) Driver

New creates a new driver instance based on the flags

type FKDescriptor added in v0.5.0

type FKDescriptor struct {
	ConstraintName    string
	TableName         string
	ColumnName        string
	ForeignTableName  string
	ForeignColumnName string
}

type Field

type Field struct {
	Type   Type
	Length int16
	Enum   []string
}

Field is the possible field definition

type FieldDescriptor added in v0.4.0

type FieldDescriptor struct {
	Field                string
	Type                 string
	Null                 string
	Key                  string
	Length               null.Int
	Default              null.String
	Extra                string
	Precision            null.Int
	Scale                null.Int
	HasDefaultValue      bool
	ForeignKeyDescriptor *FKDescriptor
}

FieldDescriptor represents a field described by the table in the SQL database

type Flags

type Flags struct {
	Username string
	Password string
	Database string
	Host     string
	Port     string
	Driver   string
}

Flags needed by the driver

type MySQL

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

MySQL implementation of the Driver

func (MySQL) Connection

func (m MySQL) Connection() string

Connection returns the specific connection string

func (MySQL) Describe added in v0.5.0

func (MySQL) Describe(table string, db *sql.DB) ([]FieldDescriptor, error)

func (MySQL) Driver

func (m MySQL) Driver() string

Driver returns the name of the driver

func (MySQL) GetLatestColumnValue added in v0.5.0

func (MySQL) GetLatestColumnValue(table, column string, db *sql.DB) (interface{}, error)

func (MySQL) GetTestCase added in v0.5.0

func (MySQL) GetTestCase(name string) (TestCase, error)

func (MySQL) Insert

func (m MySQL) Insert(fields []string, table string) string

Insert inserts the data into

func (MySQL) MapField

func (m MySQL) MapField(descriptor FieldDescriptor) Field

MapField returns the actual fields

func (MySQL) MultiDescribe added in v0.5.0

func (m MySQL) MultiDescribe(tables []string, db *sql.DB) (map[string][]FieldDescriptor, []string, error)

func (MySQL) ShowTables added in v0.4.0

func (m MySQL) ShowTables(db *sql.DB) ([]string, error)

func (MySQL) TestTable added in v0.4.0

func (m MySQL) TestTable(db *sql.DB, testCase, table string) error

TestTable only for test purposes

type Postgres added in v0.4.0

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

func (Postgres) Connection added in v0.4.0

func (p Postgres) Connection() string

func (Postgres) Describe added in v0.5.0

func (p Postgres) Describe(table string, db *sql.DB) ([]FieldDescriptor, error)

func (Postgres) Driver added in v0.4.0

func (p Postgres) Driver() string

func (Postgres) GetLatestColumnValue added in v0.5.0

func (p Postgres) GetLatestColumnValue(table, column string, db *sql.DB) (interface{}, error)

func (Postgres) GetTestCase added in v0.5.0

func (Postgres) GetTestCase(name string) (TestCase, error)

func (Postgres) Insert added in v0.4.0

func (p Postgres) Insert(fields []string, table string) string

func (Postgres) MapField added in v0.4.0

func (p Postgres) MapField(descriptor FieldDescriptor) Field

func (Postgres) MultiDescribe added in v0.5.0

func (p Postgres) MultiDescribe(tables []string, db *sql.DB) (map[string][]FieldDescriptor, []string, error)

func (Postgres) ShowTables added in v0.4.0

func (p Postgres) ShowTables(db *sql.DB) ([]string, error)
Example
createTable()
db, err := getPostgresConnection()
if err != nil {
	return
}
driver := Postgres{}
tables, err := driver.ShowTables(db)
if err != nil {
	log.Printf("Error showing tables : %s", err.Error())
	return
}
for _, table := range tables {
	fmt.Println(table)
}
Output:

func (Postgres) TestTable added in v0.4.0

func (p Postgres) TestTable(db *sql.DB, testCase, table string) error

TestTable only for test purposes

type TestCase added in v0.5.0

type TestCase struct {
	TableToCreateQueryMap map[string]string
	TableCreationOrder    []string
}

TestCase has a map of table to its create table query and table creation order

type Testable added in v0.4.0

type Testable interface {
	GetTestCase(name string) (TestCase, error)
	TestTable(conn *sql.DB, testCase, table string) error
}

func NewTestable added in v0.4.0

func NewTestable(f Flags) Testable

type Type

type Type int16
const (
	String Type = iota
	Int16
	Int32
	Float
	Blob // base64
	Text
	Enum
	Bool
	Json
	Time
	Year
	XML
	UUID
	BinaryString
	Unknown
)

Jump to

Keyboard shortcuts

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