dzql 0.4.6 → 0.4.8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dzql",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
4
4
  "description": "PostgreSQL-powered framework with zero boilerplate CRUD operations and real-time WebSocket synchronization",
5
5
  "type": "module",
6
6
  "main": "src/server/index.js",
@@ -267,7 +267,8 @@ CREATE OR REPLACE FUNCTION search_${this.tableName}(
267
267
  p_search TEXT DEFAULT NULL,
268
268
  p_sort JSONB DEFAULT NULL,
269
269
  p_page INT DEFAULT 1,
270
- p_limit INT DEFAULT 25
270
+ p_limit INT DEFAULT 25,
271
+ p_on_date TIMESTAMPTZ DEFAULT NULL
271
272
  ) RETURNS JSONB AS $$
272
273
  DECLARE
273
274
  v_data JSONB;
@@ -280,8 +281,10 @@ DECLARE
280
281
  v_filter JSONB;
281
282
  v_operator TEXT;
282
283
  v_value JSONB;
284
+ v_on_date TIMESTAMPTZ;
283
285
  BEGIN
284
286
  v_offset := (p_page - 1) * p_limit;
287
+ v_on_date := COALESCE(p_on_date, NOW());
285
288
 
286
289
  -- Extract sort parameters
287
290
  v_sort_field := COALESCE(p_sort->>'field', '${this.entity.labelField}');
@@ -329,8 +332,7 @@ BEGIN
329
332
  v_where_clause := v_where_clause || ' AND (${searchConditions})';
330
333
  END IF;
331
334
 
332
- -- Add temporal filter
333
- v_where_clause := v_where_clause || '${this._generateTemporalFilter().replace(/\n/g, ' ')}';
335
+ -- Add temporal filter${this._generateTemporalFilterForSearch()}
334
336
 
335
337
  -- Get total count
336
338
  EXECUTE format('SELECT COUNT(*) FROM ${this.tableName} WHERE %s', v_where_clause) INTO v_total;
@@ -754,7 +756,7 @@ $$ LANGUAGE plpgsql SECURITY DEFINER;`;
754
756
  }
755
757
 
756
758
  /**
757
- * Generate temporal filter
759
+ * Generate temporal filter for static SQL (GET, LOOKUP)
758
760
  * @private
759
761
  */
760
762
  _generateTemporalFilter() {
@@ -770,6 +772,23 @@ $$ LANGUAGE plpgsql SECURITY DEFINER;`;
770
772
  AND (${validTo} > COALESCE(p_on_date, NOW()) OR ${validTo} IS NULL)`;
771
773
  }
772
774
 
775
+ /**
776
+ * Generate temporal filter for SEARCH function (dynamic SQL with EXECUTE)
777
+ * Uses format() to properly interpolate the v_on_date variable
778
+ * @private
779
+ */
780
+ _generateTemporalFilterForSearch() {
781
+ if (!this.entity.temporalFields || Object.keys(this.entity.temporalFields).length === 0) {
782
+ return '';
783
+ }
784
+
785
+ const validFrom = this.entity.temporalFields.valid_from || 'valid_from';
786
+ const validTo = this.entity.temporalFields.valid_to || 'valid_to';
787
+
788
+ return `
789
+ v_where_clause := v_where_clause || format(' AND ${validFrom} <= %L AND (${validTo} > %L OR ${validTo} IS NULL)', v_on_date, v_on_date);`;
790
+ }
791
+
773
792
  /**
774
793
  * Check if a trigger has any rules with actions
775
794
  * @private
package/src/server/db.js CHANGED
@@ -207,7 +207,7 @@ export async function callDZQLOperation(operation, entity, args, userId) {
207
207
  return result[0].result;
208
208
  } else if (operation === 'save') {
209
209
  const result = await sql.unsafe(`
210
- SELECT ${compiledFunctionName}($1::int, $2::jsonb, NULL) as result
210
+ SELECT ${compiledFunctionName}($1::int, $2::jsonb) as result
211
211
  `, [userId, args]);
212
212
  return result[0].result;
213
213
  } else if (operation === 'delete') {