-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathcreate_table_cloud.ts
34 lines (32 loc) · 1.07 KB
/
create_table_cloud.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { createClient } from '@clickhouse/client' // or '@clickhouse/client-web'
void (async () => {
const client = createClient({
url: getFromEnv('CLICKHOUSE_URL'),
password: getFromEnv('CLICKHOUSE_PASSWORD'),
})
// Note that ENGINE and ON CLUSTER clauses can be omitted entirely here.
// ClickHouse cloud will automatically use ReplicatedMergeTree
// with appropriate settings in this case.
await client.command({
query: `
CREATE TABLE IF NOT EXISTS clickhouse_js_example_cloud_table
(id UInt64, name String)
ORDER BY (id)
`,
// Recommended for cluster usage to avoid situations
// where a query processing error occurred after the response code
// and HTTP headers were sent to the client.
// See https://clickhouse.com/docs/en/interfaces/http/#response-buffering
clickhouse_settings: {
wait_end_of_query: 1,
},
})
await client.close()
})()
function getFromEnv(key: string) {
if (process.env[key]) {
return process.env[key]
}
console.error(`${key} environment variable should be set`)
process.exit(1)
}