generate

package
v2.0.0-...-bd3aa36 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OModel byte = 1 << iota
	OController
	ORouter
)
View Source
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{},
			),
		),
`
)
View Source
const (
	HproseAddFunction = `` /* 407-byte string literal not displayed */

	HproseStructModelTPL = `package models
{{importTimePkg}}
{{modelStruct}}
`

	HproseModelTPL = `` /* 3738-byte string literal not displayed */

)
View Source
const (
	MPath       = "migrations"
	MDateFormat = "20060102_150405"
	DBPath      = "database"
)
View Source
const (
	MigrationHeader = `` /* 364-byte string literal not displayed */

	DDLSpecCreate = `` /* 244-byte string literal not displayed */

	DDLSpecAlter = `` /* 132-byte string literal not displayed */

	MigrationUp = `` /* 143-byte string literal not displayed */

	MigrationDown = `` /* 157-byte string literal not displayed */

)

Variables

View Source
var HproseAddFunctions = []string{}
View Source
var HproseMainconngo = `` /* 844-byte string literal not displayed */
View Source
var HproseMaingo = `` /* 803-byte string literal not displayed */
View Source
var HproseModels = `` /* 997-byte string literal not displayed */
View Source
var HproseModels2 = `` /* 1572-byte string literal not displayed */
View Source
var Hproseconf = `appname = {{.Appname}}
httpport = 8080
runmode = dev
autorender = false
copyrequestbody = true
EnableDocs = true
`
View Source
var SQLConn utils.DocValue
View Source
var SQLDriver 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)

func GenerateView

func GenerateView(viewpath, currpath string)

recipe admin/recipe

Types

type Column

type Column struct {
	Name string
	Type string
	Tag  *OrmTag
}

Column reprsents a column for a table

func (*Column) String

func (col *Column) String() string

String returns the source code string of a field in Table struct It maps to a column in database table. e.g. Id int `orm:"column(id);auto"`

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

type ForeignKey struct {
	Name      string
	RefSchema string
	RefTable  string
	RefColumn string
}

ForeignKey represents a foreign key column for a table

type MvcPath

type MvcPath struct {
	ModelPath      string
	ControllerPath string
	RouterPath     string
}

type MysqlDB

type MysqlDB struct {
}

MysqlDB is the MySQL version of DbTransformer

func (*MysqlDB) GetColumns

func (mysqlDB *MysqlDB) GetColumns(db *sql.DB, table *Table, blackList map[string]bool)

GetColumns retrieves columns details from information_schema and fill in the Column struct

func (*MysqlDB) GetConstraints

func (*MysqlDB) GetConstraints(db *sql.DB, table *Table, blackList map[string]bool)

GetConstraints gets primary key, unique key and foreign keys of a table from information_schema and fill in the Table struct

func (*MysqlDB) GetGoDataType

func (*MysqlDB) GetGoDataType(sqlType string) (string, error)

GetGoDataType maps an SQL data type to Golang data type

func (*MysqlDB) GetTableNames

func (*MysqlDB) GetTableNames(db *sql.DB) (tables []string)

GetTableNames returns a slice of table names in the current database

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
	Comment     string //column comment
}

OrmTag contains Beego ORM tag information for a column

func (*OrmTag) String

func (tag *OrmTag) String() string

String returns the ORM tag string for a column

type PostgresDB

type PostgresDB struct {
}

PostgresDB is the PostgreSQL version of DbTransformer

func (*PostgresDB) GetColumns

func (postgresDB *PostgresDB) GetColumns(db *sql.DB, table *Table, blackList map[string]bool)

GetColumns for PostgreSQL

func (*PostgresDB) GetConstraints

func (*PostgresDB) GetConstraints(db *sql.DB, table *Table, blackList map[string]bool)

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

type Table

type Table struct {
	Name          string
	Pk            string
	Uk            []string
	Fk            map[string]*ForeignKey
	Columns       []*Column
	ImportTimePkg bool
}

Table represent a table in a database

func (*Table) String

func (tb *Table) String() string

String returns the source code string for the Table struct

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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