Documentation ¶
Index ¶
- func ConnectToDsn(dsnStr string) (*gorm.DB, error)
- func ReadDbSchema(dsn string) (map[string]TableSchema, error)
- type ColumnContext
- type ColumnSchema
- type Generator
- func (g *Generator) CreateTemplateContext(dbSchema map[string]TableSchema) (*StructsContext, error)
- func (g *Generator) GenerateGormStructs() error
- func (g *Generator) GenerateTemplate(tmpl string, filePath string) error
- func (g *Generator) GenerateTemplateWithContext(tmpl string, fileName string, context interface{}) error
- type StructsContext
- type TableContext
- type TableSchema
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConnectToDsn ¶
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 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 ¶
GenerateGormStructs generates gorm structs
func (*Generator) GenerateTemplate ¶
GenerateTemplate is used for file generation based on template and path
type StructsContext ¶
type StructsContext struct { StructsPackage string Imports map[string]string DbSchema map[string]TableContext DbName string }
StructsContext struct
type TableSchema ¶
type TableSchema []*ColumnSchema
TableSchema contains the schemas of its columns in order.
Click to show internal directories.
Click to hide internal directories.