|
1 |
| -import { Join, OrderBy, SimpleWhere, WhereCondition } from "../types"; |
| 1 | +import {Join, ManyToManyJoin, OrderBy, SimpleWhere, WhereCondition} from "../types"; |
2 | 2 | import { toSnakeCase } from "./formatting";
|
3 | 3 |
|
4 | 4 | /**
|
@@ -181,6 +181,48 @@ export const buildJoinClause = <T>(
|
181 | 181 | };
|
182 | 182 | };
|
183 | 183 |
|
| 184 | + |
| 185 | +/** |
| 186 | + * Builds JOIN clauses for SQL queries |
| 187 | + */ |
| 188 | +// export const buildJoinManyToManyClause = <T>( |
| 189 | +// joins?: Array<ManyToManyJoin<any, any>>, |
| 190 | +// baseTableName?: string |
| 191 | +// ): { joinConditionClause: string; joinSelectClause: string[] } => { |
| 192 | +// if (!joins || joins.length === 0) { |
| 193 | +// return { |
| 194 | +// joinConditionClause: "", |
| 195 | +// joinSelectClause: [] |
| 196 | +// }; |
| 197 | +// } |
| 198 | + |
| 199 | +// const joinConditions = joins.map((join) => { |
| 200 | +// const joinType = join.type.toUpperCase(); |
| 201 | +// const alias = join.as || join.table; |
| 202 | +// const foreignField = join.on.foreignField as any; |
| 203 | +// const localField = join.on.localField as any; |
| 204 | +// return `${joinType} JOIN "${join.table}" AS "${alias}" ON "${alias}"."${foreignField}" = "${baseTableName}"."${localField}"`; |
| 205 | +// }); |
| 206 | +// |
| 207 | +// const joinSelectClause = joins |
| 208 | +// .map((join) => { |
| 209 | +// if (!join.columns || join.columns.length === 0) return ""; |
| 210 | +// |
| 211 | +// const alias = join.as || join.table; |
| 212 | +// const jsonColumns = join.columns |
| 213 | +// .map((col) => `'${col.toString()}', "${alias}"."${col.toString()}"`) |
| 214 | +// .join(", "); |
| 215 | +// |
| 216 | +// return `json_build_object(${jsonColumns}) AS ${alias}`; |
| 217 | +// }) |
| 218 | +// .filter(Boolean); |
| 219 | +// |
| 220 | +// return { |
| 221 | +// joinConditionClause: joinConditions.join(" "), |
| 222 | +// joinSelectClause |
| 223 | +// }; |
| 224 | +// }; |
| 225 | + |
184 | 226 | /**
|
185 | 227 | * Builds a SET clause for UPDATE SQL statements with proper type handling
|
186 | 228 | */
|
|
0 commit comments