Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateAppcode(driver, connStr, level, tables, currpath string)
- func GenerateController(cname, currpath string)
- func GenerateHproseAppcode(driver, connStr, level, tables, currpath string)
- func GenerateMigration(mname, upsql, downsql, curpath string)
- func GenerateModel(mname, fields, currpath string)
- func GenerateScaffold(sname, fields, currpath, driver, conn string)
- func GenerateView(viewpath, currpath string)
- type Column
- type DBDriver
- type DbTransformer
- type ForeignKey
- type MvcPath
- type MysqlDB
- type OrmTag
- type PostgresDB
- func (postgresDB *PostgresDB) GetColumns(db *sql.DB, table *Table, blackList map[string]bool)
- func (*PostgresDB) GetConstraints(db *sql.DB, table *Table, blackList map[string]bool)
- func (*PostgresDB) GetGoDataType(sqlType string) (string, error)
- func (*PostgresDB) GetTableNames(db *sql.DB) (tables []string)
- type Table
Constants ¶
const ( OModel byte = 1 << iota OController ORouter )
const ( StructModelTPL = `package models {{importTimePkg}} {{modelStruct}} ` ModelTPL = `` /* 3911-byte string literal not displayed */ CtrlTPL = `` /* 4568-byte string literal not displayed */ RouterTPL = `` /* 462-byte string literal not displayed */ NamespaceTPL = ` beego.NSNamespace("/{{nameSpace}}", beego.NSInclude( &controllers.{{ctrlName}}Controller{}, ), ), ` )
const ( HproseAddFunction = `` /* 407-byte string literal not displayed */ HproseStructModelTPL = `package models {{importTimePkg}} {{modelStruct}} ` HproseModelTPL = `` /* 3738-byte string literal not displayed */ )
const ( MPath = "migrations" MDateFormat = "20060102_150405" DBPath = "database" )
const MigrationTPL = `` /* 517-byte string literal not displayed */
Variables ¶
var Fields utils.DocValue
var HproseAddFunctions = []string{}
var HproseMainconngo = `` /* 844-byte string literal not displayed */
var HproseMaingo = `` /* 803-byte string literal not displayed */
var HproseModels = `` /* 997-byte string literal not displayed */
var HproseModels2 = `` /* 1572-byte string literal not displayed */
var Hproseconf = `appname = {{.Appname}}
httpport = 8080
runmode = dev
autorender = false
copyrequestbody = true
EnableDocs = true
`
var Level utils.DocValue
var SQLConn utils.DocValue
var SQLDriver utils.DocValue
var Tables utils.DocValue
Functions ¶
func GenerateAppcode ¶
func GenerateAppcode(driver, connStr, level, tables, currpath string)
func GenerateController ¶
func GenerateController(cname, currpath string)
func GenerateHproseAppcode ¶
func GenerateHproseAppcode(driver, connStr, level, tables, currpath string)
func GenerateMigration ¶
func GenerateMigration(mname, upsql, downsql, curpath string)
generateMigration generates migration file template for database schema update. The generated file template consists of an up() method for updating schema and a down() method for reverting the update.
func GenerateModel ¶
func GenerateModel(mname, fields, currpath string)
func GenerateScaffold ¶
func GenerateScaffold(sname, fields, currpath, driver, conn string)
Types ¶
type DBDriver ¶
type DBDriver interface { GenerateCreateUp(tableName string) string GenerateCreateDown(tableName string) string }
func NewDBDriver ¶
func NewDBDriver() DBDriver
type DbTransformer ¶
type DbTransformer interface { GetTableNames(conn *sql.DB) []string GetConstraints(conn *sql.DB, table *Table, blackList map[string]bool) GetColumns(conn *sql.DB, table *Table, blackList map[string]bool) GetGoDataType(sqlType string) (string, error) }
DbTransformer has method to reverse engineer a database schema to restful api code
type ForeignKey ¶
ForeignKey represents a foreign key column for a table
type MysqlDB ¶
type MysqlDB struct { }
MysqlDB is the MySQL version of DbTransformer
func (*MysqlDB) GetColumns ¶
GetColumns retrieves columns details from information_schema and fill in the Column struct
func (*MysqlDB) GetConstraints ¶
GetConstraints gets primary key, unique key and foreign keys of a table from information_schema and fill in the Table struct
func (*MysqlDB) GetGoDataType ¶
GetGoDataType maps an SQL data type to Golang data type
type OrmTag ¶
type OrmTag struct { Auto bool Pk bool Null bool Index bool Unique bool Column string Size string Decimals string Digits string AutoNow bool AutoNowAdd bool Type string Default string RelOne bool ReverseOne bool RelFk bool ReverseMany bool RelM2M bool }
OrmTag contains Beego ORM tag information for a column
type PostgresDB ¶
type PostgresDB struct { }
PostgresDB is the PostgreSQL version of DbTransformer
func (*PostgresDB) GetColumns ¶
GetColumns for PostgreSQL
func (*PostgresDB) GetConstraints ¶
GetConstraints for PostgreSQL
func (*PostgresDB) GetGoDataType ¶
func (*PostgresDB) GetGoDataType(sqlType string) (string, error)
GetGoDataType returns the Go type from the mapped Postgres type
func (*PostgresDB) GetTableNames ¶
func (*PostgresDB) GetTableNames(db *sql.DB) (tables []string)
GetTableNames for PostgreSQL