github.com/woremacx/kocha@v0.7.1-0.20150731103243-a5889322afc9/cmd/kocha-generate/kocha-generate-model/genmai.go (about)

     1  package main
     2  
     3  import (
     4  	"path/filepath"
     5  	"runtime"
     6  
     7  	"github.com/woremacx/kocha/util"
     8  )
     9  
    10  // GenmaiModelType implements ModelTyper interface.
    11  type GenmaiModelType struct{}
    12  
    13  // FieldTypeMap returns type map for Genmai ORM.
    14  func (mt *GenmaiModelType) FieldTypeMap() map[string]ModelFieldType {
    15  	return map[string]ModelFieldType{
    16  		"int":        ModelFieldType{"int", nil},
    17  		"integer":    ModelFieldType{"int", nil},
    18  		"int8":       ModelFieldType{"int8", nil},
    19  		"byte":       ModelFieldType{"int8", nil},
    20  		"int16":      ModelFieldType{"int16", nil},
    21  		"smallint":   ModelFieldType{"int16", nil},
    22  		"int32":      ModelFieldType{"int32", nil},
    23  		"int64":      ModelFieldType{"int64", nil},
    24  		"bigint":     ModelFieldType{"int64", nil},
    25  		"string":     ModelFieldType{"string", nil},
    26  		"text":       ModelFieldType{"string", []string{`size:"65533"`}},
    27  		"mediumtext": ModelFieldType{"string", []string{`size:"16777216"`}},
    28  		"longtext":   ModelFieldType{"string", []string{`size:"4294967295"`}},
    29  		"bytea":      ModelFieldType{"[]byte", nil},
    30  		"blob":       ModelFieldType{"[]byte", nil},
    31  		"mediumblob": ModelFieldType{"[]byte", []string{`size:"65533"`}},
    32  		"longblob":   ModelFieldType{"[]byte", []string{`size:"4294967295"`}},
    33  		"bool":       ModelFieldType{"bool", nil},
    34  		"boolean":    ModelFieldType{"bool", nil},
    35  		"float":      ModelFieldType{"genmai.Float64", nil},
    36  		"float64":    ModelFieldType{"genmai.Float64", nil},
    37  		"double":     ModelFieldType{"genmai.Float64", nil},
    38  		"real":       ModelFieldType{"genmai.Float64", nil},
    39  		"date":       ModelFieldType{"time.Time", nil},
    40  		"time":       ModelFieldType{"time.Time", nil},
    41  		"datetime":   ModelFieldType{"time.Time", nil},
    42  		"timestamp":  ModelFieldType{"time.Time", nil},
    43  		"decimal":    ModelFieldType{"genmai.Rat", nil},
    44  		"numeric":    ModelFieldType{"genmai.Rat", nil},
    45  	}
    46  }
    47  
    48  // TemplatePath returns paths that templates of Genmai ORM for model generation.
    49  func (mt *GenmaiModelType) TemplatePath() (templatePath string, configTemplatePath string) {
    50  	templatePath = filepath.Join(skeletonDir("model"), "genmai", "genmai.go"+util.TemplateSuffix)
    51  	configTemplatePath = filepath.Join(skeletonDir("model"), "genmai", "config.go"+util.TemplateSuffix)
    52  	return templatePath, configTemplatePath
    53  }
    54  
    55  func skeletonDir(name string) string {
    56  	_, filename, _, _ := runtime.Caller(0)
    57  	baseDir := filepath.Dir(filename)
    58  	return filepath.Join(baseDir, "skeleton", name)
    59  }