Documentation ¶
Index ¶
- Constants
- type Driver
- type Field
- type FieldDescriptor
- type Flags
- type MySQL
- func (m MySQL) Connection() string
- func (MySQL) DescribeFields(table string, db *sql.DB) ([]FieldDescriptor, error)
- func (m MySQL) Driver() string
- func (m MySQL) Insert(fields []string, table string) string
- func (m MySQL) MapField(descriptor FieldDescriptor) Field
- func (m MySQL) ShowTables(db *sql.DB) ([]string, error)
- func (m MySQL) TestTable(db *sql.DB, table string) error
- type Postgres
- func (p Postgres) Connection() string
- func (p Postgres) DescribeFields(table string, db *sql.DB) ([]FieldDescriptor, error)
- func (p Postgres) Driver() string
- func (p Postgres) Insert(fields []string, table string) string
- func (p Postgres) MapField(descriptor FieldDescriptor) Field
- func (p Postgres) ShowTables(db *sql.DB) ([]string, error)
- func (p Postgres) TestTable(db *sql.DB, table string) error
- type Testable
- type Type
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 (
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 DescribeFields(table string, db *sql.DB) ([]FieldDescriptor, error) }
Driver is the interface should satisfied by a certain driver
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 }
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 ¶
Connection returns the specific connection string
func (MySQL) DescribeFields ¶ added in v0.4.0
func (MySQL) MapField ¶
func (m MySQL) MapField(descriptor FieldDescriptor) Field
MapField returns the actual fields
type Postgres ¶ added in v0.4.0
type Postgres struct {
// contains filtered or unexported fields
}
func (Postgres) Connection ¶ added in v0.4.0
func (Postgres) DescribeFields ¶ added in v0.4.0
Example ¶
createTable() db, err := getConnection() if err != nil { return } driver := Postgres{} fields, err := driver.DescribeFields("pg_data_types", db) if err != nil { log.Printf("Error describing table : %s", err.Error()) return } for _, field := range fields { fmt.Println(fmt.Sprintf("Column name %s Field Type %s", field.Field, field.Type)) }
Output:
func (Postgres) MapField ¶ added in v0.4.0
func (p Postgres) MapField(descriptor FieldDescriptor) Field
func (Postgres) ShowTables ¶ added in v0.4.0
Example ¶
createTable() db, err := getConnection() 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:
type Testable ¶ added in v0.4.0
func NewTestable ¶ added in v0.4.0
Click to show internal directories.
Click to hide internal directories.