iobroker.sql 3.0.1 → 4.0.0

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 (52) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +138 -424
  3. package/admin/i18n/de/translations.json +1 -1
  4. package/admin/i18n/en/translations.json +1 -1
  5. package/admin/i18n/es/translations.json +12 -12
  6. package/admin/i18n/fr/translations.json +1 -1
  7. package/admin/i18n/it/translations.json +1 -1
  8. package/admin/i18n/nl/translations.json +1 -1
  9. package/admin/i18n/pt/translations.json +1 -1
  10. package/admin/i18n/ru/translations.json +1 -1
  11. package/admin/jsonConfig.json +423 -321
  12. package/admin/words.js +12 -12
  13. package/build/lib/aggregate.js +1484 -0
  14. package/build/lib/aggregate.js.map +1 -0
  15. package/build/lib/connection-factory.js +7 -0
  16. package/build/lib/connection-factory.js.map +1 -0
  17. package/build/lib/mssql-client.js +67 -0
  18. package/build/lib/mssql-client.js.map +1 -0
  19. package/build/lib/mssql.js +267 -0
  20. package/build/lib/mssql.js.map +1 -0
  21. package/build/lib/mysql-client.js +55 -0
  22. package/build/lib/mysql-client.js.map +1 -0
  23. package/build/lib/mysql.js +245 -0
  24. package/build/lib/mysql.js.map +1 -0
  25. package/build/lib/postgresql-client.js +56 -0
  26. package/build/lib/postgresql-client.js.map +1 -0
  27. package/build/lib/postgresql.js +241 -0
  28. package/build/lib/postgresql.js.map +1 -0
  29. package/build/lib/sql-client-pool.js +369 -0
  30. package/build/lib/sql-client-pool.js.map +1 -0
  31. package/build/lib/sql-client.js +110 -0
  32. package/build/lib/sql-client.js.map +1 -0
  33. package/build/lib/sqlite.js +244 -0
  34. package/build/lib/sqlite.js.map +1 -0
  35. package/build/lib/sqlite3-client.js +68 -0
  36. package/build/lib/sqlite3-client.js.map +1 -0
  37. package/build/main.js +3591 -0
  38. package/build/main.js.map +1 -0
  39. package/docker-compose.yaml +57 -0
  40. package/io-package.json +41 -19
  41. package/package.json +28 -20
  42. package/admin/.gitignore +0 -0
  43. package/lib/aggregate.js +0 -1000
  44. package/lib/mssql-client.js +0 -61
  45. package/lib/mssql.js +0 -278
  46. package/lib/mysql-client.js +0 -62
  47. package/lib/mysql.js +0 -263
  48. package/lib/postgresql-client.js +0 -202
  49. package/lib/postgresql.js +0 -260
  50. package/lib/sqlite.js +0 -260
  51. package/lib/tools.js +0 -99
  52. package/main.js +0 -3469
package/README.md CHANGED
@@ -12,7 +12,7 @@ This adapter saves state history into SQL DB.
12
12
  Supports PostgreSQL, mysql, Microsoft SQL Server and sqlite.
13
13
  You can leave port 0 if the default port is desired.
14
14
 
15
- **This adapter uses Sentry libraries to automatically report exceptions and code errors to the developers.** For more details and for information how to disable the error reporting see [Sentry-Plugin Documentation](https://github.com/ioBroker/plugin-sentry#plugin-sentry)! Sentry reporting is used starting with js-controller 3.0.
15
+ **This adapter uses Sentry libraries to automatically report exceptions and code errors to the developers.** For more details and for information how to disable the error reporting, see [Sentry-Plugin Documentation](https://github.com/ioBroker/plugin-sentry#plugin-sentry)! Sentry reporting is used starting with js-controller 3.0.
16
16
 
17
17
  ## Settings
18
18
 
@@ -30,15 +30,15 @@ You can leave port 0 if the default port is desired.
30
30
  - **Do not create database**: Activate this option if a database already created (e.g. by administrator) and the ioBroker-user does not have enough rights to create a DB.
31
31
 
32
32
  ## Default Settings
33
- - **Debounce Time** - Protection against unstable values to make sure that only stable values are logged when the value did not change in the defined amount of Milliseconds. ATTENTION: If values change more often then this setting effectively no value will be logged (because any value is unstable)
34
- - **Blocktime** - Defines for how long after storing the last value no further value is stored. When the given time in Milliseconds is over then the next value that fulfills all other checks is logged.
33
+ - **Debounce Time** - Protection against unstable values to make sure that only stable values are logged when the value did not change in the defined amount of Milliseconds. ATTENTION: If values change more often than this setting effectively, no value will be logged (because any value is unstable)
34
+ - **Blocktime** - Defines for how long after storing the last value no further value is stored. When the given time in Milliseconds is over, then the next value that fulfills all other checks is logged.
35
35
  - **Record changes only** - This function makes sure that only changed values are logged if they fulfill other checks (see below). Same values will not be logged.
36
36
  - **still record the same values (seconds)** - When using "Record changes only" you can set a time interval in seconds here after which also unchanged values will be re-logged into the DB. You can detect the values re-logged by the adapter with the "from" field.
37
- - **Minimum difference from last value** - When using "Record changes only" you can define the required minimum difference between the new value and the last value. If this is not reached the value is not recorded.
37
+ - **Minimum difference from the last value** - When using "Record changes only" you can define the required minimum difference between the new value and the last value. If this is not reached, the value is not recorded.
38
38
  - **ignore 0 or null values (==0)** - You can define if 0 or null values should be ignored.
39
39
  - **ignore values below zero (<0)** - You can define if values below zero should be ignored.
40
40
  - **Disable charting optimized logging of skipped values** - By default, the adapter tries to record the values for optimized charting. This can mean that additional values (that e.g. not fulfilled all checks above) are logged automatically. If this is not wanted, you can disable this feature.
41
- - **Alias-ID** - You can define an alias for the ID. This is useful if you have changed a device and want to have continuous data logging. Please consider switching to real alias States in teh future!
41
+ - **Alias-ID** - You can define an alias for the ID. This is useful if you have changed a device and want to have continuous data logging. Please consider switching to real alias States in the future!
42
42
  - **Storage retention** - How many values in the past will be stored on disk. Data are deleted when the time is reached as soon as new data should be stored for a datapoint.
43
43
  - **Maximal number of stored in RAM values** - Define how many numbers of values will be held in RAM before persisting them on disk. You can control how much I/O is done.
44
44
  - **Enable enhanced debug logs for the datapoint** - If you want to see more detailed logs for this datapoint, you can enable this option. You still need to enable "debug" loglevel for these additional values to be visible! This helps in debugging issues or understanding why the adapter is logging a value (or not).
@@ -48,27 +48,21 @@ Most of these values can be pre-defined in the instance settings and are then pr
48
48
  ## Database installation tips
49
49
 
50
50
  ### MS-SQL:
51
- Use ```localhost\instance``` for the host and check TCP/IP connections enabled.
51
+ Use `localhost\instance` for the host and check TCP/IP connections enabled.
52
52
  https://msdn.microsoft.com/en-us/library/bb909712(v=vs.90).aspx
53
53
 
54
54
  ### SQLite:
55
- is "file"-DB and cannot manage too many events. If you have a big amount of data, use the real DB, like PostgreSQL and co.
55
+ is a "file"-DB and cannot manage too many events. If you have a big amount of data, use the real DB, like PostgreSQL and co.
56
56
 
57
57
  SQLite DB must not be installed extra. It is just a file on disk, but to install it you require build tools on your system. For linux, just write:
58
58
 
59
- ```
59
+ ```bash
60
60
  sudo apt-get install build-essential
61
61
  ```
62
62
 
63
- For windows:
64
-
65
- ```
66
- c:\>npm install --global --production windows-build-tools
67
- ```
68
-
69
- and then reinstall the adapter, e.g:
63
+ For windows install node.js with "Automatically install the necessary tools..."-option and then reinstall the adapter, e.g:
70
64
 
71
- ```
65
+ ```bash
72
66
  cd /opt/iobroker
73
67
  iobroker stop sql
74
68
  npm install iobroker.sql --production
@@ -78,7 +72,7 @@ iobroker start sql
78
72
  ### MySQL:
79
73
  You can install mysql on linux systems as following:
80
74
 
81
- ```
75
+ ```bash
82
76
  apt-get install mysql-server mysql-client
83
77
 
84
78
  mysql -u root -p
@@ -90,7 +84,7 @@ FLUSH PRIVILEGES;
90
84
 
91
85
  If required, edit */etc/mysql/my.cnf* to set bind to IP-Address for remote connecting.
92
86
 
93
- **Warning**: iobroker user is "admin". If required give limited rights to iobroker user.
87
+ **Warning**: iobroker user is "admin". If required, give limited rights to iobroker user.
94
88
 
95
89
  On the "windows" it can be easily installed via installer: https://dev.mysql.com/downloads/installer/.
96
90
 
@@ -101,7 +95,7 @@ Pay attention to the authentication method. The new encryption algorithm in MySQ
101
95
  ## Structure of the DBs
102
96
  The default Database name is `iobroker`, but it can be changed in the configuration.
103
97
  ### Sources
104
- This table is a list of adapter's instances, that wrote the entries. (state.from)
98
+ This table is a list of adapter's instances that wrote the entries. (state.from)
105
99
 
106
100
  | DB | Name in query |
107
101
  |------------|----------------------|
@@ -142,8 +136,8 @@ Structure:
142
136
  ### Numbers
143
137
  Values for states with type "number". **ts** means "time series".
144
138
 
145
- | DB | Name in query |
146
- |------------|-------------------------|
139
+ | DB | Name in query |
140
+ |------------|------------------------|
147
141
  | MS-SQL | iobroker.dbo.ts_number |
148
142
  | MySQL | iobroker.ts_number |
149
143
  | PostgreSQL | ts_number |
@@ -151,18 +145,19 @@ Values for states with type "number". **ts** means "time series".
151
145
 
152
146
  Structure:
153
147
 
154
- | Field | Type | Description |
155
- |--------|--------------------------------------------|-------------------------------------------------|
156
- | id | INTEGER | ID of state from "Data points" table |
157
- | ts | BIGINT / INTEGER | Time in ms till epoch. Can be converted to time with "new Date(ts)" |
158
- | val | REAL | Value |
159
- | ack | BIT/BOOLEAN | Is acknowledged: 0 - not ack, 1 - ack |
160
- | _from | INTEGER | ID of source from "Sources" table |
148
+ | Field | Type | Description |
149
+ |--------|--------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
150
+ | id | INTEGER | ID of state from "Data points" table |
151
+ | ts | BIGINT / INTEGER | Time in ms till epoch. Can be converted to time with "new Date(ts)" |
152
+ | val | REAL | Value |
153
+ | ack | BIT/BOOLEAN | Is acknowledged: 0 - not ack, 1 - ack |
154
+ | _from | INTEGER | ID of source from "Sources" table |
161
155
  | q | INTEGER | Quality as number. You can find description [here](https://github.com/ioBroker/ioBroker/blob/master/doc/SCHEMA.md#states) |
162
156
 
163
157
  *Note:* MS-SQL uses BIT, and others use BOOLEAN. SQLite uses for ts INTEGER and all others BIGINT.
164
158
 
165
159
  The user can define additional to type `number` the functionality of `counters`. For this purpose, the following table is created:
160
+
166
161
  | DB | Name in the query |
167
162
  |------------|-------------------------|
168
163
  | MS-SQL | iobroker.dbo.ts_counter |
@@ -172,19 +167,19 @@ The user can define additional to type `number` the functionality of `counters`.
172
167
 
173
168
  Structure:
174
169
 
175
- | Field | Type | Description |
176
- |--------|--------------------------------------------|-------------------------------------------------|
177
- | id | INTEGER | ID of state from "Data points" table |
178
- | ts | BIGINT / INTEGER | Time in ms till epoch. Can be converted to time with "new Date(ts)" |
179
- | val | REAL | Value |
170
+ | Field | Type | Description |
171
+ |--------|------------------|---------------------------------------------------------------------|
172
+ | id | INTEGER | ID of state from "Data points" table |
173
+ | ts | BIGINT / INTEGER | Time in ms till epoch. Can be converted to time with "new Date(ts)" |
174
+ | val | REAL | Value |
180
175
 
181
176
  This table stores the values when the counter was exchanged and the value does not increase, but failed to zero or lower value.
182
177
 
183
178
  ### Strings
184
179
  Values for states with type `string`.
185
180
 
186
- | DB | Name in query |
187
- |------------|-------------------------|
181
+ | DB | Name in query |
182
+ |------------|------------------------|
188
183
  | MS-SQL | iobroker.dbo.ts_string |
189
184
  | MySQL | iobroker.ts_string |
190
185
  | PostgreSQL | ts_string |
@@ -192,14 +187,14 @@ Values for states with type `string`.
192
187
 
193
188
  Structure:
194
189
 
195
- | Field | Type | Description |
196
- |--------|--------------------------------------------|-------------------------------------------------|
197
- | id | INTEGER | ID of state from "Data points" table |
198
- | ts | BIGINT | Time in ms till epoch. Can be converted to time with "new Date(ts)" |
199
- | val | TEXT | Value |
200
- | ack | BIT/BOOLEAN | Is acknowledged: 0 - not ack, 1 - ack |
201
- | _from | INTEGER | ID of source from "Sources" table |
202
- | q | INTEGER | Quality as number. You can find description [here](https://github.com/ioBroker/ioBroker/blob/master/doc/SCHEMA.md#states) |
190
+ | Field | Type | Description |
191
+ |--------|-----------------------|---------------------------------------------------------------------------------------------------------------------------|
192
+ | id | INTEGER | ID of state from "Data points" table |
193
+ | ts | BIGINT | Time in ms till epoch. Can be converted to time with "new Date(ts)" |
194
+ | val | TEXT | Value |
195
+ | ack | BIT/BOOLEAN | Is acknowledged: 0 - not ack, 1 - ack |
196
+ | _from | INTEGER | ID of source from "Sources" table |
197
+ | q | INTEGER | Quality as number. You can find description [here](https://github.com/ioBroker/ioBroker/blob/master/doc/SCHEMA.md#states) |
203
198
 
204
199
  *Note:* MS-SQL uses BIT, and others use BOOLEAN. SQLite uses for ts INTEGER and all others BIGINT.
205
200
 
@@ -215,22 +210,22 @@ Values for states with type `boolean`.
215
210
 
216
211
  Structure:
217
212
 
218
- | Field | Type | Description |
219
- |--------|--------------------------------------------|-------------------------------------------------|
220
- | id | INTEGER | ID of state from "Data points" table |
221
- | ts | BIGINT | Time in ms till epoch. Can be converted to time with "new Date(ts)" |
222
- | val | BIT/BOOLEAN | Value |
223
- | ack | BIT/BOOLEAN | Is acknowledged: 0 - not ack, 1 - ack |
224
- | _from | INTEGER | ID of source from "Sources" table |
225
- | q | INTEGER | Quality as number. You can find description [here](https://github.com/ioBroker/ioBroker/blob/master/doc/SCHEMA.md#states) |
213
+ | Field | Type | Description |
214
+ |--------|-------------|---------------------------------------------------------------------------------------------------------------------------|
215
+ | id | INTEGER | ID of state from "Data points" table |
216
+ | ts | BIGINT | Time in ms till epoch. Can be converted to time with "new Date(ts)" |
217
+ | val | BIT/BOOLEAN | Value |
218
+ | ack | BIT/BOOLEAN | Is acknowledged: 0 - not ack, 1 - ack |
219
+ | _from | INTEGER | ID of source from "Sources" table |
220
+ | q | INTEGER | Quality as number. You can find description [here](https://github.com/ioBroker/ioBroker/blob/master/doc/SCHEMA.md#states) |
226
221
 
227
222
  *Note:* MS-SQL uses BIT, and others use BOOLEAN. SQLite uses for ts INTEGER and all others BIGINT.
228
223
 
229
224
  ## Access values from Javascript adapter
230
- The sorted values can be accessed from Javascript adapter.
225
+ The sorted values can be accessed from JavaScript adapter.
231
226
 
232
227
  * Get 50 last stored events for all IDs
233
- ```
228
+ ```js
234
229
  sendTo('sql.0', 'getHistory', {
235
230
  id: '*',
236
231
  options: {
@@ -247,7 +242,7 @@ sendTo('sql.0', 'getHistory', {
247
242
  ```
248
243
 
249
244
  * Get stored values for "system.adapter.admin.0.memRss" in last hour
250
- ```
245
+ ```js
251
246
  var end = Date.now();
252
247
  sendTo('sql.0', 'getHistory', {
253
248
  id: 'system.adapter.admin.0.memRss',
@@ -265,8 +260,8 @@ sendTo('sql.0', 'getHistory', {
265
260
  ```
266
261
 
267
262
  Possible options:
268
- - **start** - (optional) time in ms - *Date.now()*'
269
- - **end** - (optional) time in ms - *Date.now()*', by default is (now + 5000 seconds)
263
+ - **start** - (optional) time in ms - *Date.now()*
264
+ - **end** - (optional) time in ms - *Date.now()*, by default is `(now + 5000 seconds)`
270
265
  - **step** - (optional) used in aggregate (max, min, average, total, ...) step in ms of intervals
271
266
  - **count** - number of values if aggregate is 'onchange' or number of intervals if other aggregate method. Count will be ignored if a step is set, else default is 500 if not set
272
267
  - **from** - if *from* field should be included in answer
@@ -277,8 +272,8 @@ Possible options:
277
272
  - **round** - round result to number of digits after decimal point
278
273
  - **ignoreNull** - if null values should be included (false), replaced by last not null value (true) or replaced with 0 (0)
279
274
  - **removeBorderValues** - By default, additional border values are returned to optimize charting. Set this option to true if this is not wanted (e.g. for script data processing)
280
- - **returnNewestEntries** - The returned data are always sorted by timestamp ascending. When using aggregate "none" and also providing "count" or "limit" this means that normally the oldest entries are returned (unless no start data is provided). Set this option to true to get the newest entries instead.
281
- - **aggregate** - aggregate method (Default: 'average'):
275
+ - **returnNewestEntries** - The returned data are always sorted by timestamp ascending. When using aggregate "none" and also providing "count" or "limit", this means that normally the oldest entries are returned (unless no start data is provided). Set this option to true to get the newest entries instead.
276
+ - **aggregate** - aggregate method (Default: `average`):
282
277
  - *minmax* - used special algorithm. Splice the whole time range in small intervals and find for every interval max, min, start and end values.
283
278
  - *max* - Splice the whole time range in small intervals and find for every interval max value and use it for this interval (nulls will be ignored).
284
279
  - *min* - Same as max, but take minimal value.
@@ -286,7 +281,7 @@ Possible options:
286
281
  - *total* - Same as max, but calculate total value.
287
282
  - *count* - Same as max, but calculate number of values (nulls will be calculated).
288
283
  - *percentile* - Calculate n-th percentile (n is given in `options.percentile` or defaults to 50 if not provided).
289
- - *quantile* - Calculate n quantile (n is given in options.quantile or defaults to 0.5 if not provided).
284
+ - *quantile* - Calculate n quantile (n is given in `options.quantile` or defaults to 0.5 if not provided).
290
285
  - *integral* - Calculate integral (additional parameters see below).
291
286
  - *none* - No aggregation at all. Only raw values in a given period.
292
287
  - **percentile** - (optional) when using aggregate method "percentile" defines the percentile level (0..100)(defaults to 50)
@@ -297,13 +292,13 @@ Possible options:
297
292
  - *none* - no/stepwise interpolation
298
293
 
299
294
  The first and last points will be calculated for aggregations, except aggregation `none`.
300
- If you manually request some aggregation, you should ignore first and last values, because they are calculated from values outside of a period.
295
+ If you manually request some aggregation, you should ignore first and last values because they are calculated from values outside of a period.
301
296
 
302
297
 
303
298
  ## Get counter
304
299
  User can ask the value of some counter (type=number, counter=true) for a specific period.
305
300
 
306
- ```
301
+ ```js
307
302
  var now = Date.now();
308
303
  // get consumption value for last 30 days
309
304
  sendTo('sql.0', 'getCounter', {
@@ -321,7 +316,7 @@ If the counter-device is replaced, it will be calculated too.
321
316
  ## Custom queries
322
317
  The user can execute custom queries on tables from javascript adapter:
323
318
 
324
- ```
319
+ ```js
325
320
  sendTo('sql.0', 'query', 'SELECT * FROM datapoints', function (result) {
326
321
  if (result.error) {
327
322
  console.error(result.error);
@@ -333,7 +328,7 @@ sendTo('sql.0', 'query', 'SELECT * FROM datapoints', function (result) {
333
328
  ```
334
329
 
335
330
  Or get entries for the last hour for ID=system.adapter.admin.0.memRss
336
- ```
331
+ ```js
337
332
  sendTo('sql.0', 'query', 'SELECT id FROM datapoints WHERE name="system.adapter.admin.0.memRss"', function (result) {
338
333
  if (result.error) {
339
334
  console.error(result.error);
@@ -355,47 +350,78 @@ Depending on the database, the database name or database name + schema must be i
355
350
 
356
351
  Example if your database is called 'iobroker':
357
352
 
358
- | DB | Name in query |
359
- |------------|------------------------------------------|
360
- | MS-SQL | SELECT * FROM iobroker.dbo.datapoints ...|
361
- | MySQL | SELECT * FROM iobroker.datapoints ... |
353
+ | DB | Name in query |
354
+ |---------|---------------------------------------------|
355
+ | MS-SQL | `SELECT * FROM iobroker.dbo.datapoints ...` |
356
+ | MySQL | `SELECT * FROM iobroker.datapoints ...` |
362
357
 
363
358
  ## storeState
364
- If you want to write other data into the InfluxDB/SQL you can use the build in system function **storeState**.
365
- This function can also be used to convert data from other History adapters like History or SQL.
366
359
 
367
- A successful response does not mean that the data is really written out to the disk. It just means that they were processed.
360
+ If you want to write other data into the SQL database, you can use the build
361
+ in system function **storeState**. This function can also be used to convert
362
+ data from other History adapters like InfluxDB or SQL.
363
+
364
+ A successful response does not mean that the data is really written out to the disk. It just means that they were processed!
368
365
 
369
366
  The given ids are not checked against the ioBroker database and do not need to be set up or enabled there. If own IDs are used without settings, then the "rules" parameter is not supported and will result in an error. The default "Maximal number of stored in RAM values" is used for such IDs.
370
367
 
371
368
  The Message can have one of the following three formats:
372
- * one ID and one state object
373
369
 
374
- ```
375
- sendTo('history.0', 'storeState', [
376
- id: 'mbus.0.counter.xxx',
377
- state: {ts: 1589458809352, val: 123, ack: false, from: 'system.adapter.whatever.0', ...}
378
- ], result => console.log('added'));
379
- ```
370
+ 1. one ID and one state object
371
+ 2. one ID and array of state objects
372
+ 3. array of multiple IDs with one state object each
380
373
 
381
- * one ID and array of state objects
374
+ ```javascript
375
+ // 1.
376
+ sendTo('sql.0', 'storeState', {
377
+ id: 'mbus.0.counter.xxx',
378
+ state: {
379
+ ts: 1589458809352,
380
+ val: 123,
381
+ ack: false,
382
+ from: 'system.adapter.whatever.0'
383
+ }
384
+ }, result => console.log('added'));
382
385
 
383
- ```
384
- sendTo('history.0', 'storeState', {
386
+ // 2.
387
+ sendTo('sql.0', 'storeState', {
385
388
  id: 'mbus.0.counter.xxx',
386
389
  state: [
387
- {ts: 1589458809352, val: 123, ack: false, from: 'system.adapter.whatever.0', ...},
388
- {ts: 1589458809353, val: 123, ack: false, from: 'system.adapter.whatever.0', ...}
390
+ {
391
+ ts: 1589458809352,
392
+ val: 123,
393
+ ack: false,
394
+ from: 'system.adapter.whatever.0'
395
+ },
396
+ {
397
+ ts: 1589458809353,
398
+ val: 123,
399
+ ack: false,
400
+ from: 'system.adapter.whatever.0'
401
+ }
389
402
  ]
390
403
  }, result => console.log('added'));
391
- ```
392
-
393
- * array of multiple IDs with one state object each
394
404
 
395
- ```
396
- sendTo('history.0', 'storeState', [
397
- {id: 'mbus.0.counter.xxx', state: {ts: 1589458809352, val: 123, ack: false, from: 'system.adapter.whatever.0', ...}},
398
- {id: 'mbus.0.counter.yyy', state: {ts: 1589458809353, val: 123, ack: false, from: 'system.adapter.whatever.0', ...}}
405
+ // 3.
406
+ sendTo('sql.0', 'storeState', [
407
+ {
408
+ id: 'mbus.0.counter.xxx',
409
+ state: {
410
+ ts: 1589458809352,
411
+ val: 123,
412
+ ack: false,
413
+ from: 'system.adapter.whatever.0'
414
+ }
415
+ },
416
+ {
417
+ id: 'mbus.0.counter.yyy',
418
+ state: {
419
+ ts: 1589458809353,
420
+ val: 123,
421
+ ack: false,
422
+ from: 'system.adapter.whatever.0'
423
+ }
424
+ }
399
425
  ], result => console.log('added'));
400
426
  ```
401
427
 
@@ -406,42 +432,42 @@ In case of errors, an array with all single error messages is returned and also
406
432
  ## delete state
407
433
  If you want to delete entry from the Database, you can use the build in system function **delete**:
408
434
 
409
- ```
435
+ ```javascript
410
436
  sendTo('sql.0', 'delete', [
411
- {id: 'mbus.0.counter.xxx', state: {ts: 1589458809352},
412
- {id: 'mbus.0.counter.yyy', state: {ts: 1589458809353}
437
+ {id: 'mbus.0.counter.xxx', state: {ts: 1589458809352}},
438
+ {id: 'mbus.0.counter.yyy', state: {ts: 1589458809353}},
413
439
  ], result => console.log('deleted'));
414
440
  ```
415
441
 
416
442
  To delete ALL history data for some data point, execute:
417
443
 
418
- ```
444
+ ```javascript
419
445
  sendTo('sql.0', 'deleteAll', [
420
- {id: 'mbus.0.counter.xxx'}
446
+ {id: 'mbus.0.counter.xxx'},
421
447
  {id: 'mbus.0.counter.yyy'}
422
448
  ], result => console.log('deleted'));
423
449
  ```
424
450
 
425
451
  To delete history data for some data point and for some range, execute:
426
452
 
427
- ```
453
+ ```javascript
428
454
  sendTo('sql.0', 'deleteRange', [
429
455
  {id: 'mbus.0.counter.xxx', start: '2019-01-01T00:00:00.000Z', end: '2019-12-31T23:59:59.999'},
430
456
  {id: 'mbus.0.counter.yyy', start: 1589458809352, end: 1589458809353}
431
457
  ], result => console.log('deleted'));
432
458
  ```
433
459
 
434
- Time could be ms since epoch or ans string, that could be converted by javascript Date object.
460
+ Time could be ms since epoch or ans string, that could be converted by JavaScript Date object.
435
461
 
436
462
  Values will be deleted including defined limits. `ts >= start AND ts <= end`
437
463
 
438
464
  ## change state
439
465
  If you want to change entry's value, quality or acknowledge flag in the database, you can use the build in system function **update**:
440
466
 
441
- ```
467
+ ```javascript
442
468
  sendTo('sql.0', 'update', [
443
- {id: 'mbus.0.counter.xxx', state: {ts: 1589458809352, val: 15, ack: true, q: 0},
444
- {id: 'mbus.0.counter.yyy', state: {ts: 1589458809353, val: 16, ack: true, q: 0}
469
+ {id: 'mbus.0.counter.xxx', state: {ts: 1589458809352, val: 15, ack: true, q: 0}},
470
+ {id: 'mbus.0.counter.yyy', state: {ts: 1589458809353, val: 16, ack: true, q: 0}},
445
471
  ], result => console.log('deleted'));
446
472
  ```
447
473
 
@@ -455,7 +481,7 @@ The adapter supports enabling and disabling of history logging via JavaScript an
455
481
  ### enable
456
482
  The message requires having the "id" of the data point. Additionally, optional "options" to define the data point specific settings:
457
483
 
458
- ```
484
+ ```javascript
459
485
  sendTo('sql.0', 'enableHistory', {
460
486
  id: 'system.adapter.sql.0.memRss',
461
487
  options: {
@@ -479,7 +505,7 @@ sendTo('sql.0', 'enableHistory', {
479
505
  ### disable
480
506
  The message requires having the "id" of the data point.
481
507
 
482
- ```
508
+ ```javascript
483
509
  sendTo('sql.0', 'disableHistory', {
484
510
  id: 'system.adapter.sql.0.memRss',
485
511
  }, function (result) {
@@ -495,10 +521,10 @@ sendTo('sql.0', 'disableHistory', {
495
521
  ### get List
496
522
  The message has no parameters.
497
523
 
498
- ```
524
+ ```javascript
499
525
  sendTo('sql.0', 'getEnabledDPs', {}, function (result) {
500
526
  //result is object like:
501
- {
527
+ console.log({
502
528
  "system.adapter.sql.0.memRss": {
503
529
  "changesOnly":true,
504
530
  "debounce":0,
@@ -508,9 +534,9 @@ sendTo('sql.0', 'getEnabledDPs', {}, function (result) {
508
534
  "enabled":true,
509
535
  "changesRelogInterval":0,
510
536
  "aliasId": ""
511
- }
512
- ...
513
- }
537
+ },
538
+ // ...
539
+ });
514
540
  });
515
541
  ```
516
542
 
@@ -520,6 +546,10 @@ sendTo('sql.0', 'getEnabledDPs', {}, function (result) {
520
546
  -->
521
547
 
522
548
  ## Changelog
549
+ ### 4.0.0 (2026-08-04)
550
+ * (@GermanBluefox) Migrated to TypeScript
551
+ * (@GermanBluefox) Node.js 22 is now needed at a minimum!
552
+
523
553
  ### 3.0.1 (2024-06-13)
524
554
  * (foxriver76) upgraded dependencies
525
555
 
@@ -537,329 +567,13 @@ sendTo('sql.0', 'getEnabledDPs', {}, function (result) {
537
567
  * (riversource/Apollon77) Optimize getHistory query by using "UNION ALL"
538
568
  * (Apollon77) Fix crash cases reported by Sentry
539
569
 
540
- ### 2.1.7 (2022-06-30)
541
- * (Apollon77) Fix crash cases reported by Sentry
542
-
543
- ### 2.1.6 (2022-06-27)
544
- * (Apollon77) Allowed removing a configuration value for "round" in config again
545
-
546
- ### 2.1.5 (2022-06-27)
547
- * (Apollon77) When no count is provided for aggregate "none" or "onchange" then the limit (default 2000) is used as count to define the number of data to return.
548
- * (Apollon77) Fix the initialization of types and IDs for some cases.
549
-
550
- ### 2.1.3 (2022-06-12)
551
- * (Apollon77) Make sure the debug log is active, according to the settings
552
-
553
- ### 2.1.2 (2022-06-08)
554
- * (Apollon77) Huge performance optimizations for GetHistory calls
555
-
556
- ### 2.1.1 (2022-05-30)
557
- * (Apollon77) Fix crash cases reported by Sentry
558
-
559
- ### 2.1.0 (2022-05-27)
560
- * (Apollon77) Fix crash cases reported by Sentry
561
- * (Apollon77) Fix several places where pooled connections might have not been returned to pool correctly and add logging for it
562
- * (Apollon77) Work around an issue in used Pooling library that potentially gave out too many connections
563
- * (Apollon77) Optimize retention check to better spread the first checks over time
564
- * (Apollon77) Default to not use datapoint buffering as in 1.x when set to 0
565
- * (Apollon77) Make sure disabling "Log changes only" also really does not log the changes anymore
566
- * (Apollon77) Allow storeState and GetHistory also to be called for "unknown ids"
567
- * (Apollon77) Adjust the fallback logic for type detection to use the type of the state value to log as last fallback
568
- * (Apollon77) Fix storing booleans on MSSQL
569
-
570
- ### 2.0.2 (2022-05-11)
571
- * (Apollon77) BREAKING: Configuration is only working in the new Admin 5 UI!
572
- * (Apollon77) Did bigger adjustments to the recording logic and added a lot of new Features. Please refer to Changelog and Forum post for details.
573
-
574
- ### 2.0.0 (2022-05-11)
575
- * (Apollon77) Breaking: Configuration is only working in the new Admin 5 UI!
576
- * (Apollon77) Breaking! Did bigger adjustments to the recording logic. Debounce is refined and blockTime is added to differentiate between the two checks
577
- * (Apollon77) Breaking! GetHistory requests now need to deliver the ts in milliseconds! Make sure to use up-to-date scripts and Charting UIs
578
- * (Apollon77) Add RAM buffering and mass inserts for logging
579
- * (Apollon77) New setting added to disable the "logging of additional values for charting optimization" - then only the expected data are logged
580
- * (Apollon77) Add flag returnNewestEntries for GetHistory to determine which records to return when more entries as "count" are existing for aggregate "none"
581
- * (Apollon77) Add support for addId getHistory flag for GetHistory
582
- * (Apollon77) Add new Debug flag to enable/disable debug logging on datapoint level (default is false) to optimize performance
583
- * (Apollon77) Add aggregate method "percentile" to calculate the percentile (0..100) of the values (requires options.percentile with the percentile level, defaults to 50 if not provided). Basically same as Quantile just different levels are used
584
- * (Apollon77) Add aggregate method "quantile" to calculate the quantile (0..1) of the values (requires options.quantile with the quantile level, defaults to 0.5 if not provided). Basically same as Percentile just different levels are used
585
- * (Apollon77) Add (experimental) method "integral" to calculate the integral of the values. Requires options.integralUnit with the time duration of the integral in seconds, defaults to 60s if not provided. Optionally a linear interpolation can be done by setting options.integralInterpolation to "linear"
586
- * (Apollon77) When request contains flag removeBorderValues: true, the result then cut the additional pre and post border values out of the results
587
- * (Apollon77) Enhance the former "Ignore below 0" feature and now allow specifying to ignore below or above specified values. The old setting is converted to the new one
588
- * (Apollon77) Upgrade MSSQL and MySQL drivers incl. Support for MySQL 8
589
- * (Apollon77) Make sure that min change delta allows numbers entered with comma (german notation) in all cases
590
- * (Apollon77) Add support to specify how to round numbers on query per datapoint
591
- * (Apollon77) Do not log passwords for Postgres connections
592
- * (Apollon77) Optimize SSL support for database connections including option to allow self signed certificates
593
- * (Apollon77) Allow to specify custom retention duration in days
594
- * (winnyschuster) Fix Insert statement for MSSQL ts_counter
595
- * (winnyschuster) type of ts in user queries corrected
596
-
597
- ### 1.16.2 (2022-02-16)
598
- * (bluefox) Marked interpolated data with `i=true`
599
-
600
- ### 1.16.1 (2021-12-19)
601
- * (Excodibur) Hide settings not relevant when "log changes only" is not used
602
- * (Apollon77) Allow all number values for debounce again
603
-
604
- ### 1.16.0 (2021-12-14)
605
- * (bluefox) Support only `js-controller` >= 3.3.x
606
- * (bluefox) Used system/custom view for collecting the objects
607
- * (bluefox) Implemented option to ignore zero- or/and below zero- values
608
-
609
- ### 1.15.7 (2021-04-28)
610
- * (bluefox) fixed the support of Admin5
611
-
612
- ### 1.15.6 (2021-04-19)
613
- * (bluefox) added support of Admin5
614
-
615
- ### 1.15.5 (2021-01-22)
616
- * (Apollon77) make sure message query is a string (Sentry)
617
-
618
- ### 1.15.4 (2021-01-17)
619
- * (Apollon77) Optimize stop handling
620
-
621
- ### 1.15.3 (2020-08-29)
622
- * (bluefox) Added the option "Do not create database". E.g. if DB was created and it does not required to do that, because the user does not have enough rights.
623
-
624
- ### 1.15.2 (2020-07-26)
625
- * (Apollon77) prevent wrong errors that realId is missing
626
-
627
- ### 1.15.1 (2020-07-20)
628
- * (Apollon77) implement a workaround for postgres problem
629
-
630
- ### 1.15.0 (2020-07-19)
631
- *BREAKING* This version only accepts Node.js 10.x+ (because sqlite3 was upgraded)
632
- * (Apollon77) Prevent crash case (Sentry IOBROKER-SQL-16, IOBROKER-SQL-15, IOBROKER-SQL-1K)
633
-
634
- ### 1.14.2 (2020-06-23)
635
- * (bluefox) Fixed error for data storage
636
-
637
- ### 1.14.1 (2020-06-17)
638
- * (bluefox) Corrected error for objects with mixed type
639
-
640
- ### 1.14.0 (2020-05-20)
641
- * (bluefox) added the range deletion and the delete all operations
642
-
643
- ### 1.13.1 (2020-05-20)
644
- * (bluefox) added changed and delete operations
645
-
646
- ### 1.12.6 (2020-05-08)
647
- * (bluefox) set default history if not yet set
648
-
649
- ### 1.12.5 (2020-05-05)
650
- * (Apollon77) Crash prevented for invalid objects (Sentry IOBROKER-SQL-X)
651
-
652
- ### 1.12.4 (2020-05-04)
653
- * (Apollon77) Potential crash fixed when disabling data points too fast (Sentry IOBROKER-SQL-W)
654
- * (Apollon77) Always set "encrypt" flag, even if false because else might en in default true (see https://github.com/tediousjs/tedious/issues/931)
655
-
656
- ### 1.12.3 (2020-04-30)
657
- * (Apollon77) Try to create indexes on MSSQL to speed up things. Infos are shown if not possible to be able for the user to do it themself. Timeout is 15s
658
-
659
- ### 1.12.2 (2020-04-30)
660
- * (Apollon77) MSSQL works again
661
-
662
- ### 1.12.1 (2020-04-26)
663
- * (Apollon77) Fix potential crash (Sentry)
664
-
665
- ### 1.12.0 (2020-04-23)
666
- * (Apollon77) Implement max Connections setting and respect it, now allows to control how many concurrent connections to database are used (default 100) and others wait up to 10s for a free connection before failing)
667
- * (Apollon77) Change dependencies to admin to a global dependency
668
- * (Apollon77) Update connection status also in between
669
- * (Apollon77) fix some potential crash cases (Sentry reported)
670
- * (Omega236) Add id to error message for queries
671
- * (Apollon77) update pg to stay compatible with nodejs 14
672
- * (Apollon77) Start clearly ending timeouts on unload ... still some cases left!
673
-
674
- ### 1.11.1 (2020-04-19)
675
- * __Requires js-controller >= 2.0.0__
676
- * (Apollon77) removed usage of adapter.objects
677
- * (Apollon77) check if objects have changed and ignore unchanged
678
- * (Apollon77) Add Sentry for Error Reporting with js-controller 3.0
679
- * (Apollon77) Make sure value undefined is ignored
680
-
681
- ### 1.10.1 (2020-04-12)
682
- * (bluefox) Converted to ES6
683
- * (bluefox) The counter functionality was implemented.
684
-
685
- ### 1.9.5 (2019-05-15)
686
- * (Apollon77) Add support for nodejs 12
687
-
688
- ### 1.9.4 (2019-02-24)
689
- * (Apollon77) Fix several smaller issues and topics
690
- * (Apollon77) Optimize Texts (for Admin v3 UI)
691
-
692
- ### 1.9.0 (2018-06-19)
693
- * (Apollon77) Add option to log datapoints as other ID (alias) to easier migrate devices and such
694
-
695
- ### 1.8.0 (2018-04-29)
696
- * (Apollon77) Update sqlite3, nodejs 10 compatible
697
- * (BuZZy1337) Admin fix
698
-
699
- ### 1.7.4 (2018-04-15)
700
- * (Apollon77) Fix getHistory
701
-
702
- ### 1.7.3 (2018-03-28)
703
- * (Apollon77) Respect 'keep forever' setting for retention from data point configuration
704
-
705
- ### 1.7.2 (2018-03-24)
706
- * (Apollon77) Disable to write NULLs for SQLite
707
-
708
- ### 1.7.1 (2018-02-10)
709
- * (Apollon77) Make option to write NULL values on start/stop boundaries configurable
710
-
711
- ### 1.6.9 (2018-02-07)
712
- * (bondrogeen) Admin3 Fixes
713
- * (Apollon77) optimize relog feature and other things
714
-
715
- ### 1.6.7 (2018-01-31)
716
- * (Bluefox) Admin3 Fixes
717
- * (Apollon77) Relog and null log fixes
718
-
719
- ### 1.6.2 (2018-01-30)
720
- * (Apollon77) Admin3 Fixes
721
-
722
- ### 1.6.0 (2018-01-14)
723
- * (bluefox) Ready for Admin3
724
-
725
- ### 1.5.8 (2017-10-05)
726
- * (Apollon77) fix relog value feature
727
-
728
- ### 1.5.7 (2017-08-10)
729
- * (bluefox) add "save last value" option
730
-
731
- ### 1.5.6 (2017-08-02)
732
- * (Apollon77) fix behaviour of log interval to always log the current value
733
-
734
- ### 1.5.4 (2017-06-12)
735
- * (Apollon77) fix dependency to other library
736
-
737
- ### 1.5.3 (2017-04-07)
738
- * (Apollon77) fix in datatype conversions
739
-
740
- ### 1.5.0 (2017-03-02)
741
- * (Apollon77) Add option to define storage datatype per datapoint inclusing converting the value if needed
742
-
743
- ### 1.4.6 (2017-02-25)
744
- * (Apollon77) Fix typo with PostgrSQL
745
-
746
- ### 1.4.5 (2017-02-18)
747
- * (Apollon77) Small fix again for older configurations
748
- * (Apollon77) fix for DBConverter Analyze function
749
-
750
- ### 1.4.3 (2017-02-11)
751
- * (Apollon77) Small fix for older configurations
752
-
753
- ### 1.4.2 (2017-01-16)
754
- * (bluefox) Fix handling of float values in Adapter config and Datapoint config.
755
-
756
- ### 1.4.1
757
- * (Apollon77) Rollback to sql-client 0.7 to get rid of the mmagic dependecy that brings problems on older systems
758
-
759
- ### 1.4.0 (2016-12-02)
760
- * (Apollon77) Add messages enableHistory/disableHistory
761
- * (Apollon77) add support to log changes only if value differs a minimum value for numbers
762
-
763
- ### 1.3.4 (2016-11)
764
- * (Apollon77) Allow database names with '-' for MySQL
765
-
766
- ### 1.3.3 (2016-11)
767
- * (Apollon77) Update dependecies
768
-
769
- ### 1.3.2 (2016-11-21)
770
- * (bluefox) Fix insert of string with '
771
-
772
- ### 1.3.0 (2016-10-29)
773
- * (Apollon77) add option to re-log unchanged values to make it easier for visualization
774
-
775
- ### 1.2.1 (2016-08-30)
776
- * (bluefox) Fix selector for SQL objects
777
-
778
- ### 1.2.0 (2016-08-30)
779
- * (bluefox) сompatible only with new admin
780
-
781
- ### 1.0.10 (2016-08-27)
782
- * (bluefox) change name of object from "history" to "custom"
783
-
784
- ### 1.0.10 (2016-07-31)
785
- * (bluefox) fix multi requests if sqlite
786
-
787
- ### 1.0.9 (2016-06-14)
788
- * (bluefox) allow settings for parallel requests
789
-
790
- ### 1.0.7 (2016-05-31)
791
- * (bluefox) draw line to the end if ignore null
792
-
793
- ### 1.0.6 (2016-05-30)
794
- * (bluefox) allow setup DB name for mysql and mssql
795
-
796
- ### 1.0.5 (2016-05-29)
797
- * (bluefox) switch max and min with each other
798
-
799
- ### 1.0.4 (2016-05-29)
800
- * (bluefox) check retention of data if set "never"
801
-
802
- ### 1.0.3 (2016-05-28)
803
- * (bluefox) try to calculate old timestamps
804
-
805
- ### 1.0.2 (2016-05-24)
806
- * (bluefox) fix error with io-package
807
-
808
- ### 1.0.1 (2016-05-24)
809
- * (bluefox) fix error with SQLite
810
-
811
- ### 1.0.0 (2016-05-20)
812
- * (bluefox) change default aggregation name
813
-
814
- ### 0.3.3 (2016-05-18)
815
- * (bluefox) fix postgres
816
-
817
- ### 0.3.2 (2016-05-13)
818
- * (bluefox) queue select if IDs and FROMs queries for sqlite
819
-
820
- ### 0.3.1 (2016-05-12)
821
- * (bluefox) queue delete queries too for sqlite
822
-
823
- ### 0.3.0 (2016-05-08)
824
- * (bluefox) support of custom queries
825
- * (bluefox) only one request simultaneously for sqlite
826
- * (bluefox) add tests (primitive and only sql)
827
-
828
- ### 0.2.0 (2016-04-30)
829
- * (bluefox) support of milliseconds
830
- * (bluefox) fix sqlite
831
-
832
- ### 0.1.4 (2016-04-25)
833
- * (bluefox) fix deletion of old entries
834
-
835
- ### 0.1.3 (2016-03-08)
836
- * (bluefox) do not print errors twice
837
-
838
- ### 0.1.2 (2015-12-22)
839
- * (bluefox) fix MS-SQL port settings
840
-
841
- ### 0.1.1 (2015-12-19)
842
- * (bluefox) fix error with double entries
843
-
844
- ### 0.1.0 (2015-12-14)
845
- * (bluefox) support of strings
846
-
847
- ### 0.0.3 (2015-12-06)
848
- * (smiling_Jack) Add demo Data ( todo: faster insert to db )
849
- * (smiling_Jack) change aggregation (now same as history Adapter)
850
- * (bluefox) bug fixing
851
-
852
- ### 0.0.2 (2015-12-06)
853
- * (bluefox) allow only 1 client for SQLite
854
-
855
- ### 0.0.1 (2015-11-19)
856
- * (bluefox) initial commit
570
+ [Older changelogs can be found there](CHANGELOG_OLD.md)
857
571
 
858
572
  ## License
859
573
 
860
574
  The MIT License (MIT)
861
575
 
862
- Copyright (c) 2015-2024 bluefox <dogafox@gmail.com>, Apollon77
576
+ Copyright (c) 2015-2026 bluefox <dogafox@gmail.com>, Apollon77
863
577
 
864
578
  Permission is hereby granted, free of charge, to any person obtaining a copy
865
579
  of this software and associated documentation files (the "Software"), to deal