gorm/dialect/mysql.go

63 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 (
"database/sql"
"fmt"
"time"
)
type mysql struct{}
2013-11-16 16:47:25 +04:00
func (s *mysql) BinVar(i int) string {
2013-11-14 14:59:11 +04:00
return "?"
}
func (s *mysql) SupportLastInsertId() bool {
return true
}
func (d *mysql) SqlTag(column interface{}, size int) string {
switch column.(type) {
case time.Time:
return "timestamp"
case bool, sql.NullBool:
return "boolean"
case int, int8, int16, int32, uint, uint8, uint16, uint32:
return "int"
case int64, uint64, sql.NullInt64:
return "bigint"
case float32, float64, sql.NullFloat64:
return "double"
case []byte:
if size > 0 && size < 65532 {
return fmt.Sprintf("varbinary(%d)", size)
} else {
return "longblob"
}
case string, sql.NullString:
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
}