linkgress-orm 0.0.1 → 0.0.2

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.
@@ -74,20 +74,20 @@ class TempTableCollectionStrategy {
74
74
  // Determine if we're doing client-side grouping (JSONB/array) or server-side (scalar)
75
75
  const isClientSideGrouping = config.aggregationType === 'jsonb' || config.aggregationType === 'array';
76
76
  // Combine everything into a single multi-statement query
77
- const multiStatementSQL = `
78
- -- Create temporary table for parent IDs
79
- CREATE TEMP TABLE ${tempTableName} (
80
- id integer PRIMARY KEY
81
- ) ON COMMIT DROP;
82
-
83
- -- Insert parent IDs
84
- INSERT INTO ${tempTableName} VALUES ${valuePlaceholders};
85
-
86
- -- Query and return the data
87
- ${aggregationSQL};
88
-
89
- -- Cleanup
90
- DROP TABLE IF EXISTS ${tempTableName};
77
+ const multiStatementSQL = `
78
+ -- Create temporary table for parent IDs
79
+ CREATE TEMP TABLE ${tempTableName} (
80
+ id integer PRIMARY KEY
81
+ ) ON COMMIT DROP;
82
+
83
+ -- Insert parent IDs
84
+ INSERT INTO ${tempTableName} VALUES ${valuePlaceholders};
85
+
86
+ -- Query and return the data
87
+ ${aggregationSQL};
88
+
89
+ -- Cleanup
90
+ DROP TABLE IF EXISTS ${tempTableName};
91
91
  `.trim();
92
92
  // Execute multi-statement query using querySimple (no parameters)
93
93
  const executor = context.executor || client;
@@ -158,10 +158,10 @@ DROP TABLE IF EXISTS ${tempTableName};
158
158
  async buildAggregationLegacy(config, context, client) {
159
159
  const tempTableName = `tmp_parent_ids_${config.counter}`;
160
160
  // Create temp table (without ON COMMIT DROP to persist across queries in the same session)
161
- const createTableSQL = `
162
- CREATE TEMP TABLE IF NOT EXISTS ${tempTableName} (
163
- id integer PRIMARY KEY
164
- )
161
+ const createTableSQL = `
162
+ CREATE TEMP TABLE IF NOT EXISTS ${tempTableName} (
163
+ id integer PRIMARY KEY
164
+ )
165
165
  `.trim();
166
166
  // Use executor from context if available for query logging
167
167
  if (context.executor) {
@@ -186,9 +186,9 @@ CREATE TEMP TABLE IF NOT EXISTS ${tempTableName} (
186
186
  const selectExpression = `"${tempTableName}_agg".data`;
187
187
  // Execute aggregation query and store results in another temp table
188
188
  const aggTempTableName = `${tempTableName}_agg`;
189
- const createAggTableSQL = `
190
- CREATE TEMP TABLE ${aggTempTableName} AS
191
- ${aggregationSQL}
189
+ const createAggTableSQL = `
190
+ CREATE TEMP TABLE ${aggTempTableName} AS
191
+ ${aggregationSQL}
192
192
  `.trim();
193
193
  // Use executor from context if available for query logging
194
194
  if (context.executor) {
@@ -287,14 +287,14 @@ ${aggregationSQL}
287
287
  limitOffsetClause += ` OFFSET ${offsetValue}`;
288
288
  }
289
289
  // Simple SELECT with foreign key for grouping
290
- const sql = `
291
- SELECT
292
- "${foreignKey}" as parent_id,
293
- ${selectFields}
294
- FROM "${targetTable}"
295
- WHERE "${foreignKey}" IN (SELECT id FROM ${tempTableName})${additionalWhere}
296
- ${orderBySQL}
297
- ${limitOffsetClause}
290
+ const sql = `
291
+ SELECT
292
+ "${foreignKey}" as parent_id,
293
+ ${selectFields}
294
+ FROM "${targetTable}"
295
+ WHERE "${foreignKey}" IN (SELECT id FROM ${tempTableName})${additionalWhere}
296
+ ${orderBySQL}
297
+ ${limitOffsetClause}
298
298
  `.trim();
299
299
  return sql;
300
300
  }
@@ -361,20 +361,20 @@ ${limitOffsetClause}
361
361
  // Build jsonb_agg ORDER BY clause
362
362
  const jsonbAggOrderBy = orderByClause ? ` ORDER BY ${orderByClause}` : '';
363
363
  // Build the SQL - matching JSONB strategy approach
364
- const sql = `
365
- SELECT
366
- t."${foreignKey}" as parent_id,
367
- jsonb_agg(
368
- jsonb_build_object(${jsonbFields})${jsonbAggOrderBy}
369
- ) as data
370
- FROM (
371
- SELECT *
372
- FROM "${targetTable}"
373
- WHERE "${foreignKey}" IN (SELECT id FROM ${tempTableName})${additionalWhere}
374
- ${orderBySQL}
375
- ${limitOffsetClause}
376
- ) t
377
- GROUP BY t."${foreignKey}"
364
+ const sql = `
365
+ SELECT
366
+ t."${foreignKey}" as parent_id,
367
+ jsonb_agg(
368
+ jsonb_build_object(${jsonbFields})${jsonbAggOrderBy}
369
+ ) as data
370
+ FROM (
371
+ SELECT *
372
+ FROM "${targetTable}"
373
+ WHERE "${foreignKey}" IN (SELECT id FROM ${tempTableName})${additionalWhere}
374
+ ${orderBySQL}
375
+ ${limitOffsetClause}
376
+ ) t
377
+ GROUP BY t."${foreignKey}"
378
378
  `.trim();
379
379
  return sql;
380
380
  }
@@ -401,18 +401,18 @@ GROUP BY t."${foreignKey}"
401
401
  // Build array_agg ORDER BY clause
402
402
  const arrayAggOrderBy = orderByClause ? ` ORDER BY ${orderByClause}` : '';
403
403
  // Build the SQL - matching JSONB strategy approach
404
- const sql = `
405
- SELECT
406
- t."${foreignKey}" as parent_id,
407
- array_agg(t."${arrayField}"${arrayAggOrderBy}) as data
408
- FROM (
409
- SELECT "${foreignKey}", "${arrayField}"
410
- FROM "${targetTable}"
411
- WHERE "${foreignKey}" IN (SELECT id FROM ${tempTableName})${additionalWhere}
412
- ${orderBySQL}
413
- ${limitOffsetClause}
414
- ) t
415
- GROUP BY t."${foreignKey}"
404
+ const sql = `
405
+ SELECT
406
+ t."${foreignKey}" as parent_id,
407
+ array_agg(t."${arrayField}"${arrayAggOrderBy}) as data
408
+ FROM (
409
+ SELECT "${foreignKey}", "${arrayField}"
410
+ FROM "${targetTable}"
411
+ WHERE "${foreignKey}" IN (SELECT id FROM ${tempTableName})${additionalWhere}
412
+ ${orderBySQL}
413
+ ${limitOffsetClause}
414
+ ) t
415
+ GROUP BY t."${foreignKey}"
416
416
  `.trim();
417
417
  return sql;
418
418
  }
@@ -441,13 +441,13 @@ GROUP BY t."${foreignKey}"
441
441
  default:
442
442
  throw new Error(`Unknown aggregation type: ${aggregationType}`);
443
443
  }
444
- const sql = `
445
- SELECT
446
- tmp.id as parent_id,
447
- COALESCE(${aggregateExpression}, ${config.defaultValue}) as data
448
- FROM ${tempTableName} tmp
449
- LEFT JOIN "${targetTable}" t ON t."${foreignKey}" = tmp.id${additionalWhere}
450
- GROUP BY tmp.id
444
+ const sql = `
445
+ SELECT
446
+ tmp.id as parent_id,
447
+ COALESCE(${aggregateExpression}, ${config.defaultValue}) as data
448
+ FROM ${tempTableName} tmp
449
+ LEFT JOIN "${targetTable}" t ON t."${foreignKey}" = tmp.id${additionalWhere}
450
+ GROUP BY tmp.id
451
451
  `.trim();
452
452
  return sql;
453
453
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linkgress-orm",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "A lightweight, type-safe ORM for PostgreSQL with LINQ-style queries and automatic type inference",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",