From c3b84c6ae2abccfe14b8a0222c680682647040e7 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 8 Apr 2018 17:21:58 +0800 Subject: [PATCH] Join add struct support --- statement.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/statement.go b/statement.go index ef2011fa..adf3e2fb 100644 --- a/statement.go +++ b/statement.go @@ -766,12 +766,13 @@ func (statement *Statement) Join(joinOP string, tablename interface{}, condition var table string if l > 0 { f := t[0] - v := rValue(f) - t := v.Type() - if t.Kind() == reflect.String { + switch f.(type) { + case string: table = f.(string) - } else if t.Kind() == reflect.Struct { - table = statement.Engine.tbName(v) + case TableName: + table = f.(TableName).TableName() + default: + // FIXME: error } } if l > 1 { @@ -782,8 +783,16 @@ func (statement *Statement) Join(joinOP string, tablename interface{}, condition } case TableName: fmt.Fprintf(&buf, tablename.(TableName).TableName()) + case string: + fmt.Fprintf(&buf, tablename.(string)) default: - fmt.Fprintf(&buf, statement.Engine.Quote(fmt.Sprintf("%v", tablename))) + v := rValue(tablename) + t := v.Type() + if t.Kind() == reflect.Struct { + fmt.Fprintf(&buf, statement.Engine.tbName(v)) + } else { + fmt.Fprintf(&buf, statement.Engine.Quote(fmt.Sprintf("%v", tablename))) + } } fmt.Fprintf(&buf, " ON %v", condition)