* Convert a WITH clause into a WithStep.
(withClause: WithClause)
| 796 | * Convert a WITH clause into a WithStep. |
| 797 | */ |
| 798 | function convertWithClause(withClause: WithClause): WithStep { |
| 799 | const items: WithItemConfig[] = withClause.items.map((item) => convertWithItem(item)); |
| 800 | |
| 801 | // Convert ORDER BY if present |
| 802 | // Build alias map from WITH items for alias resolution |
| 803 | const aliasMap = buildWithAliasMap(withClause.items); |
| 804 | const orderBy = withClause.orderBy |
| 805 | ? withClause.orderBy.orders.map( |
| 806 | (order) => resolveOrderItem(order, aliasMap, true), // true = use alias directly for WITH ORDER BY |
| 807 | ) |
| 808 | : undefined; |
| 809 | |
| 810 | // Convert WHERE condition if present |
| 811 | const whereCondition = withClause.where |
| 812 | ? convertCondition(withClause.where.condition) |
| 813 | : undefined; |
| 814 | |
| 815 | return new WithStep({ |
| 816 | distinct: withClause.distinct, |
| 817 | items, |
| 818 | orderBy, |
| 819 | skip: withClause.skip, |
| 820 | limit: withClause.limit, |
| 821 | whereCondition, |
| 822 | }); |
| 823 | } |
| 824 | |
| 825 | /** |
| 826 | * Convert a WITH item AST node to a WithItemConfig. |
no test coverage detected