query_set_components_update_table.go 1.2 KB
package domain

func (qc *QueryComponent) UpdateTables(tables ...*Table) {
	for _, table := range tables {
		qc.updateTable(table)
	}
}
func (qc *QueryComponent) updateTable(table *Table) {
	for i := range qc.Conditions {
		qc.Conditions[i].FieldLeft.UpdateTable(table)
		qc.Conditions[i].FieldRight.UpdateTable(table)
	}
	for i := range qc.Selects {
		qc.Selects[i].FieldLeft.UpdateTable(table)
		qc.Selects[i].FieldRight.UpdateTable(table)
		for j := range qc.Selects[i].SubSelects {
			qc.Selects[i].SubSelects[j].FieldLeft.UpdateTable(table)
			qc.Selects[i].SubSelects[j].FieldRight.UpdateTable(table)
		}
	}
	if qc.Formula != nil && len(qc.Formula.ExprHuman) > 0 {
		qc.Formula.FieldExpr.UpdateTable(table)
	}
	if qc.Aggregation != nil {
		for i := range qc.Aggregation.RowFields {
			qc.Aggregation.RowFields[i].Expr.UpdateTable(table)
		}
		for i := range qc.Aggregation.ValueFields {
			qc.Aggregation.ValueFields[i].Expr.UpdateTable(table)
		}
	}
	if qc.Layout != nil {
		for i := range qc.Layout.Cells {
			if qc.Layout.Cells[i].Data == nil || qc.Layout.Cells[i].Data.TableField == nil {
				continue
			}
			if qc.Layout.Cells[i].Data.TableField.TableId == table.TableId {
				qc.Layout.Cells[i].Data.TableField.TableName = table.Name
			}
		}
	}
}