Documentation ¶
Overview ¶
package mysql gathers data about a database from MySQL's information schema and generates Go code using this data.
Index ¶
- func Import() string
- func New(server, user, password, database string) (dbsql2go.DBer, error)
- type Column
- type Constraint
- type DB
- func (m *DB) Get() error
- func (m *DB) GetConstraints() error
- func (m *DB) GetIndexes() error
- func (m *DB) GetTables() error
- func (m *DB) GetViews() error
- func (m *DB) Tables() []dbsql2go.Tabler
- func (m *DB) UpdateTableConstraints() error
- func (m *DB) UpdateTableIndexes()
- func (m *DB) Views() []dbsql2go.Viewer
- type Index
- type Table
- func (t *Table) Collation() string
- func (t *Table) ColumnNames() []string
- func (t *Table) Constraints() []dbsql2go.Constraint
- func (t *Table) Definition(w io.Writer) error
- func (t *Table) DeletePKMethod(w io.Writer) (n int64, err error)
- func (t *Table) Go(w io.Writer) error
- func (t *Table) GoFmt(w io.Writer) error
- func (t *Table) Indexes() []dbsql2go.Index
- func (t *Table) InsertMethod(w io.Writer) (n int64, err error)
- func (t *Table) IsView() bool
- func (t *Table) Name() string
- func (t *Table) NonAutoIncrementColumnNames() []string
- func (t *Table) NonPKColumnNames() []string
- func (t *Table) PK() *dbsql2go.Constraint
- func (t *Table) Schema() string
- func (t *Table) SelectInRangeFunc(w io.Writer) (n int64, err error)
- func (t *Table) SelectPKMethod(w io.Writer) (n int64, err error)
- func (t *Table) StructName() string
- func (t *Table) UpdateMethod(w io.Writer) (n int64, err error)
- type View
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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) 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 ¶
func (*DB) Get ¶
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 (*DB) GetIndexes ¶
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) Tables ¶
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 ¶
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.
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 }
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) ColumnNames ¶
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 ¶
Definition writes the struct definition.
func (*Table) DeletePKMethod ¶
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 ¶
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 ¶
GoFmt creates a formatted struct definition and methods and returns the resulting bytes.
func (*Table) InsertMethod ¶
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) NonAutoIncrementColumnNames ¶
NonAutoIncrementColumnNames returns the names of all the auto-increment columns in the table TODO: is this still necessary?
func (*Table) NonPKColumnNames ¶
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) SelectInRangeFunc ¶
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 ¶
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 ¶
StructName returns the name of the Go struct for this table.
func (*Table) UpdateMethod ¶
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.