@loomcore/api 0.1.114 → 0.1.116

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import { LeftJoin } from "../../operations/left-join.operation.js";
2
2
  import { InnerJoin } from "../../operations/inner-join.operation.js";
3
+ import { LeftJoinMany } from "../../operations/left-join-many.operation.js";
3
4
  import { toSnakeCase } from "./convert-keys.util.js";
4
5
  function convertFieldToSnakeCase(field) {
5
6
  if (field.startsWith("_")) {
@@ -8,15 +9,14 @@ function convertFieldToSnakeCase(field) {
8
9
  return toSnakeCase(field);
9
10
  }
10
11
  export function buildJoinClauses(operations, mainTableName) {
11
- let joinClauses = [];
12
+ const joinClauses = [];
12
13
  for (const operation of operations) {
13
- if (operation instanceof LeftJoin || operation instanceof InnerJoin) {
14
- const localRef = convertFieldToSnakeCase(operation.localField);
15
- const foreignSnake = convertFieldToSnakeCase(operation.foreignField);
14
+ if (operation instanceof LeftJoin || operation instanceof InnerJoin || operation instanceof LeftJoinMany) {
16
15
  const joinType = operation instanceof InnerJoin ? "INNER JOIN" : "LEFT JOIN";
17
- const joinTable = `"${operation.from}" AS "${operation.as}"`;
18
- const leftSide = mainTableName ? `"${mainTableName}"."${localRef}"` : localRef;
19
- joinClauses.push(`${joinType} ${joinTable} ON ${leftSide} = ${operation.as}."${foreignSnake}"`);
16
+ const localColumn = convertFieldToSnakeCase(operation.localField);
17
+ const foreignColumn = convertFieldToSnakeCase(operation.foreignField);
18
+ const leftSide = mainTableName ? `"${mainTableName}"."${localColumn}"` : `"${localColumn}"`;
19
+ joinClauses.push(`${joinType} "${operation.from}" AS "${operation.as}" ON ${leftSide} = ${operation.as}."${foreignColumn}"`);
20
20
  }
21
21
  }
22
22
  return joinClauses.join(' ');
@@ -1,6 +1,7 @@
1
1
  import { LeftJoin } from '../../operations/left-join.operation.js';
2
2
  import { InnerJoin } from '../../operations/inner-join.operation.js';
3
3
  import { LeftJoinMany } from '../../operations/left-join-many.operation.js';
4
+ import { buildAs } from './build-things.util.js';
4
5
  async function getTableColumns(client, tableName) {
5
6
  const result = await client.query(`
6
7
  SELECT column_name
@@ -29,10 +30,10 @@ export async function buildSelectClause(client, mainTableName, operations) {
29
30
  const mainTableColumns = await getTableColumns(client, mainTableName);
30
31
  const mainSelects = mainTableColumns.map(col => `"${mainTableName}"."${col}" AS "${col}"`);
31
32
  const joinSelects = [];
32
- for (const join of [...leftJoinOperations, ...leftJoinManyOperations, ...innerJoinOperations]) {
33
+ for (const join of [...leftJoinOperations, ...innerJoinOperations, ...leftJoinManyOperations]) {
33
34
  const joinColumns = await getTableColumns(client, join.from);
34
35
  for (const col of joinColumns) {
35
- joinSelects.push(`${join.as}."${col}" AS "${join.as}__${col}"`);
36
+ joinSelects.push(`${join.as}."${col}" AS "${buildAs(col, join)}"`);
36
37
  }
37
38
  }
38
39
  const allSelects = [...mainSelects, ...joinSelects];
@@ -0,0 +1,2 @@
1
+ import { Operation } from "../../operations/index.js";
2
+ export declare function buildAs(columnName: string, operation: Operation): string;
@@ -0,0 +1,3 @@
1
+ export function buildAs(columnName, operation) {
2
+ return `${operation.as}__${columnName}`;
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.1.114",
3
+ "version": "0.1.116",
4
4
  "private": false,
5
5
  "description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb or PostgreSQL",
6
6
  "scripts": {