Include mysql column comments into generated types
This commit is contained in:
parent
fa69565dbf
commit
7b36f31cad
6 changed files with 33 additions and 11 deletions
|
|
@ -7,6 +7,7 @@ type Column struct {
|
||||||
IsNullable bool
|
IsNullable bool
|
||||||
IsGenerated bool
|
IsGenerated bool
|
||||||
DataType DataType
|
DataType DataType
|
||||||
|
Comment string
|
||||||
}
|
}
|
||||||
|
|
||||||
// DataTypeKind is database type kind(base, enum, user-defined, array)
|
// DataTypeKind is database type kind(base, enum, user-defined, array)
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ func (m mySqlQuerySet) GetTableColumnsMetaData(db *sql.DB, schemaName string, ta
|
||||||
query := `
|
query := `
|
||||||
SELECT COLUMN_NAME AS "column.Name",
|
SELECT COLUMN_NAME AS "column.Name",
|
||||||
IS_NULLABLE = "YES" AS "column.IsNullable",
|
IS_NULLABLE = "YES" AS "column.IsNullable",
|
||||||
|
columns.COLUMN_COMMENT as "column.Comment",
|
||||||
(EXISTS(
|
(EXISTS(
|
||||||
SELECT 1
|
SELECT 1
|
||||||
FROM information_schema.table_constraints t
|
FROM information_schema.table_constraints t
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,10 @@ var {{tableTemplate.InstanceName}} = new{{tableTemplate.TypeName}}("{{schemaName
|
||||||
type {{structImplName}} struct {
|
type {{structImplName}} struct {
|
||||||
{{dialect.PackageName}}.Table
|
{{dialect.PackageName}}.Table
|
||||||
|
|
||||||
//Columns
|
// Columns
|
||||||
{{- range $i, $c := .Columns}}
|
{{- range $i, $c := .Columns}}
|
||||||
{{- $field := columnField $c}}
|
{{- $field := columnField $c}}
|
||||||
{{$field.Name}} {{dialect.PackageName}}.Column{{$field.Type}}
|
{{$field.Name}} {{dialect.PackageName}}.Column{{$field.Type}} {{- if $c.Comment }} // {{$c.Comment}} {{end}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
|
|
||||||
AllColumns {{dialect.PackageName}}.ColumnList
|
AllColumns {{dialect.PackageName}}.ColumnList
|
||||||
|
|
@ -123,7 +123,7 @@ import (
|
||||||
type {{$modelTableTemplate.TypeName}} struct {
|
type {{$modelTableTemplate.TypeName}} struct {
|
||||||
{{- range .Columns}}
|
{{- range .Columns}}
|
||||||
{{- $field := structField .}}
|
{{- $field := structField .}}
|
||||||
{{$field.Name}} {{$field.Type.Name}} ` + "{{$field.TagsString}}" + `
|
{{$field.Name}} {{$field.Type.Name}} ` + "{{$field.TagsString}}" + ` {{- if .Comment }} // {{.Comment}} {{end}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -198,6 +198,26 @@ func assertGeneratedFiles(t *testing.T) {
|
||||||
testutils.AssertFileContent(t, genTestDir3+"/dvds/model/actor.go", actorModelFile)
|
testutils.AssertFileContent(t, genTestDir3+"/dvds/model/actor.go", actorModelFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestModelColumnComment(t *testing.T) {
|
||||||
|
testutils.AssertFileContent(t, "./../.gentestdata/mysql/test_sample/model/link.go", `
|
||||||
|
//
|
||||||
|
// Code generated by go-jet DO NOT EDIT.
|
||||||
|
//
|
||||||
|
// WARNING: Changes to this file may cause incorrect behavior
|
||||||
|
// and will be lost if the code is regenerated
|
||||||
|
//
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
type Link struct {
|
||||||
|
ID int32 `+"`sql:\"primary_key\"`"+` // this is link id
|
||||||
|
URL string // link url
|
||||||
|
Name string // link name
|
||||||
|
Description *string // this is link description
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
var mpaaRatingEnumFile = `
|
var mpaaRatingEnumFile = `
|
||||||
//
|
//
|
||||||
// Code generated by go-jet DO NOT EDIT.
|
// Code generated by go-jet DO NOT EDIT.
|
||||||
|
|
@ -244,7 +264,7 @@ var Actor = newActorTable("dvds", "actor", "")
|
||||||
type actorTable struct {
|
type actorTable struct {
|
||||||
mysql.Table
|
mysql.Table
|
||||||
|
|
||||||
//Columns
|
// Columns
|
||||||
ActorID mysql.ColumnInteger
|
ActorID mysql.ColumnInteger
|
||||||
FirstName mysql.ColumnString
|
FirstName mysql.ColumnString
|
||||||
LastName mysql.ColumnString
|
LastName mysql.ColumnString
|
||||||
|
|
@ -386,7 +406,7 @@ var ActorInfo = newActorInfoTable("dvds", "actor_info", "")
|
||||||
type actorInfoTable struct {
|
type actorInfoTable struct {
|
||||||
mysql.Table
|
mysql.Table
|
||||||
|
|
||||||
//Columns
|
// Columns
|
||||||
ActorID mysql.ColumnInteger
|
ActorID mysql.ColumnInteger
|
||||||
FirstName mysql.ColumnString
|
FirstName mysql.ColumnString
|
||||||
LastName mysql.ColumnString
|
LastName mysql.ColumnString
|
||||||
|
|
|
||||||
|
|
@ -322,7 +322,7 @@ var Actor = newActorTable("dvds", "actor", "")
|
||||||
type actorTable struct {
|
type actorTable struct {
|
||||||
postgres.Table
|
postgres.Table
|
||||||
|
|
||||||
//Columns
|
// Columns
|
||||||
ActorID postgres.ColumnInteger
|
ActorID postgres.ColumnInteger
|
||||||
FirstName postgres.ColumnString
|
FirstName postgres.ColumnString
|
||||||
LastName postgres.ColumnString
|
LastName postgres.ColumnString
|
||||||
|
|
@ -463,7 +463,7 @@ var ActorInfo = newActorInfoTable("dvds", "actor_info", "")
|
||||||
type actorInfoTable struct {
|
type actorInfoTable struct {
|
||||||
postgres.Table
|
postgres.Table
|
||||||
|
|
||||||
//Columns
|
// Columns
|
||||||
ActorID postgres.ColumnInteger
|
ActorID postgres.ColumnInteger
|
||||||
FirstName postgres.ColumnString
|
FirstName postgres.ColumnString
|
||||||
LastName postgres.ColumnString
|
LastName postgres.ColumnString
|
||||||
|
|
@ -735,7 +735,7 @@ var AllTypes = newAllTypesTable("test_sample", "all_types", "")
|
||||||
type allTypesTable struct {
|
type allTypesTable struct {
|
||||||
postgres.Table
|
postgres.Table
|
||||||
|
|
||||||
//Columns
|
// Columns
|
||||||
SmallIntPtr postgres.ColumnInteger
|
SmallIntPtr postgres.ColumnInteger
|
||||||
SmallInt postgres.ColumnInteger
|
SmallInt postgres.ColumnInteger
|
||||||
IntegerPtr postgres.ColumnInteger
|
IntegerPtr postgres.ColumnInteger
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,7 @@ var Actor = newActorTable("", "actor", "")
|
||||||
type actorTable struct {
|
type actorTable struct {
|
||||||
sqlite.Table
|
sqlite.Table
|
||||||
|
|
||||||
//Columns
|
// Columns
|
||||||
ActorID sqlite.ColumnInteger
|
ActorID sqlite.ColumnInteger
|
||||||
FirstName sqlite.ColumnString
|
FirstName sqlite.ColumnString
|
||||||
LastName sqlite.ColumnString
|
LastName sqlite.ColumnString
|
||||||
|
|
@ -280,7 +280,7 @@ var FilmList = newFilmListTable("", "film_list", "")
|
||||||
type filmListTable struct {
|
type filmListTable struct {
|
||||||
sqlite.Table
|
sqlite.Table
|
||||||
|
|
||||||
//Columns
|
// Columns
|
||||||
Fid sqlite.ColumnInteger
|
Fid sqlite.ColumnInteger
|
||||||
Title sqlite.ColumnString
|
Title sqlite.ColumnString
|
||||||
Description sqlite.ColumnString
|
Description sqlite.ColumnString
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue