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-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"
|
2013-11-14 14:59:11 +04:00
|
|
|
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
|
|
|
|
}
|
2013-11-30 10:52:01 +04:00
|
|
|
|
|
|
|
func (s *mysql) Quote(key string) (str string) {
|
|
|
|
return fmt.Sprintf("`%s`", key)
|
|
|
|
}
|