@transitive-sdk/clickhouse 0.3.5 → 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 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 ensureMqttHistoryTable
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: [
@@ -54,7 +54,7 @@ class ClickHouse {
54
54
 
55
55
  const {hostname, port} = URL.parse(_url);
56
56
  const interval = 200;
57
- await waitPort({ host: hostname, port: port || 80, interval }, 10000);
57
+ await waitPort({ host: hostname, port: Number(port || 80), interval }, 10000);
58
58
  await new Promise(done => setTimeout(done, 200));
59
59
 
60
60
  // console.debug(`Creating ClickHouse client for URL: ${_url}, DB: ${_dbName}, User: ${_user}`);
@@ -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} (${fullSchema.join(', ')}) ${settings.join(' ')}`;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transitive-sdk/clickhouse",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "A tiny ClickHouse utility class for use in the Transitive framework.",
5
5
  "homepage": "https://transitiverobotics.com",
6
6
  "repository": {
@@ -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({