Build converts the expression into a SQL fragment. Implements [dbx.Expression] interface.
(db *dbx.DB, params dbx.Params)
| 630 | // |
| 631 | // Implements [dbx.Expression] interface. |
| 632 | func (e *manyVsManyExpr) Build(db *dbx.DB, params dbx.Params) string { |
| 633 | if e.left.MultiMatchSubQuery == nil || e.right.MultiMatchSubQuery == nil { |
| 634 | return "0=1" |
| 635 | } |
| 636 | |
| 637 | lAlias := "__ml" + security.PseudorandomString(8) |
| 638 | rAlias := "__mr" + security.PseudorandomString(8) |
| 639 | |
| 640 | whereExpr, buildErr := buildResolversExpr( |
| 641 | &ResolverResult{ |
| 642 | NullFallback: e.left.NullFallback, |
| 643 | Identifier: "[[" + lAlias + ".multiMatchValue]]", |
| 644 | }, |
| 645 | e.op, |
| 646 | &ResolverResult{ |
| 647 | NullFallback: e.right.NullFallback, |
| 648 | Identifier: "[[" + rAlias + ".multiMatchValue]]", |
| 649 | // note: the AfterBuild needs to be handled only once and it |
| 650 | // doesn't matter whether it is applied on the left or right subquery operand |
| 651 | AfterBuild: dbx.Not, // inverse for the not-exist expression |
| 652 | }, |
| 653 | ) |
| 654 | |
| 655 | if buildErr != nil { |
| 656 | return "0=1" |
| 657 | } |
| 658 | |
| 659 | return fmt.Sprintf( |
| 660 | "NOT EXISTS (SELECT 1 FROM (%s) {{%s}} LEFT JOIN (%s) {{%s}} WHERE %s)", |
| 661 | e.left.MultiMatchSubQuery.Build(db, params), |
| 662 | lAlias, |
| 663 | e.right.MultiMatchSubQuery.Build(db, params), |
| 664 | rAlias, |
| 665 | whereExpr.Build(db, params), |
| 666 | ) |
| 667 | } |
| 668 | |
| 669 | // ------------------------------------------------------------------- |
| 670 |
nothing calls this directly
no test coverage detected