-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchdb.js
58 lines (53 loc) · 1.7 KB
/
chdb.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { ClickHouse } from 'clickhouse'
export default async () => {
const ch = new ClickHouse({
url: '127.0.0.1',
port: '8123',
format: 'json',
config: {
enable_http_compression: 1,
database: 'default'
}
})
const ch_migration = `
create table if not exists asset (
id String,
name Nullable(String),
description Nullable(String),
site Nullable(String),
class_id Nullable(UInt32),
location_id Nullable(UInt32),
category_id Nullable(UInt32),
manufacturer_id Nullable(UInt32),
assetstatus_id Nullable(UInt32),
owner_id Nullable(UInt32),
current_condition_score Nullable(UInt8),
location_x Nullable(Float32),
location_y Nullable(Float32),
quadint Nullable(UInt64),
index asset_class_id_idx (class_id)
type bloom_filter granularity 3,
index asset_location_id_idx (location_id)
type bloom_filter granularity 3,
index asset_category_id_idx (category_id)
type bloom_filter granularity 3,
index asset_manufacturer_id_idx (manufacturer_id)
type bloom_filter granularity 3,
index asset_assetstatus_id_idx (assetstatus_id)
type bloom_filter granularity 3,
index asset_owner_id_idx (owner_id)
type bloom_filter granularity 3,
index asset_quadint_idx (quadint)
type minmax,
index asset_location_x_idx (location_x)
type minmax,
index asset_location_y_idx (location_y)
type minmax
)
engine = ReplacingMergeTree
primary key (id);
`
const queries = ch_migration.split(';').map(s => s.trim()).filter(s => s != '')
for (const q of queries) await ch.query(q).toPromise()
return ch
}