gorm/dialect/mysql.go

66 lines
1.3 KiB
Go
Raw Normal View History

2013-11-14 13:35:17 +04:00
package dialect
2013-11-14 14:59:11 +04:00
import (
"fmt"
"time"
)
type mysql struct{}
2013-11-16 16:47:25 +04:00
func (s *mysql) BinVar(i int) string {
2013-11-21 10:33:06 +04:00
return "$$" // ?
2013-11-14 14:59:11 +04:00
}
func (s *mysql) SupportLastInsertId() bool {
return true
}
func (d *mysql) SqlTag(column interface{}, size int) string {
switch column.(type) {
case time.Time:
2013-12-04 08:06:50 +04:00
return "datetime"
case bool:
2013-11-14 14:59:11 +04:00
return "boolean"
case int, int8, int16, int32, uint, uint8, uint16, uint32:
return "int"
case int64, uint64:
2013-11-14 14:59:11 +04:00
return "bigint"
case float32, float64:
2013-11-14 14:59:11 +04:00
return "double"
case []byte:
if size > 0 && size < 65532 {
return fmt.Sprintf("varbinary(%d)", size)
} else {
return "longblob"
}
case string:
2013-11-14 14:59:11 +04:00
if size > 0 && size < 65532 {
return fmt.Sprintf("varchar(%d)", size)
} else {
return "longtext"
}
default:
panic("Invalid sql type for mysql")
}
}
func (s *mysql) PrimaryKeyTag(column interface{}, size int) string {
suffix_str := " NOT NULL AUTO_INCREMENT PRIMARY KEY"
switch column.(type) {
case int, int8, int16, int32, uint, uint8, uint16, uint32:
return "int" + suffix_str
case int64, uint64:
return "bigint" + suffix_str
default:
panic("Invalid primary key type")
}
}
func (s *mysql) ReturningStr(key string) (str string) {
return
}
func (s *mysql) Quote(key string) (str string) {
return fmt.Sprintf("`%s`", key)
}