namirasoft-node-clickhouse 1.4.0
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/dist/BaseClickhouseDatabase.d.ts +12 -0
- package/dist/BaseClickhouseDatabase.js +45 -0
- package/dist/BaseClickhouseDatabase.js.map +1 -0
- package/dist/BaseClickhouseModelSchema.d.ts +4 -0
- package/dist/BaseClickhouseModelSchema.js +3 -0
- package/dist/BaseClickhouseModelSchema.js.map +1 -0
- package/dist/BaseClickhouseModelSchemaColumnOptions.d.ts +5 -0
- package/dist/BaseClickhouseModelSchemaColumnOptions.js +4 -0
- package/dist/BaseClickhouseModelSchemaColumnOptions.js.map +1 -0
- package/dist/BaseClickhouseTable.d.ts +19 -0
- package/dist/BaseClickhouseTable.js +83 -0
- package/dist/BaseClickhouseTable.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/logo.png +0 -0
- package/package.json +25 -0
- package/src/BaseClickhouseDatabase.ts +38 -0
- package/src/BaseClickhouseModelSchema.ts +5 -0
- package/src/BaseClickhouseModelSchemaColumnOptions.ts +7 -0
- package/src/BaseClickhouseTable.ts +159 -0
- package/src/index.ts +4 -0
- package/tsconfig.json +42 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseDatabase } from "namirasoft-node";
|
|
2
|
+
import { NodeClickHouseClient } from '@clickhouse/client/dist/client';
|
|
3
|
+
export declare abstract class BaseClickhouseDatabase extends BaseDatabase {
|
|
4
|
+
client: NodeClickHouseClient;
|
|
5
|
+
private name;
|
|
6
|
+
constructor(isHTTPS: boolean, host: string, port: number, name: string, user: string, pass: string, params?: {
|
|
7
|
+
[name: string]: string;
|
|
8
|
+
});
|
|
9
|
+
connect(): Promise<void>;
|
|
10
|
+
sync(force: boolean): Promise<void>;
|
|
11
|
+
getSortOptions(): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.BaseClickhouseDatabase = void 0;
|
|
13
|
+
const namirasoft_log_1 = require("namirasoft-log");
|
|
14
|
+
const namirasoft_node_1 = require("namirasoft-node");
|
|
15
|
+
const client_1 = require("@clickhouse/client");
|
|
16
|
+
class BaseClickhouseDatabase extends namirasoft_node_1.BaseDatabase {
|
|
17
|
+
constructor(isHTTPS, host, port, name, user, pass, params) {
|
|
18
|
+
super();
|
|
19
|
+
let parameters = Object.keys(params !== null && params !== void 0 ? params : {}).map(key => `${key}=>${params === null || params === void 0 ? void 0 : params[key]}`).join("&");
|
|
20
|
+
this.client = (0, client_1.createClient)({
|
|
21
|
+
url: `http${isHTTPS ? "s" : ""}://${user}:${pass}@${host}:${port}/${name}${parameters.length > 0 ? ("?" + parameters) : ""}`,
|
|
22
|
+
});
|
|
23
|
+
this.name = name;
|
|
24
|
+
}
|
|
25
|
+
connect() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
var _a;
|
|
28
|
+
if (!process.env.NAMIRASOFT_MUTE) {
|
|
29
|
+
yield this.client.ping();
|
|
30
|
+
(_a = namirasoft_log_1.Logger.main) === null || _a === void 0 ? void 0 : _a.success(`Database Clickhouse was connected to ${this.name}`);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
sync(force) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
if (!process.env.NAMIRASOFT_MUTE)
|
|
37
|
+
if (force) {
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
getSortOptions() {
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.BaseClickhouseDatabase = BaseClickhouseDatabase;
|
|
45
|
+
//# sourceMappingURL=BaseClickhouseDatabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseClickhouseDatabase.js","sourceRoot":"","sources":["../src/BaseClickhouseDatabase.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAwC;AACxC,qDAA+C;AAC/C,+CAAkD;AAGlD,MAAsB,sBAAuB,SAAQ,8BAAY;IAI7D,YAAY,OAAgB,EAAE,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,MAAmC;QAEnI,KAAK,EAAE,CAAC;QACR,IAAI,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,KAAK,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAG,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC5F,IAAI,CAAC,MAAM,GAAG,IAAA,qBAAY,EAAC;YACvB,GAAG,EAAE,OAAO,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;SAC/H,CAAC,CAAA;QACF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IACc,OAAO;;;YAElB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAChC,CAAC;gBACG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;gBACzB,MAAA,uBAAM,CAAC,IAAI,0CAAE,OAAO,CAAC,wCAAwC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YAC9E,CAAC;QACL,CAAC;KAAA;IACc,IAAI,CAAC,KAAc;;YAE9B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe;gBAC5B,IAAI,KAAK,EACT,CAAC;gBAED,CAAC;QACT,CAAC;KAAA;IACQ,cAAc;IAEvB,CAAC;CACJ;AAhCD,wDAgCC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseClickhouseModelSchema.js","sourceRoot":"","sources":["../src/BaseClickhouseModelSchema.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseClickhouseModelSchemaColumnOptions.js","sourceRoot":"","sources":["../src/BaseClickhouseModelSchemaColumnOptions.ts"],"names":[],"mappings":";;AAMC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseClickhouseDatabase } from "./BaseClickhouseDatabase";
|
|
2
|
+
import { BaseTable } from "namirasoft-node";
|
|
3
|
+
import { BaseMetaColumn } from "namirasoft-core";
|
|
4
|
+
import { BaseTypeSchema } from "namirasoft-schema";
|
|
5
|
+
import { BaseClickhouseModelSchemaColumnOptions } from "./BaseClickhouseModelSchemaColumnOptions";
|
|
6
|
+
import { BaseClickhouseModelSchema } from "./BaseClickhouseModelSchema";
|
|
7
|
+
export declare abstract class BaseClickhouseTable<D extends BaseClickhouseDatabase> extends BaseTable<D, BaseClickhouseModelSchemaColumnOptions> {
|
|
8
|
+
name: string;
|
|
9
|
+
schema: BaseClickhouseModelSchema;
|
|
10
|
+
constructor(database: D, name: string);
|
|
11
|
+
getName(): string;
|
|
12
|
+
getSecureColumns(): string[];
|
|
13
|
+
getReadOnlyColumns(): string[];
|
|
14
|
+
private getModelAllSchemas;
|
|
15
|
+
getColumnOption(name: string): BaseClickhouseModelSchemaColumnOptions;
|
|
16
|
+
forEachColumn(handler: (name: string, column: BaseClickhouseModelSchemaColumnOptions) => void): void;
|
|
17
|
+
getColumn(name: string): BaseMetaColumn;
|
|
18
|
+
protected getTypeSchema(option: BaseClickhouseModelSchemaColumnOptions): BaseTypeSchema;
|
|
19
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseClickhouseTable = void 0;
|
|
4
|
+
const namirasoft_node_1 = require("namirasoft-node");
|
|
5
|
+
const namirasoft_core_1 = require("namirasoft-core");
|
|
6
|
+
const namirasoft_schema_1 = require("namirasoft-schema");
|
|
7
|
+
class BaseClickhouseTable extends namirasoft_node_1.BaseTable {
|
|
8
|
+
constructor(database, name) {
|
|
9
|
+
super(database);
|
|
10
|
+
this.name = name;
|
|
11
|
+
}
|
|
12
|
+
getName() {
|
|
13
|
+
return this.name;
|
|
14
|
+
}
|
|
15
|
+
getSecureColumns() {
|
|
16
|
+
let columns = super.getSecureColumns();
|
|
17
|
+
return ["_id", "__v", "deleted_at", "deletedAt", ...columns];
|
|
18
|
+
}
|
|
19
|
+
getReadOnlyColumns() {
|
|
20
|
+
let columns = super.getReadOnlyColumns();
|
|
21
|
+
return ["id", "created_at", "updated_at", "createdAt", "updatedAt", ...columns];
|
|
22
|
+
}
|
|
23
|
+
getModelAllSchemas() {
|
|
24
|
+
let otherAttributes = {
|
|
25
|
+
_id: { type: String, required: true },
|
|
26
|
+
__v: { type: String, required: true },
|
|
27
|
+
};
|
|
28
|
+
return Object.assign(Object.assign({}, this.schema), otherAttributes);
|
|
29
|
+
}
|
|
30
|
+
getColumnOption(name) {
|
|
31
|
+
let schema = this.getModelAllSchemas();
|
|
32
|
+
return schema[name];
|
|
33
|
+
}
|
|
34
|
+
forEachColumn(handler) {
|
|
35
|
+
let schema = this.getModelAllSchemas();
|
|
36
|
+
let keys = Object.keys(schema);
|
|
37
|
+
for (let i = 0; i < keys.length; i++)
|
|
38
|
+
handler(keys[i], this.getColumnOption(keys[i]));
|
|
39
|
+
}
|
|
40
|
+
getColumn(name) {
|
|
41
|
+
let option = this.getColumnOption(name);
|
|
42
|
+
let table_name = this.getName();
|
|
43
|
+
let table = new namirasoft_core_1.BaseMetaTable(null, table_name, table_name);
|
|
44
|
+
let type = option.type;
|
|
45
|
+
try {
|
|
46
|
+
if (typeof (type) == "function")
|
|
47
|
+
type = type.name;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
}
|
|
51
|
+
let column = new namirasoft_core_1.BaseMetaColumn(table, name, name, type, option.required);
|
|
52
|
+
return column;
|
|
53
|
+
}
|
|
54
|
+
getTypeSchema(option) {
|
|
55
|
+
var _a;
|
|
56
|
+
let required = option.required;
|
|
57
|
+
if (option.type === Boolean)
|
|
58
|
+
return new namirasoft_schema_1.BoolSchema(required);
|
|
59
|
+
else if (option.type === Number)
|
|
60
|
+
return new namirasoft_schema_1.DoubleSchema(required, null);
|
|
61
|
+
else if (option.type === String)
|
|
62
|
+
return new namirasoft_schema_1.StringSchema(required, null, null);
|
|
63
|
+
else if (option.type === Date)
|
|
64
|
+
return new namirasoft_schema_1.DateTimeSchema(required);
|
|
65
|
+
else if (option.type === Object) {
|
|
66
|
+
let tags_type = (_a = option.tags) === null || _a === void 0 ? void 0 : _a.type;
|
|
67
|
+
if (tags_type) {
|
|
68
|
+
if (tags_type === "BaseTypeSchema")
|
|
69
|
+
return new namirasoft_schema_1.TypeSchema(required);
|
|
70
|
+
if (tags_type === "BaseVariableSchema")
|
|
71
|
+
return new namirasoft_schema_1.VariableSchema(required);
|
|
72
|
+
if (tags_type === "BaseTypeSchema[]")
|
|
73
|
+
return new namirasoft_schema_1.ArraySchema(required, [new namirasoft_schema_1.TypeSchema(required)]);
|
|
74
|
+
if (tags_type === "BaseVariableSchema[]")
|
|
75
|
+
return new namirasoft_schema_1.ArraySchema(required, [new namirasoft_schema_1.VariableSchema(required)]);
|
|
76
|
+
}
|
|
77
|
+
return new namirasoft_schema_1.AnySchema(required);
|
|
78
|
+
}
|
|
79
|
+
throw new Error("Unsupported datatype for schema: " + option);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.BaseClickhouseTable = BaseClickhouseTable;
|
|
83
|
+
//# sourceMappingURL=BaseClickhouseTable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseClickhouseTable.js","sourceRoot":"","sources":["../src/BaseClickhouseTable.ts"],"names":[],"mappings":";;;AACA,qDAA4C;AAC5C,qDAAgE;AAChE,yDAA+J;AAI/J,MAAsB,mBAAsD,SAAQ,2BAAoD;IAIpI,YAAY,QAAW,EAAE,IAAY;QAEjC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAChB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IACQ,OAAO;QAEZ,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IACQ,gBAAgB;QAErB,IAAI,OAAO,GAAG,KAAK,CAAC,gBAAgB,EAAE,CAAC;QACvC,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,CAAA;IAChE,CAAC;IACQ,kBAAkB;QAEvB,IAAI,OAAO,GAAG,KAAK,CAAC,kBAAkB,EAAE,CAAC;QACzC,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,CAAC;IACpF,CAAC;IACO,kBAAkB;QAEtB,IAAI,eAAe,GAA8B;YAC7C,GAAG,EAAE,EAAE,IAAI,EAAE,MAA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,mCAAmC,GAAG,MAAM,CAAC,CAAC;IAClE,CAAC;CA8BJ;AAvJD,kDAuJC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./BaseClickhouseDatabase"), exports);
|
|
18
|
+
__exportStar(require("./BaseClickhouseModelSchema"), exports);
|
|
19
|
+
__exportStar(require("./BaseClickhouseModelSchemaColumnOptions"), exports);
|
|
20
|
+
__exportStar(require("./BaseClickhouseTable"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,8DAA4C;AAC5C,2EAAyD;AACzD,wDAAsC"}
|
package/logo.png
ADDED
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "namirasoft-node-clickhouse",
|
|
3
|
+
"title": "Namirasoft Node Clickhouse NPM Package",
|
|
4
|
+
"description": "Namira Software Corporation Node Clickhouse NPM Package",
|
|
5
|
+
"icon": "logo.png",
|
|
6
|
+
"logo": "https://static.namirasoft.com/image/namirasoft/site/logo/base.png",
|
|
7
|
+
"language": "ts",
|
|
8
|
+
"framework": "npm",
|
|
9
|
+
"application": "package",
|
|
10
|
+
"private": false,
|
|
11
|
+
"version": "1.4.0",
|
|
12
|
+
"author": "Amir Abolhasani",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": ""
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@clickhouse/client": "^1.11.0",
|
|
21
|
+
"@types/node": "^22.14.1",
|
|
22
|
+
"namirasoft-core": "^1.4.66",
|
|
23
|
+
"namirasoft-node": "^1.4.94"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Logger } from "namirasoft-log";
|
|
2
|
+
import { BaseDatabase } from "namirasoft-node";
|
|
3
|
+
import { createClient } from '@clickhouse/client';
|
|
4
|
+
import { NodeClickHouseClient } from '@clickhouse/client/dist/client';
|
|
5
|
+
|
|
6
|
+
export abstract class BaseClickhouseDatabase extends BaseDatabase
|
|
7
|
+
{
|
|
8
|
+
public client: NodeClickHouseClient;
|
|
9
|
+
private name: string;
|
|
10
|
+
constructor(isHTTPS: boolean, host: string, port: number, name: string, user: string, pass: string, params?: { [name: string]: string })
|
|
11
|
+
{
|
|
12
|
+
super();
|
|
13
|
+
let parameters = Object.keys(params ?? {}).map(key => `${key}=>${params?.[key]}`).join("&");
|
|
14
|
+
this.client = createClient({
|
|
15
|
+
url: `http${isHTTPS ? "s" : ""}://${user}:${pass}@${host}:${port}/${name}${parameters.length > 0 ? ("?" + parameters) : ""}`,
|
|
16
|
+
})
|
|
17
|
+
this.name = name;
|
|
18
|
+
}
|
|
19
|
+
override async connect()
|
|
20
|
+
{
|
|
21
|
+
if (!process.env.NAMIRASOFT_MUTE)
|
|
22
|
+
{
|
|
23
|
+
await this.client.ping();
|
|
24
|
+
Logger.main?.success(`Database Clickhouse was connected to ${this.name}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
override async sync(force: boolean)
|
|
28
|
+
{
|
|
29
|
+
if (!process.env.NAMIRASOFT_MUTE)
|
|
30
|
+
if (force)
|
|
31
|
+
{
|
|
32
|
+
// There is no such a feature
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
override getSortOptions()
|
|
36
|
+
{
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { BaseClickhouseDatabase } from "./BaseClickhouseDatabase";
|
|
2
|
+
import { BaseTable } from "namirasoft-node";
|
|
3
|
+
import { BaseMetaColumn, BaseMetaTable } from "namirasoft-core";
|
|
4
|
+
import { AnySchema, ArraySchema, BaseTypeSchema, BoolSchema, DateTimeSchema, DoubleSchema, StringSchema, TypeSchema, VariableSchema } from "namirasoft-schema";
|
|
5
|
+
import { BaseClickhouseModelSchemaColumnOptions } from "./BaseClickhouseModelSchemaColumnOptions";
|
|
6
|
+
import { BaseClickhouseModelSchema } from "./BaseClickhouseModelSchema";
|
|
7
|
+
|
|
8
|
+
export abstract class BaseClickhouseTable<D extends BaseClickhouseDatabase> extends BaseTable<D, BaseClickhouseModelSchemaColumnOptions>
|
|
9
|
+
{
|
|
10
|
+
name!: string;
|
|
11
|
+
schema!: BaseClickhouseModelSchema;
|
|
12
|
+
constructor(database: D, name: string)
|
|
13
|
+
{
|
|
14
|
+
super(database);
|
|
15
|
+
this.name = name;
|
|
16
|
+
}
|
|
17
|
+
override getName(): string
|
|
18
|
+
{
|
|
19
|
+
return this.name;
|
|
20
|
+
}
|
|
21
|
+
override getSecureColumns(): string[]
|
|
22
|
+
{
|
|
23
|
+
let columns = super.getSecureColumns();
|
|
24
|
+
return ["_id", "__v", "deleted_at", "deletedAt", ...columns]
|
|
25
|
+
}
|
|
26
|
+
override getReadOnlyColumns(): string[]
|
|
27
|
+
{
|
|
28
|
+
let columns = super.getReadOnlyColumns();
|
|
29
|
+
return ["id", "created_at", "updated_at", "createdAt", "updatedAt", ...columns];
|
|
30
|
+
}
|
|
31
|
+
private getModelAllSchemas()
|
|
32
|
+
{
|
|
33
|
+
let otherAttributes: BaseClickhouseModelSchema = {
|
|
34
|
+
_id: { type: String, required: true },
|
|
35
|
+
__v: { type: String, required: true },
|
|
36
|
+
};
|
|
37
|
+
return { ... this.schema, ...otherAttributes };
|
|
38
|
+
}
|
|
39
|
+
public override getColumnOption(name: string)
|
|
40
|
+
{
|
|
41
|
+
let schema = this.getModelAllSchemas();
|
|
42
|
+
return schema[name] as BaseClickhouseModelSchemaColumnOptions;
|
|
43
|
+
}
|
|
44
|
+
public override forEachColumn(handler: (name: string, column: BaseClickhouseModelSchemaColumnOptions) => void)
|
|
45
|
+
{
|
|
46
|
+
let schema = this.getModelAllSchemas();
|
|
47
|
+
let keys = Object.keys(schema);
|
|
48
|
+
for (let i = 0; i < keys.length; i++)
|
|
49
|
+
handler(keys[i], this.getColumnOption(keys[i]));
|
|
50
|
+
}
|
|
51
|
+
public override getColumn(name: string): BaseMetaColumn
|
|
52
|
+
{
|
|
53
|
+
let option = this.getColumnOption(name);
|
|
54
|
+
let table_name = this.getName();
|
|
55
|
+
let table = new BaseMetaTable(null, table_name, table_name);
|
|
56
|
+
let type = option.type;
|
|
57
|
+
try
|
|
58
|
+
{
|
|
59
|
+
if (typeof (type) == "function")
|
|
60
|
+
type = type.name;
|
|
61
|
+
} catch (error)
|
|
62
|
+
{
|
|
63
|
+
}
|
|
64
|
+
let column = new BaseMetaColumn(table, name, name, type, option.required);
|
|
65
|
+
return column;
|
|
66
|
+
}
|
|
67
|
+
protected override getTypeSchema(option: BaseClickhouseModelSchemaColumnOptions): BaseTypeSchema
|
|
68
|
+
{
|
|
69
|
+
let required = option.required;
|
|
70
|
+
/* VariableType */
|
|
71
|
+
if (option.type === Boolean)
|
|
72
|
+
return new BoolSchema(required);
|
|
73
|
+
// else if (type instanceof Number)
|
|
74
|
+
// return new TinyIntSchema(required);
|
|
75
|
+
// else if (type instanceof DataTypes.SMALLINT)
|
|
76
|
+
// return new SmallIntSchema(required);
|
|
77
|
+
// else if (type instanceof DataTypes.MEDIUMINT)
|
|
78
|
+
// return new MediumIntSchema(required);
|
|
79
|
+
// else if (type instanceof DataTypes.INTEGER)
|
|
80
|
+
// return new IntegerSchema(required);
|
|
81
|
+
// else if (type instanceof DataTypes.BIGINT)
|
|
82
|
+
// return new BigIntSchema(required);
|
|
83
|
+
// else if (this.isFloat(type))
|
|
84
|
+
// return new FloatSchema(required, type.options.decimals);
|
|
85
|
+
else if (option.type === Number)
|
|
86
|
+
return new DoubleSchema(required, null);
|
|
87
|
+
// else if (this.isDecimal(type))
|
|
88
|
+
// return new DecimalSchema(required, type.options.scale);
|
|
89
|
+
// else if (this.isReal(type))
|
|
90
|
+
// return new RealSchema(required, type.options.decimals);
|
|
91
|
+
// else if (this.isChar(type))
|
|
92
|
+
// return new StringSchema(required, type.options.length, type.options.length);
|
|
93
|
+
else if (option.type === String)
|
|
94
|
+
return new StringSchema(required, null, null);
|
|
95
|
+
// else if (type instanceof DataTypes.TEXT)
|
|
96
|
+
// return new StringSchema(required, null, null);
|
|
97
|
+
else if (option.type === Date)
|
|
98
|
+
return new DateTimeSchema(required);
|
|
99
|
+
// else if (type instanceof DataTypes.DATEONLY)
|
|
100
|
+
// return new DateSchema(required);
|
|
101
|
+
// else if (type instanceof DataTypes.TIME)
|
|
102
|
+
// return new TimeSchema(required);
|
|
103
|
+
// else if (type instanceof DataTypes.DURATION)
|
|
104
|
+
// return new DurationSchema(required);
|
|
105
|
+
// else if (this.isEnum(type))
|
|
106
|
+
// {
|
|
107
|
+
// let name = NamingConvention.lower_case_underscore.convert(this.model.modelName + "_" + element.field, NamingConvention.Pascal_Case);
|
|
108
|
+
// return new EnumSchema(name, required, type.options.values);
|
|
109
|
+
// }
|
|
110
|
+
// else if (type instanceof DataTypes.JSON)
|
|
111
|
+
// return new AnySchema(required);
|
|
112
|
+
else if (option.type === Object)
|
|
113
|
+
{
|
|
114
|
+
let tags_type = option.tags?.type;
|
|
115
|
+
if (tags_type)
|
|
116
|
+
{
|
|
117
|
+
if (tags_type === "BaseTypeSchema")
|
|
118
|
+
return new TypeSchema(required);
|
|
119
|
+
if (tags_type === "BaseVariableSchema")
|
|
120
|
+
return new VariableSchema(required);
|
|
121
|
+
if (tags_type === "BaseTypeSchema[]")
|
|
122
|
+
return new ArraySchema(required, [new TypeSchema(required)]);
|
|
123
|
+
if (tags_type === "BaseVariableSchema[]")
|
|
124
|
+
return new ArraySchema(required, [new VariableSchema(required)]);
|
|
125
|
+
}
|
|
126
|
+
return new AnySchema(required);
|
|
127
|
+
}
|
|
128
|
+
throw new Error("Unsupported datatype for schema: " + option);
|
|
129
|
+
}
|
|
130
|
+
// async _getOrNull(filter?: FilterQuery<M>, projection?: ProjectionType<M> | null, options?: QueryOptions<M> | null): Promise<BaseDocument<M> | null>
|
|
131
|
+
// {
|
|
132
|
+
// return await this.model.findOne(filter, projection, options);
|
|
133
|
+
// }
|
|
134
|
+
// async _get(filter?: FilterQuery<M>, projection?: ProjectionType<M> | null, options?: QueryOptions<M> | null): Promise<BaseDocument<M>>
|
|
135
|
+
// {
|
|
136
|
+
// let value = await this._getOrNull(filter, projection, options);
|
|
137
|
+
// if (value != null)
|
|
138
|
+
// return value;
|
|
139
|
+
// throw this.getNotFoundError(filter);
|
|
140
|
+
// }
|
|
141
|
+
// async _list(where: { [name: string]: any }, pagination: { dont: true } | { page: number, size: number }, sorts: { dont: true } | SortItem[]): Promise<{ rows: M[], count: number }>
|
|
142
|
+
// {
|
|
143
|
+
// let query = this.model.find<M>(where);
|
|
144
|
+
// if (!('dont' in pagination))
|
|
145
|
+
// {
|
|
146
|
+
// let { offset, limit } = this.database.paginate(pagination.page, pagination.size);
|
|
147
|
+
// query = query.skip(offset);
|
|
148
|
+
// query = query.limit(limit);
|
|
149
|
+
// }
|
|
150
|
+
// if (!('dont' in sorts))
|
|
151
|
+
// {
|
|
152
|
+
// let sort_options = this.database.getSortOptions(sorts);
|
|
153
|
+
// query = query.sort(sort_options);
|
|
154
|
+
// }
|
|
155
|
+
// let rows = await query.exec();
|
|
156
|
+
// let count = await this.model.countDocuments(where);
|
|
157
|
+
// return { rows, count };
|
|
158
|
+
// }
|
|
159
|
+
}
|
package/src/index.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES6",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"lib": [
|
|
8
|
+
"es6",
|
|
9
|
+
"dom"
|
|
10
|
+
],
|
|
11
|
+
"allowJs": false,
|
|
12
|
+
"checkJs": false,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
"sourceMap": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"declaration": true,
|
|
18
|
+
"noUnusedLocals": true,
|
|
19
|
+
"noUnusedParameters": true,
|
|
20
|
+
"noImplicitAny": true,
|
|
21
|
+
"noImplicitOverride": true,
|
|
22
|
+
"noImplicitReturns": true,
|
|
23
|
+
"noImplicitThis": true,
|
|
24
|
+
"skipLibCheck": true,
|
|
25
|
+
"allowSyntheticDefaultImports": true,
|
|
26
|
+
"forceConsistentCasingInFileNames": true,
|
|
27
|
+
"noFallthroughCasesInSwitch": true,
|
|
28
|
+
"isolatedModules": false,
|
|
29
|
+
"removeComments": true
|
|
30
|
+
},
|
|
31
|
+
"include": [
|
|
32
|
+
"src",
|
|
33
|
+
"build/types/**/*.ts"
|
|
34
|
+
],
|
|
35
|
+
"exclude": [
|
|
36
|
+
"node_modules",
|
|
37
|
+
"build",
|
|
38
|
+
"dist",
|
|
39
|
+
"static",
|
|
40
|
+
"public"
|
|
41
|
+
]
|
|
42
|
+
}
|