gomgen

package
v0.0.0-...-a003fe3 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2014 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GoTypeMap = map[GoType]string{
	GoInt:         "int64",
	GoFloat64:     "float64",
	GoBool:        "bool",
	GoString:      "string",
	GoTime:        "time.Time",
	GoNullInt:     "sql.NullInt64",
	GoNullFloat64: "sql.NullFloat64",
	GoNullBool:    "sql.NullBool",
	GoNullString:  "sql.NullString",
}

map GoType constants to strings of actual types

Functions

This section is empty.

Types

type Analyzer

type Analyzer interface {
	Analyze(gen *Generator)
}

type Field

type Field struct {
	Name        string
	EscapedName string
	RealName    string
	Default     sql.NullString
	Nullable    bool
	Type        GoType
	GoType      string
	Primary     bool
	AutoInc     bool
	Comment     string
	Format      string
}

represent individual field in the table

func NewField

func NewField(rawName string) *Field

the name of the field

type Generator

type Generator struct {
	Db      *sql.DB
	Schema  string
	Tables  []*Table
	Imports map[string]bool
	Output  *bytes.Buffer
}

Gomgen generator is the primary interface for scanning, analyzing and generating models with gomgen

func NewGenerator

func NewGenerator(db *sql.DB, schema string) *Generator

create and initialize new Gomgen object

func (*Generator) Analyse

func (this *Generator) Analyse() error

Investigate the database

func (*Generator) Generate

func (this *Generator) Generate() error

Generate the model source code

func (*Generator) GetTable

func (this *Generator) GetTable(name string) *Table

find table by name

type GoType

type GoType int

Field data type mapping to Go

const (
	GoInt GoType = iota
	GoFloat64
	GoBool
	GoString
	GoTime
	GoNullInt
	GoNullFloat64
	GoNullBool
	GoNullString
)

type Mysql

type Mysql struct {
	// contains filtered or unexported fields
}

mysql analyzer

func (*Mysql) Analyze

func (this *Mysql) Analyze(gen *Generator) error

analyze mysql table

type Relation

type Relation struct {
	Name            string
	Table           *Table
	Column          *Field // null for many-to-many
	TargetEntity    *Table
	TargetColumn    *Field // null for many-to-many
	MiddleEntity    *Table // connecting table
	MiddleSrcColumn *Field // point to this entity
	MiddleDstColumn *Field // point to target entity
}

represent a relation between the tables

func NewRelation

func NewRelation(name string) *Relation

Create new relation object

type RelationType

type RelationType int

specify the relation type between the entities

const (
	OneToOne RelationType = iota
	OneToMany
	ManyToMany
)

type Table

type Table struct {
	Name           string
	EscapedName    string
	EntitySingular string
	EntityPlural   string
	Comment        string
	Fields         []*Field
	Identity       []*Field
	Relations      []*Relation
}

represent a database table

func NewTable

func NewTable(sqlName, comment string) *Table

create new table

func (*Table) GetField

func (this *Table) GetField(name string) *Field

get field by name

Jump to

Keyboard shortcuts

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