xormplus 10 years ago
parent
commit
bd2e08d6ad
3 changed files with 19 additions and 1 deletions
  1. 6 0
      helpers.go
  2. 5 0
      mssql_dialect.go
  3. 8 1
      sqlite3_dialect.go

+ 6 - 0
helpers.go

@@ -37,6 +37,12 @@ func isZero(k interface{}) bool {
 		return k.(uint32) == 0
 	case uint64:
 		return k.(uint64) == 0
+	case float32:
+		return k.(float32) == 0
+	case float64:
+		return k.(float64) == 0
+	case bool:
+		return k.(bool) == false
 	case string:
 		return k.(string) == ""
 	case time.Time:

+ 5 - 0
mssql_dialect.go

@@ -220,6 +220,11 @@ func (db *mssql) SqlType(c *core.Column) string {
 	switch t := c.SQLType.Name; t {
 	case core.Bool:
 		res = core.TinyInt
+		if c.Default == "true" {
+			c.Default = "1"
+		} else if c.Default == "false" {
+			c.Default = "0"
+		}
 	case core.Serial:
 		c.IsAutoIncrement = true
 		c.IsPrimaryKey = true

+ 8 - 1
sqlite3_dialect.go

@@ -156,6 +156,13 @@ func (db *sqlite3) Init(d *core.DB, uri *core.Uri, drivername, dataSourceName st
 
 func (db *sqlite3) SqlType(c *core.Column) string {
 	switch t := c.SQLType.Name; t {
+	case core.Bool:
+		if c.Default == "true" {
+			c.Default = "1"
+		} else if c.Default == "false" {
+			c.Default = "0"
+		}
+		return core.Integer
 	case core.Date, core.DateTime, core.TimeStamp, core.Time:
 		return core.DateTime
 	case core.TimeStampz:
@@ -163,7 +170,7 @@ func (db *sqlite3) SqlType(c *core.Column) string {
 	case core.Char, core.Varchar, core.NVarchar, core.TinyText,
 		core.Text, core.MediumText, core.LongText, core.Json:
 		return core.Text
-	case core.Bit, core.TinyInt, core.SmallInt, core.MediumInt, core.Int, core.Integer, core.BigInt, core.Bool:
+	case core.Bit, core.TinyInt, core.SmallInt, core.MediumInt, core.Int, core.Integer, core.BigInt:
 		return core.Integer
 	case core.Float, core.Double, core.Real:
 		return core.Real