Documentation
¶
Index ¶
- Constants
- func DataTypeToFormatString(column *Column) (fieldType string)
- func DataTypeToGoTypeString(column *Column) (fieldType string)
- func Debug(content string, options Options)
- func Debugf(content string, options Options, a ...interface{})
- func DirExists(dirPath string) bool
- func DirIsEmpty(dirPath string) bool
- func EnsureDir(dir string) (e error)
- func Error(content string, options Options)
- func Errorf(content string, options Options, a ...interface{})
- func FetchDirFileNames(dirPath string) (fileNames []string, e error)
- func FetchFile(filePath string) (changesetFileString string, e error)
- func FetchNonDirFileNames(dirPath string) (files []string, e error)
- func FileExists(filePath string) bool
- func FmtGoCode(filePath string) (e error)
- func FormatCode(code string) ([]byte, error)
- func FormatFieldList(src []byte, fieldList *ast.FieldList, pkgName string) (fields []string)
- func GetFuncDeclarationReceiverType(fd *ast.FuncDecl) (expr ast.Expr, e error)
- func GetReceiverTypeName(src []byte, fl interface{}) (name string, funcDef *ast.FuncDecl)
- func HashFileMd5(filePath string) (string, error)
- func HashStringMd5(s string) string
- func Info(content string, options Options)
- func Infof(content string, options Options, a ...interface{})
- func IsString(column *Column) bool
- func IsValidSQLType(str string) bool
- func Log(content string, logLevel LogLevel, options Options)
- func ReadCliInput(reader *bufio.Reader, title string) string
- func RunCommand(name string, args ...string) (stdout string, stderr string, exitCode int)
- func Warn(content string, options Options)
- func Warnf(content string, options Options, a ...interface{})
- func WriteGoCodeToFile(goCode string, filePath string) (e error)
- type CLITable
- type ChangeFile
- type Changeset
- type Column
- type ColumnWithTable
- type Command
- type Config
- type Database
- type DatabaseType
- type Executor
- type Files
- func (f *Files) BuildChangeFile(sqlPath string, ordinal int) (changeFile *ChangeFile, e error)
- func (f *Files) BuildChangeFiles(sqlPaths []string) (changeFiles []ChangeFile, e error)
- func (f *Files) FetchLocalChangesetList(rootPath string) (sqlPaths []string, e error)
- func (f *Files) ScanDir(rootPath string, extension string) (paths []string, e error)
- type GoFileImports
- type GoStruct
- type GoStructField
- type GoStructFieldTag
- type GoStructFields
- type GoStructMethod
- type GoStructMethods
- type IConnector
- type LogLevel
- type Method
- type Options
- type Query
- func (q *Query) AddIndex(table *Table, column *Column) (sql string, e error)
- func (q *Query) AddUniqueIndex(table *Table, column *Column) (sql string, e error)
- func (q *Query) AlterTableCreateColumn(table *Table, column *Column) (sql string, e error)
- func (q *Query) AlterTableDropColumn(table *Table, column *Column) (sql string, e error)
- func (q *Query) ChangeColumn(table *Table, localColumn *Column, remoteColumn *Column) (sql string, e error)
- func (q *Query) CreateChangeSQL(localSchema *Database, remoteSchema *Database) (sql string, e error)
- func (q *Query) CreateColumn(column *Column) (sql string, e error)
- func (q *Query) CreateTable(table *Table) (sql string, e error)
- func (q *Query) CreateTableChangeSQL(localTable *Table, remoteTable *Table) (sql string, e error)
- func (q *Query) DropIndex(table *Table, column *Column) (sql string, e error)
- func (q *Query) DropTable(table *Table) (sql string, e error)
- func (q *Query) DropUniqueIndex(table *Table, column *Column) (sql string, e error)
- type Server
- type SortedColumns
- type SortedTables
- type Table
Constants ¶
const ( // OptLogInfo triggers verbose logging OptLogInfo = 1 << iota // OptLogDebug triggers extremely verbose logging OptLogDebug // OptSilent suppresses all logging OptSilent // OptReverse reverses the function OptReverse // OptSummary shows a summary of the actions instead of a raw stdout dump OptSummary // OptClean cleans OptClean // OptForce forces OptForce )
Variables ¶
This section is empty.
Functions ¶
func DataTypeToFormatString ¶ added in v1.5.0
DataTypeToFormatString converts a database type to its equivalent golang datatype
func DataTypeToGoTypeString ¶ added in v1.5.0
DataTypeToGoTypeString converts a database type to its equivalent golang datatype
func DirIsEmpty ¶ added in v1.5.0
func FetchDirFileNames ¶
FetchDirFileNames fetches returns a slice of strings of the name of the directories in a directory (non-recursive)
func FetchNonDirFileNames ¶
FetchNonDirFileNames returns a list of files in a directory that are only regular files
func FileExists ¶ added in v1.5.0
func FormatCode ¶ added in v1.5.0
FormatCode formats the code
func FormatFieldList ¶ added in v1.5.0
FormatFieldList returns a list of formatted list of fields
func GetFuncDeclarationReceiverType ¶ added in v1.5.0
GetFuncDeclarationReceiverType returns the receiver type of a function declaration
func GetReceiverTypeName ¶ added in v1.5.0
GetReceiverTypeName returns the name of the receiver type and the declaration
func HashFileMd5 ¶
HashFileMd5 returns an MD5 checksum of the file at `filePath`
func HashStringMd5 ¶ added in v1.5.0
HashStringMd5 genereates an MD5 hash of a string
func IsValidSQLType ¶ added in v1.5.0
DataTypeToGoTypeString converts a database type to its equivalent golang datatype
func RunCommand ¶ added in v1.1.0
RunCommand runs a system command
func WriteGoCodeToFile ¶ added in v1.5.0
WriteGoCodeToFile writes a string of golang code to a file and then formats it with `go fmt`
Types ¶
type CLITable ¶ added in v1.5.0
type CLITable struct {
// contains filtered or unexported fields
}
func NewCLITable ¶ added in v1.5.0
type ChangeFile ¶
type ChangeFile struct {
ID int64
DateCreated int64
Hash string
Name string
DVCSetID int64
IsRun bool
IsDeleted bool
Content string
FullPath string
Ordinal int
}
ChangeFile represents both a physical file on the local file system along with the entry in the changefile database
type Changeset ¶
type Changeset struct {
ChangeFiles map[string]ChangeFile
Signature string
}
Changeset represents all of the changes in an environment and their changes
type Column ¶
type Column struct {
Name string `json:"column"`
Position int `json:"position"`
Default string `json:"default"`
IsNullable bool `json:"isNullable"`
IsUnsigned bool `json:"isUnsigned"`
DataType string `json:"dataType"`
MaxLength int `json:"maxLength"`
Precision int `json:"precision"`
CharSet string `json:"charSet"`
Type string `json:"type"`
ColumnKey string `json:"columnKey"`
NumericScale int `json:"numericScale"`
Extra string `json:"extra"`
FmtType string `json:"fmtType"`
GoType string `json:"goType"`
}
Column represents a column in a table
type ColumnWithTable ¶ added in v1.5.0
ColumnWithTable is a column with the table name included
type Config ¶
type Config struct {
ChangeSetPath string `toml:"changesetPath"`
DatabaseType string `toml:"databaseType"`
BasePackage string `toml:"basePackage"`
Enums []string `toml:"enums"`
OneToMany map[string]string `toml:"onetomany"`
OneToOne map[string]string `toml:"onetoone"`
ManyToOne map[string]string `toml:"manytoone"`
Connection struct {
Host string `toml:"host"`
DatabaseName string `toml:"databaseName"`
Username string `toml:"username"`
Password string `toml:"password"`
}
Packages struct {
Cache string `toml:"cache"`
Models string `toml:"models"`
Schema string `toml:"schema"`
Repos string `toml:"repos"`
Services string `toml:"services"`
API string `toml:"api"`
}
Dirs struct {
Dal string `toml:"dal"`
Repos string `toml:"repos"`
Cache string `toml:"cache"`
Models string `toml:"models"`
Schema string `toml:"schema"`
Typescript string `toml:"typescript"`
Services string `toml:"services"`
Definitions string `toml:"definitions"`
API string `toml:"api"`
}
}
Config contains a set of configuration values used throughout the application
type Database ¶
type Database struct {
RunID int64
Name string
Host string `json:"-"`
SortedSetKeys []string
Tables map[string]*Table
Enums map[string][]map[string]interface{}
}
Database represents a database
func ReadSchemaFromFile ¶
ReadSchemaFromFile Unmarshal's database json to a Database object
func (*Database) FindTableByName ¶
FindTableByName finds a table by its name in the database
func (*Database) ToSortedTables ¶ added in v1.5.0
func (d *Database) ToSortedTables() SortedTables
ToSortedTables returns SortedTables
type DatabaseType ¶ added in v1.1.1
type DatabaseType string
DatabaseType is the type of database to be used.
const ( // DatabaseTypeMysql is the MySQL flavor of database DatabaseTypeMysql DatabaseType = "mysql" // DatabaseTypeSqlite is the Sqlite flavor of database DatabaseTypeSqlite DatabaseType = "sqlite" )
type Executor ¶ added in v1.5.0
type Executor struct {
// contains filtered or unexported fields
}
Executor executes commands
func NewExecutor ¶ added in v1.5.0
func NewExecutor(config *Config, connector IConnector) *Executor
NewExecutor returns a new Executor
type Files ¶
type Files struct {
}
Files contains functionality pertaining to files
func (*Files) BuildChangeFile ¶
func (f *Files) BuildChangeFile(sqlPath string, ordinal int) (changeFile *ChangeFile, e error)
BuildChangeFile builds a changeFile object based on a path and an ordinal
func (*Files) BuildChangeFiles ¶
func (f *Files) BuildChangeFiles(sqlPaths []string) (changeFiles []ChangeFile, e error)
BuildChangeFiles returns a collection of ChangeFile objects based on a collection of sql paths
func (*Files) FetchLocalChangesetList ¶
FetchLocalChangesetList gets the contents of the changesets.json file and returns a collection of paths ([]string)
type GoFileImports ¶ added in v1.5.0
type GoFileImports []string
GoFileImports is a collection of imports for a model file
func (*GoFileImports) Append ¶ added in v1.5.0
func (i *GoFileImports) Append(m string)
Append adds to the collection of imports
func (*GoFileImports) Get ¶ added in v1.5.0
func (i *GoFileImports) Get(idx int) string
Get returns an import at an index
func (*GoFileImports) Len ¶ added in v1.5.0
func (i *GoFileImports) Len() int
Len returns the length of the collection of imports
func (*GoFileImports) ToString ¶ added in v1.5.0
func (i *GoFileImports) ToString() string
ToString returns a string representation of imports on a go file
type GoStruct ¶ added in v1.5.0
type GoStruct struct {
Package string
Name string
Fields *GoStructFields
Methods *GoStructMethods
Comments string
Imports *GoFileImports
}
GoStruct represents a model struct
type GoStructField ¶ added in v1.5.0
type GoStructField struct {
Name string
DataType string
Tags []*GoStructFieldTag
Comments string
}
GoStructField is a field on a Model struct
func (*GoStructField) ToString ¶ added in v1.5.0
func (m *GoStructField) ToString() string
ToString returns a tring representation of a go struct field
type GoStructFieldTag ¶ added in v1.5.0
GoStructFieldTag is a tag on a field on a model struct
func (*GoStructFieldTag) ToString ¶ added in v1.5.0
func (t *GoStructFieldTag) ToString() string
ToString returns a string representation of a go struct field tag
type GoStructFields ¶ added in v1.5.0
type GoStructFields []*GoStructField
GoStructFields is a collection of a go struct fields
func (*GoStructFields) Append ¶ added in v1.5.0
func (i *GoStructFields) Append(m *GoStructField)
Append adds to the collection of imports
func (*GoStructFields) Get ¶ added in v1.5.0
func (i *GoStructFields) Get(idx int) *GoStructField
Get returns an import at an index
func (*GoStructFields) Len ¶ added in v1.5.0
func (i *GoStructFields) Len() int
Len returns the length of the collection of imports
type GoStructMethod ¶ added in v1.5.0
GoStructMethod is a method on a struct
type GoStructMethods ¶ added in v1.5.0
type GoStructMethods []*GoStructMethod
GoStructMethods is a collection of go methods on a struct
func (*GoStructMethods) Append ¶ added in v1.5.0
func (g *GoStructMethods) Append(m *GoStructMethod)
Append adds a new struct to the struct collection
func (*GoStructMethods) Get ¶ added in v1.5.0
func (g *GoStructMethods) Get(index int) (m *GoStructMethod)
Get gets a struct at index
func (*GoStructMethods) Len ¶ added in v1.5.0
func (g *GoStructMethods) Len() int
Len returns the number of methods
type IConnector ¶
type IConnector interface {
Connect() (server *Server, e error)
FetchDatabases(server *Server) (databases map[string]*Database, e error)
FetchEnums(server *Server) (enums map[string][]map[string]interface{})
FetchEnum(server *Server, tableName string) []map[string]interface{}
UseDatabase(server *Server, databaseName string) (e error)
FetchDatabaseTables(server *Server, databaseName string) (tables map[string]*Table, e error)
FetchTableColumns(server *Server, databaseName string, tableName string) (columns map[string]*Column, e error)
CreateChangeSQL(localSchema *Database, remoteSchema *Database) (sql string, e error)
CompareEnums(remoteSchema *Database, localSchema *Database, tableName string) (sql string)
}
IConnector defines the shape of a connector to a database
type LogLevel ¶
type LogLevel uint
LogLevel is a custom type for passing the level of logging specified by runtime flags
const ( // LogLevelAlways indicates that a log should always be printed regardless of flags LogLevelAlways LogLevel = 0 // LogLevelError indicates that a log should LogLevelError LogLevel = 1 // LogLevelWarning indicates a potential problem in the system. LogLevelWarning LogLevel = 2 // LogLevelInfo indicates that a log should be shown if the OptVerbose flag is passed LogLevelInfo LogLevel = 3 // LogLevelDebug indicates that a log should be written if the OptVerboseDebug flag is passed LogLevelDebug LogLevel = 4 )
type Method ¶ added in v1.5.0
Method describes code and Documents for a method
type Query ¶
type Query struct{}
Query contains functionality for generating sql queries
func (*Query) AddIndex ¶
AddIndex returns an alter table sql statement that adds an index to a table
func (*Query) AddUniqueIndex ¶
AddUniqueIndex returns an alter table sql statement that adds a unique index to a table
func (*Query) AlterTableCreateColumn ¶
AlterTableCreateColumn returns an alter table sql statement that adds a column
func (*Query) AlterTableDropColumn ¶
AlterTableDropColumn returns an alter table sql statement that drops a column
func (*Query) ChangeColumn ¶
func (q *Query) ChangeColumn(table *Table, localColumn *Column, remoteColumn *Column) (sql string, e error)
ChangeColumn returns an alter table sql statement that adds or removes an index from a column if and only if the one (e.g. local) has a column and the other (e.g. remote) does not Truth table
Remote | Local | Result
--------------------------------------------------------- 1. MUL | none | Drop index 2. UNI | none | Drop unique index 3. none | MUL | Create index 4. none | UNI | Create unique index 5. MUL | UNI | Drop index; Create unique index 6. UNI | MUL | Drop unique index; Create index 7. none | none | Do nothing 8. MUL | MUL | Do nothing 9. UNI | UNI | Do nothing
func (*Query) CreateChangeSQL ¶
func (q *Query) CreateChangeSQL(localSchema *Database, remoteSchema *Database) (sql string, e error)
CreateChangeSQL generates sql statements based off of comparing two database objects localSchema is authority, remoteSchema will be upgraded to match localSchema
func (*Query) CreateColumn ¶
CreateColumn returns a table column sql segment
func (*Query) CreateTable ¶
CreateTable returns a create table sql statement
func (*Query) CreateTableChangeSQL ¶
CreateTableChangeSQL returns a set of statements that alter a table's structure if and only if there is a difference between the local and remote tables If no change is found, an empty string is returned.
type Server ¶
type Server struct {
Name string `json:"name"`
Host string `json:"host"`
Databases map[string]*Database
Connection *sql.DB
CurrentDatabase string
}
Server represents a server
func (*Server) DatabaseExists ¶
DatabaseExists checks if the database `databaseName` exists in its list of databases
type SortedColumns ¶
type SortedColumns []*Column
SortedColumns is a slice of Column objects
func (SortedColumns) Less ¶
func (c SortedColumns) Less(i, j int) bool
Less is part of sort.Interface. We use count as the value to sort by
type SortedTables ¶ added in v1.5.0
type SortedTables []*Table
SortedTables is a slice of Table objects
func (SortedTables) Len ¶ added in v1.5.0
func (c SortedTables) Len() int
Len is part of sort.Interface.
func (SortedTables) Less ¶ added in v1.5.0
func (c SortedTables) Less(i, j int) bool
Less is part of sort.Interface. We use count as the value to sort by
func (SortedTables) Swap ¶ added in v1.5.0
func (c SortedTables) Swap(i, j int)
Swap is part of sort.Interface.
type Table ¶
type Table struct {
Name string `json:"name"`
Engine string `json:"engine"`
Version int `json:"version"`
RowFormat string `json:"rowFormat"`
Rows int64 `json:"-"`
DataLength int64 `json:"-"`
Collation string `json:"collation"`
AutoIncrement int64 `json:"-"`
Columns map[string]*Column `json:"columns"`
}
Table represents a table in a database
func (*Table) ToSortedColumns ¶ added in v1.5.0
func (table *Table) ToSortedColumns() SortedColumns
ToSortedColumns returns SortedColumns