mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
enable sql dialect option on integration env (#1014)
Summary: Pull Request resolved: https://github.com/facebookexternal/fbc/pull/1014 Pull Request resolved: https://github.com/facebookincubator/ent/pull/6 Reviewed By: alexsn Differential Revision: D15928002 fbshipit-source-id: 4b5a639405f218f6b6cc90d152380d2fc9525a3f
This commit is contained in:
committed by
Facebook Github Bot
parent
970a410b31
commit
5ca9494121
@@ -5,6 +5,7 @@ import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"fbc/ent/dialect"
|
||||
@@ -31,7 +32,15 @@ func OpenDB(driver string, db *sql.DB) *Driver {
|
||||
}
|
||||
|
||||
// Dialect implements the dialect.Dialect method.
|
||||
func (d Driver) Dialect() string { return d.dialect }
|
||||
func (d Driver) Dialect() string {
|
||||
// if the underlying driver is wrapped with opencensus driver.
|
||||
for _, name := range []string{dialect.MySQL, dialect.SQLite} {
|
||||
if strings.HasPrefix(d.dialect, name) {
|
||||
return name
|
||||
}
|
||||
}
|
||||
return d.dialect
|
||||
}
|
||||
|
||||
// Tx starts and returns a transaction.
|
||||
func (d *Driver) Tx(ctx context.Context) (dialect.Tx, error) {
|
||||
|
||||
@@ -170,7 +170,7 @@ func changeSet(curr, new *Table) (*Table, error) {
|
||||
case !ok:
|
||||
changes.Columns = append(changes.Columns, c1)
|
||||
case c1.Type != c2.Type:
|
||||
return nil, fmt.Errorf("changing column type for %q is invalid", c1.Name)
|
||||
return nil, fmt.Errorf("changing column type for %q is invalid (%s != %s)", c1.Name, c1.Type, c2.Type)
|
||||
case c1.Unique != c2.Unique:
|
||||
return nil, fmt.Errorf("changing column cardinality for %q is invalid", c1.Name)
|
||||
}
|
||||
|
||||
@@ -226,6 +226,8 @@ func (c *Column) ScanMySQL(rows *sql.Rows) error {
|
||||
}); parts[0] {
|
||||
case "int":
|
||||
c.Type = field.TypeInt
|
||||
case "double":
|
||||
c.Type = field.TypeFloat64
|
||||
case "timestamp":
|
||||
c.Type = field.TypeTime
|
||||
case "tinyint":
|
||||
|
||||
Reference in New Issue
Block a user