dbmeta

package
v0.0.0-...-5a7003e Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: LGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Set of characters to use for generating random strings
	Alphabet     = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
	Numerals     = "1234567890"
	Alphanumeric = Alphabet + Numerals
	Ascii        = Alphanumeric + "~!@#$%^&*()-_+={}[]\\|<,>.?/\"';:`"
)

Variables

This section is empty.

Functions

func Copy

func Copy(dst interface{}, src interface{}) error

func EnumValue

func EnumValue(v string) (val []string)

func Float64

func Float64() float64

Float64 returns a pseudo-random number in [0.0,1.0)

func FmtFieldName

func FmtFieldName(s string) string

fmtFieldName formats a string as a struct key

Example:

fmtFieldName("foo_id")

Output: FooID

func FmtFieldName2

func FmtFieldName2(s string) string

func GetRandom

func GetRandom(length int) int

func GetRandomString

func GetRandomString(n int) (s string)

AlphaString returns a random alphanumeric string n characters long.

func GetTableDesc

func GetTableDesc(db *sql.DB, tableName string) (fieldDef map[string]interface{}, primaryKey []string, err error)

默认值

func GetTablePrimaryKey

func GetTablePrimaryKey(db *sql.DB, dbName, tableName string) (primaryKey []string, err error)

主键

func GetTableRemark

func GetTableRemark(db *sql.DB, dbName, tableName string) (remark string, err error)

表备注

func Int63

func Int63() int64

Int63 returns a non-negative pseudo-random 63-bit integer as an int64.

func Int63n

func Int63n(n int64) int64

Int63n returns, as an int64, a non-negative pseudo-random number in [0,n). It panics if n <= 0.

func Intn

func Intn(n int) int

Intn returns, as an int, a non-negative pseudo-random number in [0,n). It panics if n <= 0.

func Query

func Query(db *sql.DB, queryStr string, args ...interface{}) ([]map[string]interface{}, error)

func StrToInt

func StrToInt(str string) (i int)

func String

func String(n int, charset string) (string, error)

String returns a random string n characters long, composed of entities from charset.

Types

type ColumnInfo

type ColumnInfo struct {
	ColumnName              string          `json:"column_name"`              //字段名称
	IsNullable              string          `json:"is_nullable"`              //是否允许为空
	DataType                string          `json:"data_type"`                //字段类型
	ColumnType              string          `json:"column_type"`              //详细字段类型
	CharacterMaximumLength2 string          `json:"character_maximum_length"` //长度
	CharacterOctetLength2   string          `json:"character_octet_length"`   //字符八位字节长度
	NumericPrecision2       string          `json:"numeric_precision"`        //double/floag/numeric 长度
	NumericScale2           string          `json:"numeric_scale"`            //小数点
	CharacterMaximumLength  int             //长度
	CharacterOctetLength    int             //字符八位字节长度
	NumericPrecision        int             //double/floag/numeric 长度
	NumericScale            int             //小数点
	ColumnComment           string          `json:"column_comment"` //字段备注
	ColumnItemValue         []string        //字段项值,如:enum('保密','男','女')
	ColumnCNName            string          //中文名称
	DataTypeLower           string          //小写
	StructName              string          //StructName
	Valid                   []string        //字段验证标记
	FormType                string          //表单类型,text:字符长度小于300输入框,number:数字类型,time:时间类型,date:日期类型,
	AddTestValue            interface{}     //添加测试的,字段test时值
	UpdateTestValue         interface{}     //修改测试的,字段test时值
	PrimaryKey              bool            //是否为主键
	PageTable               map[string]bool //页面控制,search:可搜索,none:不显示,如:Table[none]或Table[search]
	PageForm                map[string]bool //页面控制,none:不显示,如:Form[none]
}

func GetTableColumnRemark

func GetTableColumnRemark(db *sql.DB, dbName, tableName string) (cols []*ColumnInfo, err error)

字段备注

type ModelInfo

type ModelInfo struct {
	PackageName     string
	StructName      string
	SingName        string
	ShortStructName string
	TableName       string
	TableView       string //使用视图显示
	TableRemark     string
	TableHandle     map[string]bool
	FieldsMap       map[string]bool
	Fields          []string
	PrimaryKey      []string
	Columns         []*ColumnInfo
	IDPrimaryKeyInt bool
}

func GenerateStruct

func GenerateStruct(db *sql.DB, dbName string, tableName string, structName string, pkgName string, jsonAnnotation bool, gormAnnotation bool, gureguTypes bool) *ModelInfo

GenerateStruct generates a struct for the given table.

Jump to

Keyboard shortcuts

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