mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
schema/field: add an option to configure the database type (#484)
This commit is contained in:
@@ -218,7 +218,7 @@ func (d *MySQL) cType(c *Column) (t string) {
|
||||
t = "longtext"
|
||||
}
|
||||
case field.TypeFloat32, field.TypeFloat64:
|
||||
t = "double"
|
||||
t = c.scanTypeOr("double")
|
||||
case field.TypeTime:
|
||||
t = c.scanTypeOr("timestamp")
|
||||
// In MySQL, timestamp columns are `NOT NULL by default, and assigning NULL
|
||||
@@ -354,7 +354,7 @@ func (d *MySQL) scanColumn(c *Column, rows *sql.Rows) error {
|
||||
default:
|
||||
c.Type = field.TypeInt8
|
||||
}
|
||||
case "double":
|
||||
case "numeric", "decimal", "double":
|
||||
c.Type = field.TypeFloat64
|
||||
case "time", "timestamp", "date", "datetime":
|
||||
c.Type = field.TypeTime
|
||||
|
||||
@@ -161,6 +161,7 @@ func TestMySQL_Create(t *testing.T) {
|
||||
{Name: "small_unsigned", Type: field.TypeUint16},
|
||||
{Name: "big", Type: field.TypeInt64},
|
||||
{Name: "big_unsigned", Type: field.TypeUint64},
|
||||
{Name: "decimal", Type: field.TypeFloat64, SchemaType: map[string]string{dialect.MySQL: "decimal(6,2)"}},
|
||||
},
|
||||
PrimaryKey: []*Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
@@ -184,7 +185,8 @@ func TestMySQL_Create(t *testing.T) {
|
||||
AddRow("small", "smallint", "NO", "YES", "NULL", "", "", "").
|
||||
AddRow("small_unsigned", "smallint unsigned", "NO", "YES", "NULL", "", "", "").
|
||||
AddRow("big", "bigint", "NO", "YES", "NULL", "", "", "").
|
||||
AddRow("big_unsigned", "bigint unsigned", "NO", "YES", "NULL", "", "", ""))
|
||||
AddRow("big_unsigned", "bigint unsigned", "NO", "YES", "NULL", "", "", "").
|
||||
AddRow("decimal", "decimal(6,2)", "NO", "YES", "NULL", "", "", ""))
|
||||
mock.ExpectQuery(escape("SELECT `index_name`, `column_name`, `non_unique`, `seq_in_index` FROM INFORMATION_SCHEMA.STATISTICS WHERE `TABLE_SCHEMA` = (SELECT DATABASE()) AND `TABLE_NAME` = ? ORDER BY `index_name`, `seq_in_index`")).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "non_unique", "seq_in_index"}).
|
||||
|
||||
@@ -222,7 +222,7 @@ func (d *Postgres) scanColumn(c *Column, rows *sql.Rows) error {
|
||||
c.Type = field.TypeInt64
|
||||
case "real":
|
||||
c.Type = field.TypeFloat32
|
||||
case "double precision":
|
||||
case "numeric", "decimal", "double precision":
|
||||
c.Type = field.TypeFloat64
|
||||
case "text":
|
||||
c.Type = field.TypeString
|
||||
@@ -278,9 +278,9 @@ func (d *Postgres) cType(c *Column) (t string) {
|
||||
case field.TypeInt, field.TypeUint, field.TypeInt64, field.TypeUint64:
|
||||
t = "bigint"
|
||||
case field.TypeFloat32:
|
||||
t = "real"
|
||||
t = c.scanTypeOr("real")
|
||||
case field.TypeFloat64:
|
||||
t = "double precision"
|
||||
t = c.scanTypeOr("double precision")
|
||||
case field.TypeBytes:
|
||||
t = "bytea"
|
||||
case field.TypeJSON:
|
||||
|
||||
Reference in New Issue
Block a user