[Bug241] Remove control characters from mysql column comment

This commit is contained in:
go-jet 2023-07-22 12:01:49 +02:00
parent dbcf614140
commit bb22b80984
3 changed files with 104 additions and 3 deletions

View file

@ -191,7 +191,96 @@ 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
Description *string // '"\\%\_
}
`)
}
func TestSQLBuilderColumnComment(t *testing.T) {
testutils.AssertFileContent(t, "./../.gentestdata/mysql/test_sample/table/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 table
import (
"github.com/go-jet/jet/v2/mysql"
)
var Link = newLinkTable("test_sample", "link", "")
type linkTable struct {
mysql.Table
// Columns
ID mysql.ColumnInteger // this is link id
URL mysql.ColumnString // link url
Name mysql.ColumnString // link name
Description mysql.ColumnString // '"\\%\_
AllColumns mysql.ColumnList
MutableColumns mysql.ColumnList
}
type LinkTable struct {
linkTable
NEW linkTable
}
// AS creates new LinkTable with assigned alias
func (a LinkTable) AS(alias string) *LinkTable {
return newLinkTable(a.SchemaName(), a.TableName(), alias)
}
// Schema creates new LinkTable with assigned schema name
func (a LinkTable) FromSchema(schemaName string) *LinkTable {
return newLinkTable(schemaName, a.TableName(), a.Alias())
}
// WithPrefix creates new LinkTable with assigned table prefix
func (a LinkTable) WithPrefix(prefix string) *LinkTable {
return newLinkTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
}
// WithSuffix creates new LinkTable with assigned table suffix
func (a LinkTable) WithSuffix(suffix string) *LinkTable {
return newLinkTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
}
func newLinkTable(schemaName, tableName, alias string) *LinkTable {
return &LinkTable{
linkTable: newLinkTableImpl(schemaName, tableName, alias),
NEW: newLinkTableImpl("", "new", ""),
}
}
func newLinkTableImpl(schemaName, tableName, alias string) linkTable {
var (
IDColumn = mysql.IntegerColumn("id")
URLColumn = mysql.StringColumn("url")
NameColumn = mysql.StringColumn("name")
DescriptionColumn = mysql.StringColumn("description")
allColumns = mysql.ColumnList{IDColumn, URLColumn, NameColumn, DescriptionColumn}
mutableColumns = mysql.ColumnList{URLColumn, NameColumn, DescriptionColumn}
)
return linkTable{
Table: mysql.NewTable(schemaName, tableName, alias, allColumns...),
//Columns
ID: IDColumn,
URL: URLColumn,
Name: NameColumn,
Description: DescriptionColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,
}
}
`)
}