@transitive-sdk/clickhouse 0.3.2 → 0.3.3

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.
Files changed (2) hide show
  1. package/index.js +13 -25
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -260,35 +260,26 @@ class ClickHouse {
260
260
  * @param {string} topic - MQTT topic to register
261
261
  */
262
262
  async registerMqttTopicForStorage(selector, ttlDays = DEFAULT_TTL_DAYS) {
263
- this.topics[selector] = true;
264
-
265
- // ---------------------------------------------------------------
266
- // Set/update TTL for this capability and sub-topic
267
263
 
268
264
  const path = topicToPath(selector);
269
265
 
270
266
  if (path.length < 4) {
271
267
  // underspecified, don't set TTL
268
+ console.warn('Not registering topic as it is too short', selector);
272
269
  return;
273
270
  }
274
271
 
275
- // list of TopicParts indices and selected value to use in WHERE statement
276
- // const topicPartSelectors = [
277
- // [2, path[2]],
278
- // [3, path[3]]
279
- // ];
272
+ this.topics[selector] = true;
280
273
 
281
- // path.slice(5).forEach((value, i) => topicPartSelectors.push([i + 5, value]));
274
+ // ---------------------------------------------------------------
275
+ // Set/update TTL for this capability and sub-topic
282
276
 
283
- // const where = topicPartSelectors
284
- // // filter out wildcards
285
- // .filter(([i, value]) => !['+','#'].includes(value[0]))
286
- // // map to WHERE conditions
287
- // .map(([i, value]) => `((TopicParts[${i + 1}]) = '${value}')`);
277
+ // Derive WHERE conditions for TTL expression from non-wildcards
288
278
  const where = path2where(path);
289
279
 
290
280
  if (where.length == 0) {
291
281
  // underspecified, don't set TTL
282
+ console.warn('Not setting TTL as topic is under specified', selector);
292
283
  return;
293
284
  }
294
285
 
@@ -307,17 +298,14 @@ class ClickHouse {
307
298
  const newTTLStatement =
308
299
  `toDateTime(Timestamp) + toIntervalDay(${ttlDays}) ${whereStatement}`;
309
300
 
310
- let present = false;
311
- // check if TTL statement already present on table definiton
312
- ttls.forEach((ttl, i) => {
313
- if (ttl.replace(/[()]/g, '').endsWith(whereStatement)) {
314
- // condition already present, just replace it to update time
315
- ttls[i] = newTTLStatement;
316
- present = true;
317
- }
318
- });
301
+ const currentIndex =
302
+ ttls.findIndex(ttl => ttl.replace(/[()]/g, '').endsWith(whereStatement));
319
303
 
320
- if (!present) {
304
+ if (currentIndex >= 0) {
305
+ // replace existing
306
+ ttls[currentIndex] = newTTLStatement;
307
+ } else {
308
+ // add new
321
309
  ttls.push(newTTLStatement);
322
310
  }
323
311
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transitive-sdk/clickhouse",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "A tiny ClickHouse utility class for use in the Transitive framework.",
5
5
  "homepage": "https://transitiverobotics.com",
6
6
  "repository": {