dbmeta

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2020 License: GPL-3.0 Imports: 17 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildDefaultTableDDL

func BuildDefaultTableDDL(tableName string, cols []ColumnMeta) string

func BytesToString

func BytesToString(bs []uint8) string

func Copy

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

func FindPrimaryKeyFromInformationSchema

func FindPrimaryKeyFromInformationSchema(db *sql.DB, tableName string) (primaryKey string, err error)

func FmtFieldName

func FmtFieldName(s string) string

fmtFieldName formats a string as a struct key

Example:

fmtFieldName("foo_id")

Output: FooID

func GetFieldLenFromInformationSchema

func GetFieldLenFromInformationSchema(db *sql.DB, tableSchema, tableName, columnName string) (int64, error)

func GetMappings

func GetMappings() map[string]*SqlMapping

func LoadMappings

func LoadMappings(mappingFileName string) error

func LoadTableInfoFromMSSqlInformationSchema

func LoadTableInfoFromMSSqlInformationSchema(db *sql.DB, tableName string) (primaryKey map[string]*mssqlInformationSchema, err error)

func LoadTableInfoFromPostgresInformationSchema

func LoadTableInfoFromPostgresInformationSchema(db *sql.DB, tableName string) (primaryKey map[string]*postgresInformationSchema, err error)

func ParseSqlType

func ParseSqlType(dbType string) (resultType string, dbTypeLen int64)

func ProcessMappings

func ProcessMappings(mappingJsonstring []byte) error

func SqlTypeToGoType

func SqlTypeToGoType(sqlType string, nullable bool, gureguTypes bool) (string, error)

func SqlTypeToProtobufType

func SqlTypeToProtobufType(sqlType string) (string, error)

func TrimSpaceNewlineInString

func TrimSpaceNewlineInString(s string) string

Types

type ColumnMeta

type ColumnMeta interface {
	Name() string
	String() string
	Nullable() bool
	DatabaseTypeName() string
	DatabaseTypePretty() string
	Index() int
	IsPrimaryKey() bool
	IsAutoIncrement() bool
	ColumnType() string
	ColumnLength() int64
	DefaultValue() string
}

type DbTableMeta

type DbTableMeta interface {
	Columns() []ColumnMeta
	SqlType() string
	SqlDatabase() string
	TableName() string
	DDL() string
}

func LoadMeta

func LoadMeta(sqlType string, db *sql.DB, sqlDatabase, tableName string) (DbTableMeta, error)

GenerateStruct generates a struct for the given table.

func NewMsSqlMeta

func NewMsSqlMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)

func NewMysqlMeta

func NewMysqlMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)

func NewPostgresMeta

func NewPostgresMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)

func NewSqliteMeta

func NewSqliteMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)

func NewUnknownMeta

func NewUnknownMeta(db *sql.DB, sqlType, sqlDatabase, tableName string) (DbTableMeta, error)

type FieldInfo

type FieldInfo struct {
	Index             int
	GoFieldName       string
	GoFieldType       string
	GoAnnotations     []string
	JsonFieldName     string
	ProtobufFieldName string
	ProtobufType      string
	ProtobufPos       int
	Comment           string
	Code              string
	FakeData          interface{}
	ColumnMeta        ColumnMeta
}

type ModelInfo

type ModelInfo struct {
	Index                 int
	IndexPlus1            int
	PackageName           string
	StructName            string
	ShortStructName       string
	TableName             string
	Fields                []string
	DBMeta                DbTableMeta
	Instance              interface{}
	CodeFields            []*FieldInfo
	PrimaryKeyField       int
	PrimaryKeyGoType      string
	PrimaryKeyFieldParser string
}

func GenerateStruct

func GenerateStruct(sqlType string,
	db *sql.DB,
	sqlDatabase,
	tableName string,
	structName string,
	pkgName string,
	addJsonAnnotation bool,
	addGormAnnotation bool,
	addDBAnnotation bool,
	addProtobufAnnotation bool,
	gureguTypes bool,
	jsonNameFormat string,
	protobufNameFormat string,
	verbose bool) (*ModelInfo, error)

GenerateStruct generates a struct for the given table.

type SqlMapping

type SqlMapping struct {
	SqlType        string `json:"sql_type"`
	GoType         string `json:"go_type"`
	JsonType       string `json:"json_type"`
	ProtobufType   string `json:"protobuf_type"`
	GureguType     string `json:"guregu_type"`
	GoNullableType string `json:"go_nullable_type"`
}

func SqlTypeToMapping

func SqlTypeToMapping(sqlType string) (*SqlMapping, error)

type SqlMappings

type SqlMappings struct {
	SqlMappings []*SqlMapping `json:"mappings"`
}

Jump to

Keyboard shortcuts

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