add some interface for dialect

This commit is contained in:
Lunny Xiao 2014-04-13 15:37:25 +08:00
parent 3dd33af2d6
commit 46546777ae
2 changed files with 27 additions and 8 deletions

View File

@ -51,10 +51,12 @@ func (col *Column) String(d Dialect) string {
} }
} }
if col.Nullable { if d.ShowCreateNull() {
sql += "NULL " if col.Nullable {
} else { sql += "NULL "
sql += "NOT NULL " } else {
sql += "NOT NULL "
}
} }
if col.Default != "" { if col.Default != "" {
@ -69,10 +71,12 @@ func (col *Column) StringNoPk(d Dialect) string {
sql += d.SqlType(col) + " " sql += d.SqlType(col) + " "
if col.Nullable { if d.ShowCreateNull() {
sql += "NULL " if col.Nullable {
} else { sql += "NULL "
sql += "NOT NULL " } else {
sql += "NOT NULL "
}
} }
if col.Default != "" { if col.Default != "" {

View File

@ -30,12 +30,15 @@ type Dialect interface {
SqlType(t *Column) string SqlType(t *Column) string
SupportInsertMany() bool SupportInsertMany() bool
QuoteStr() string QuoteStr() string
AndStr() string
EqStr() string
RollBackStr() string RollBackStr() string
DropTableSql(tableName string) string DropTableSql(tableName string) string
AutoIncrStr() string AutoIncrStr() string
SupportEngine() bool SupportEngine() bool
SupportCharset() bool SupportCharset() bool
IndexOnTable() bool IndexOnTable() bool
ShowCreateNull() bool
IndexCheckSql(tableName, idxName string) (string, []interface{}) IndexCheckSql(tableName, idxName string) (string, []interface{})
TableCheckSql(tableName string) (string, []interface{}) TableCheckSql(tableName string) (string, []interface{})
@ -78,6 +81,10 @@ func (b *Base) DriverName() string {
return b.driverName return b.driverName
} }
func (b *Base) ShowCreateNull() bool {
return true
}
func (b *Base) DataSourceName() string { func (b *Base) DataSourceName() string {
return b.dataSourceName return b.dataSourceName
} }
@ -86,6 +93,14 @@ func (b *Base) Quote(c string) string {
return b.dialect.QuoteStr() + c + b.dialect.QuoteStr() return b.dialect.QuoteStr() + c + b.dialect.QuoteStr()
} }
func (b *Base) AndStr() string {
return "AND"
}
func (b *Base) EqStr() string {
return "="
}
func (db *Base) RollBackStr() string { func (db *Base) RollBackStr() string {
return "ROLL BACK" return "ROLL BACK"
} }