|
@ -145,6 +145,27 @@ func (this *Query) Join(join []string) *Query { |
|
|
this.join = append(this.join, join) |
|
|
this.join = append(this.join, join) |
|
|
return this |
|
|
return this |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 左连接 |
|
|
|
|
|
* 2023/08/10 |
|
|
|
|
|
* gz |
|
|
|
|
|
*/ |
|
|
|
|
|
func (this *Query) LeftJoin(table_name string, condition string) *Query { |
|
|
|
|
|
this.join = append(this.join, []string{table_name, condition, "left"}) |
|
|
|
|
|
return this |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 右连接 |
|
|
|
|
|
* 2023/08/10 |
|
|
|
|
|
* gz |
|
|
|
|
|
*/ |
|
|
|
|
|
func (this *Query) RightJoin(table_name string, condition string) *Query { |
|
|
|
|
|
this.join = append(this.join, []string{table_name, condition, "right"}) |
|
|
|
|
|
return this |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (this *Query) Data(data string) *Query { |
|
|
func (this *Query) Data(data string) *Query { |
|
|
this.data = append(this.data, data) |
|
|
this.data = append(this.data, data) |
|
|
return this |
|
|
return this |
|
@ -290,15 +311,17 @@ func (this *Query) BuildSelectSql() (map[string]interface{}, error) { |
|
|
sql = helper.StringJoin(sql, " from ", table) |
|
|
sql = helper.StringJoin(sql, " from ", table) |
|
|
|
|
|
|
|
|
if len(this.join) > 0 { |
|
|
if len(this.join) > 0 { |
|
|
|
|
|
join_type := "left" |
|
|
for _, joinitem := range this.join { |
|
|
for _, joinitem := range this.join { |
|
|
if len(joinitem) < 2 { |
|
|
if len(joinitem) < 2 { |
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
|
if len(joinitem) == 3 { |
|
|
if len(joinitem) == 3 { |
|
|
sql = helper.StringJoin(sql, " ", joinitem[2], " join ", getTableName(this.dbname, joinitem[0], this.dbtype), " on ", joinitem[1]) |
|
|
|
|
|
|
|
|
join_type = joinitem[2] |
|
|
} else { //默认左连接
|
|
|
} else { //默认左连接
|
|
|
sql = helper.StringJoin(sql, " left join ", getTableName(this.dbname, joinitem[0], this.dbtype), " on ", joinitem[1]) |
|
|
|
|
|
|
|
|
join_type = "left" |
|
|
} |
|
|
} |
|
|
|
|
|
sql = helper.StringJoin(sql, " ", join_type, " join ", getTableName(this.dbname, joinitem[0], this.dbtype), " on ", joinitem[1]) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if len(this.where) > 0 || len(this.where_or) > 0 { |
|
|
if len(this.where) > 0 || len(this.where_or) > 0 { |
|
|