Hide method QuoteIfPossible

This commit is contained in:
Jinzhu 2016-01-17 16:37:17 +08:00
parent 317e1a9a48
commit 4f84bf0d94
3 changed files with 5 additions and 5 deletions

View File

@ -39,9 +39,9 @@ func updateTimeStampForCreateCallback(scope *Scope) {
// createCallback the callback used to insert data into database
func createCallback(scope *Scope) {
defer scope.trace(NowFunc())
if !scope.HasError() {
defer scope.trace(NowFunc())
// set create sql
var sqls, columns []string
fields := scope.Fields()

View File

@ -88,7 +88,7 @@ func (scope *Scope) Quote(str string) string {
return scope.Dialect().Quote(str)
}
func (scope *Scope) QuoteIfPossible(str string) string {
func (scope *Scope) quoteIfPossible(str string) string {
if regexp.MustCompile("^[a-zA-Z]+(.[a-zA-Z]+)*$").MatchString(str) {
return scope.Quote(str)
}

View File

@ -663,7 +663,7 @@ func (scope *Scope) addIndex(unique bool, indexName string, column ...string) {
var columns []string
for _, name := range column {
columns = append(columns, scope.QuoteIfPossible(name))
columns = append(columns, scope.quoteIfPossible(name))
}
sqlCreate := "CREATE INDEX"
@ -678,7 +678,7 @@ func (scope *Scope) addForeignKey(field string, dest string, onDelete string, on
var keyName = fmt.Sprintf("%s_%s_%s_foreign", scope.TableName(), field, dest)
keyName = regexp.MustCompile("(_*[^a-zA-Z]+_*|_+)").ReplaceAllString(keyName, "_")
var query = `ALTER TABLE %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s ON DELETE %s ON UPDATE %s;`
scope.Raw(fmt.Sprintf(query, scope.QuotedTableName(), scope.QuoteIfPossible(keyName), scope.QuoteIfPossible(field), dest, onDelete, onUpdate)).Exec()
scope.Raw(fmt.Sprintf(query, scope.QuotedTableName(), scope.quoteIfPossible(keyName), scope.quoteIfPossible(field), dest, onDelete, onUpdate)).Exec()
}
func (scope *Scope) removeIndex(indexName string) {