@transitive-sdk/clickhouse 0.3.6 → 0.3.7
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/index.js +5 -3
- package/package.json +1 -1
- package/test/clickhouse.test.js +13 -0
package/index.js
CHANGED
|
@@ -8,7 +8,7 @@ const { topicToPath, topicMatch } = require('@transitive-sdk/datacache');
|
|
|
8
8
|
// Default TTL in days for mqtt_history table
|
|
9
9
|
const DEFAULT_TTL_DAYS = 30;
|
|
10
10
|
|
|
11
|
-
// Shared multi-tenant schema components used by createTable and
|
|
11
|
+
// Shared multi-tenant schema components used by createTable and enableHistory
|
|
12
12
|
const MULTI_TENANT_SCHEMA = {
|
|
13
13
|
// Column definitions for OrgId and DeviceId
|
|
14
14
|
columns: [
|
|
@@ -109,13 +109,15 @@ class ClickHouse {
|
|
|
109
109
|
* @param {Array<string>} columns - array of column definitions and indexes, e.g. ['Timestamp DateTime CODEC(ZSTD(1))', 'Value Float32 CODEC(ZSTD(1))']
|
|
110
110
|
* @param {Array<string>} settings - array of table settings, e.g. ['ENGINE = MergeTree()', 'ORDER BY (Timestamp)']
|
|
111
111
|
*/
|
|
112
|
-
async createTable(tableName, columns, settings = []) {
|
|
112
|
+
async createTable(tableName, columns, settings = ['ORDER BY (OrgId, DeviceId)']) {
|
|
113
113
|
const fullSchema = [
|
|
114
114
|
...columns,
|
|
115
115
|
...MULTI_TENANT_SCHEMA.columns,
|
|
116
116
|
...MULTI_TENANT_SCHEMA.indexes
|
|
117
117
|
];
|
|
118
|
-
const query = `CREATE TABLE IF NOT EXISTS ${tableName}
|
|
118
|
+
const query = `CREATE TABLE IF NOT EXISTS ${tableName}
|
|
119
|
+
(${fullSchema.join(', ')})
|
|
120
|
+
${settings.join(' ')}`;
|
|
119
121
|
|
|
120
122
|
try {
|
|
121
123
|
return await this.client.exec({
|
package/package.json
CHANGED
package/test/clickhouse.test.js
CHANGED
|
@@ -67,6 +67,19 @@ describe('ClickHouse', function() {
|
|
|
67
67
|
await clickhouse.registerMqttTopicForStorage(STANDARD_TOPIC_PATTERN);
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
+
describe('basics', () => {
|
|
71
|
+
it('creates tables without crashing', async () => {
|
|
72
|
+
const result = await clickhouse.createTable('test_tmp',
|
|
73
|
+
['text String']);
|
|
74
|
+
|
|
75
|
+
// clean up
|
|
76
|
+
await clickhouse.client.command({
|
|
77
|
+
query: `DROP TABLE IF EXISTS test_tmp`,
|
|
78
|
+
clickhouse_settings: { wait_end_of_query: 1 }
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
70
83
|
describe('enableHistory', () => {
|
|
71
84
|
it('should create the mqtt_history table', async () => {
|
|
72
85
|
const result = await clickhouse.client.query({
|