-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsyncTable.ts
58 lines (52 loc) · 1.23 KB
/
syncTable.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
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 { ClickhouseOrm, DATA_TYPE, ModelSyncTableConfig } from "../lib/index";
import { clientConfig } from "../mock";
/**
* defined Model
*/
const commanParams = {
tableName: "testsync",
options: `ENGINE = MergeTree
PARTITION BY toYYYYMM(time)
ORDER BY time`,
autoCreate: true,
autoSync: true,
};
const newModelSyncTableConfig = {
...commanParams,
schema: {
time: { type: DATA_TYPE.DateTime, default: Date },
will_typeChanged: { type: DATA_TYPE.Int16 },
will_deleted: { type: DATA_TYPE.String },
},
};
const updateModelSyncTableConfig = {
...commanParams,
schema: {
time: { type: DATA_TYPE.DateTime, default: Date },
will_typeChanged: { type: DATA_TYPE.Int32 },
add_column: { type: DATA_TYPE.String },
},
};
/**
* new instance
*/
const db = {
name: "orm_test",
};
const chOrm = ClickhouseOrm({
client: clientConfig,
db,
debug: true,
});
const doDemo = async () => {
// create database 'orm_test'
await chOrm.createDatabase();
await chOrm.client
.query(`DROP TABLE IF EXISTS ${db.name}.${commanParams.tableName}`)
.toPromise();
// create new table
await chOrm.model(newModelSyncTableConfig);
// update table
await chOrm.model(updateModelSyncTableConfig);
};
doDemo();