| 585 | } |
| 586 | |
| 587 | func (c chainG[T]) Build(builder clause.Builder) { |
| 588 | subdb := c.getInstance() |
| 589 | subdb.Logger = logger.Discard |
| 590 | subdb.DryRun = true |
| 591 | |
| 592 | if stmt, ok := builder.(*Statement); ok { |
| 593 | if subdb.Statement.SQL.Len() > 0 { |
| 594 | var ( |
| 595 | vars = subdb.Statement.Vars |
| 596 | sql = subdb.Statement.SQL.String() |
| 597 | ) |
| 598 | |
| 599 | subdb.Statement.Vars = make([]interface{}, 0, len(vars)) |
| 600 | for _, vv := range vars { |
| 601 | subdb.Statement.Vars = append(subdb.Statement.Vars, vv) |
| 602 | bindvar := strings.Builder{} |
| 603 | subdb.BindVarTo(&bindvar, subdb.Statement, vv) |
| 604 | sql = strings.Replace(sql, bindvar.String(), "?", 1) |
| 605 | } |
| 606 | |
| 607 | subdb.Statement.SQL.Reset() |
| 608 | subdb.Statement.Vars = stmt.Vars |
| 609 | if strings.Contains(sql, "@") { |
| 610 | clause.NamedExpr{SQL: sql, Vars: vars}.Build(subdb.Statement) |
| 611 | } else { |
| 612 | clause.Expr{SQL: sql, Vars: vars}.Build(subdb.Statement) |
| 613 | } |
| 614 | } else { |
| 615 | subdb.Statement.Vars = append(stmt.Vars, subdb.Statement.Vars...) |
| 616 | subdb.callbacks.Query().Execute(subdb) |
| 617 | } |
| 618 | |
| 619 | builder.WriteString(subdb.Statement.SQL.String()) |
| 620 | stmt.Vars = subdb.Statement.Vars |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | type execG[T any] struct { |
| 625 | g *g[T] |