mysql

package
v0.0.0-...-822da2f Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2017 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

package mysql gathers data about a database from MySQL's information schema and generates Go code using this data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Import

func Import() string

ImportString returns the import string for importing the mysql db driver.

func New

func New(server, user, password, database string) (dbsql2go.DBer, error)

New connects to the database's information_schema using the supplied username and password. The user must have sufficient privileges.

Types

type Column

type Column struct {
	Name             string
	OrdinalPosition  uint64
	Default          sql.NullString
	IsNullable       string
	DataType         string
	CharMaxLen       sql.NullInt64
	CharOctetLen     sql.NullInt64
	NumericPrecision sql.NullInt64
	NumericScale     sql.NullInt64
	CharacterSet     sql.NullString
	Collation        sql.NullString
	Typ              string
	Key              string
	Extra            string
	Privileges       string
	Comment          string
	// contains filtered or unexported fields
}

Column holds all information about the columns in a database as provided by MySQL's information schema.

func (*Column) Go

func (c *Column) Go() []byte

func (*Column) SetFieldName

func (c *Column) SetFieldName()

SetFieldName sets the column's field name; the name of the field in the table struct in which this column's value will be put.

type Constraint

type Constraint struct {
	Name     string         // Name of the constraint
	Type     string         // Constraint type
	Table    string         // Table of the constraint
	Column   string         // Column tyhe constraint is on
	Seq      int            // Sequence number for composite constraints
	USeq     sql.NullInt64  // Position in Unique Constraint.
	RefTable sql.NullString // Table the constraint refers to for Foreign Keys
	RefCol   sql.NullString // Column on the refered to table of the constraint for Foreign Keys.
}

Constraint is data from key_column_usage and table_constraints

type DB

type DB struct {
	Conn *sql.DB
	Name string
	// contains filtered or unexported fields
}

func (*DB) Get

func (m *DB) Get() error

Get retrieves all of the table, view, index, and constraint info for a database. The tables will have information about their constraints and indexes. None of the other Get or Update methods need to be called when using this method.

func (*DB) GetConstraints

func (m *DB) GetConstraints() error

func (*DB) GetIndexes

func (m *DB) GetIndexes() error

GetIndexes gets the information about the databases indexes. This includes key column and constraint info so that indexes with constraints, i.e. primary keys, foreign keys, and unique can be properly identified.

Any index not in the key_column_constraint is a non-unique, non-key index.

func (*DB) GetTables

func (m *DB) GetTables() error

func (*DB) GetViews

func (m *DB) GetViews() error

func (*DB) Tables

func (m *DB) Tables() []dbsql2go.Tabler

Tables returns information about all of the tables in a databasse; this includes views but not view specific information like its definition.

func (*DB) UpdateTableConstraints

func (m *DB) UpdateTableConstraints() error

UpdateTableConstraints updates the Tables with their respective Constraint information. The Constraints must be retrieved first or nothing will be done.

func (*DB) UpdateTableIndexes

func (m *DB) UpdateTableIndexes()

UpdateTableIndexes updates the Tables with their respective Index information. The Indexes must be retrieved first or nothing will be done.

func (*DB) Views

func (m *DB) Views() []dbsql2go.Viewer

type Index

type Index struct {
	Type         string
	Schema       string
	NonUnique    int64
	SeqInIndex   int64
	Table        string
	Column       string
	Collation    sql.NullString
	Cardinality  sql.NullInt64
	SubPart      sql.NullInt64
	Packed       sql.NullString
	Nullable     string
	Comment      sql.NullString
	IndexComment string
	// contains filtered or unexported fields
}

func (*Index) Name

func (i *Index) Name() string

Name returns the index's name.

type Table

type Table struct {
	Typ    string
	Engine sql.NullString

	Comment string
	// contains filtered or unexported fields
}

func NewTable

func NewTable() *Table

NewTable creates a new Table. It is intended to ensure that the Table is ready for usage.

func (*Table) Collation

func (t *Table) Collation() string

Collation returns the table's collation.

func (*Table) ColumnNames

func (t *Table) ColumnNames() []string

ColumnNames returns the names of all the columns in the table.

func (*Table) Constraints

func (t *Table) Constraints() []dbsql2go.Constraint

Constraints returns information on all of the tables keys/constraints.

func (*Table) Definition

func (t *Table) Definition(w io.Writer) error

Definition writes the struct definition.

func (*Table) DeletePKMethod

func (t *Table) DeletePKMethod(w io.Writer) (n int64, err error)

DeletePKMethod generates the method for deleting a table row using its PK and writes it to the writer. The number of bytes written is returned. If an error occurs that is returned along with the number of bytes written. If the table does not have a primary key, nothing will be written and the error will be nil as this is not an error.

func (*Table) Go

func (t *Table) Go(w io.Writer) error

Go creats the struct definition and methods for handling single row SQL queries that the struct will use. A struct represents one row of data. Any operations that result in more than one row are handled by something other than the table's struct.

func (*Table) GoFmt

func (t *Table) GoFmt(w io.Writer) error

GoFmt creates a formatted struct definition and methods and returns the resulting bytes.

func (*Table) Indexes

func (t *Table) Indexes() []dbsql2go.Index

Indexes returns information on all of the tables indexes.

func (*Table) InsertMethod

func (t *Table) InsertMethod(w io.Writer) (n int64, err error)

InsertMethod generates the method for inserting the Table's data into the db table as a row. The number of bytes written to the writer is returned along with any error that may occur, if any. If the table is a view, no insert method will be generated.

func (*Table) IsView

func (t *Table) IsView() bool

IsView returns whether or not this table is actually a view.

func (*Table) Name

func (t *Table) Name() string

Name returns the name of the table.

func (*Table) NonAutoIncrementColumnNames

func (t *Table) NonAutoIncrementColumnNames() []string

NonAutoIncrementColumnNames returns the names of all the auto-increment columns in the table TODO: is this still necessary?

func (*Table) NonPKColumnNames

func (t *Table) NonPKColumnNames() []string

NonPKColumnNames returns the names of all the non-pk columns in the table TODO: is this still necessary?

func (*Table) PK

func (t *Table) PK() *dbsql2go.Constraint

PK returns a tables primary key information, if it has a primary key, or nil if it doesn't have a primary key

func (*Table) Schema

func (t *Table) Schema() string

Schema returns the table's schema.

func (*Table) SelectInRangeFunc

func (t *Table) SelectInRangeFunc(w io.Writer) (n int64, err error)

SelectInRangeSQL creates in range SELECT funcs for the table if it has a primary key. Tables without priamry keys wiill have nothing written to the writer and 0 will be returned for the number of bytes written along with nil for the error. Any error encountered is written along with the number of bytes for the table.

func (*Table) SelectPKMethod

func (t *Table) SelectPKMethod(w io.Writer) (n int64, err error)

SelectPKMethod generates the method for selecting a table row using its PK and writes it to the writer. The number of bytes written is returned. If an error occurs that is returned along with the number of bytes written. If the table does not have a primary key, nothing will be written and the error will be nil as this is not an error.

func (*Table) StructName

func (t *Table) StructName() string

StructName returns the name of the Go struct for this table.

func (*Table) UpdateMethod

func (t *Table) UpdateMethod(w io.Writer) (n int64, err error)

UpdateMethod generates the method for updatating a table row using its PK and writes it to the writer. The number of bytes written is returned. If an error occurs that is returned along with the number of bytes written. If the table does not have a primary key, nothing will be written and the error will be nil as this is not an error.

type View

type View struct {
	Table               string
	ViewDefinition      string
	CheckOption         string
	IsUpdatable         string
	Definer             string
	SecurityType        string
	CharacterSetClient  string
	CollationConnection string
}

func (*View) Name

func (v *View) Name() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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