gormgen

package
v0.0.0-...-40038e9 Latest Latest
Warning

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

Go to latest
Published: May 18, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectToDsn

func ConnectToDsn(dsnStr string) (*gorm.DB, error)

Connect creates an open connection to a database via gorm. If an error occurs, the returned connection will be `nil`

func ReadDbSchema

func ReadDbSchema(dsn string) (map[string]TableSchema, error)

ReadDbSchema gathers the info about database structure using information_schema returns columns, if there are errors fatal gets thrown

Types

type ColumnContext

type ColumnContext struct {
	DbColumnName string
	GoColumnName string
	GoColumnType string
	GormTag      string
}

ColumnContext struct

type ColumnSchema

type ColumnSchema struct {
	TableName              string
	ColumnName             string
	IsNullable             bool
	IsPrimaryKey           bool
	DataType               string
	CharacterMaximumLength sql.NullInt64
	NumericPrecision       sql.NullInt64
	NumericScale           sql.NullInt64
	ColumnType             string
	ColumnKey              string
	Extra                  sql.NullString
	ColumnDefault          sql.NullString
}

type Generator

type Generator struct {
	OutputPath          string
	DbDsn               string
	StructsFile         string
	StructsRegistryFile string
}

func (*Generator) CreateTemplateContext

func (g *Generator) CreateTemplateContext(dbSchema map[string]TableSchema) (*StructsContext, error)

CreateTemplateContext creates context for template

func (*Generator) GenerateGormStructs

func (g *Generator) GenerateGormStructs() error

GenerateGormStructs generates gorm structs

func (*Generator) GenerateTemplate

func (g *Generator) GenerateTemplate(tmpl string, filePath string) error

GenerateTemplate is used for file generation based on template and path

func (*Generator) GenerateTemplateWithContext

func (g *Generator) GenerateTemplateWithContext(tmpl string, fileName string, context interface{}) error

GenerateTemplateWithContext is used for file generation based on template, path, and context

type StructsContext

type StructsContext struct {
	StructsPackage string
	Imports        map[string]string
	DbSchema       map[string]TableContext
	DbName         string
}

StructsContext struct

type TableContext

type TableContext []*ColumnContext

TableContext struct

type TableSchema

type TableSchema []*ColumnSchema

TableSchema contains the schemas of its columns in order.

Jump to

Keyboard shortcuts

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