@klapeks/micro-db-utils 0.0.11 → 0.0.12
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/migrations/mysql.migrations.js +2 -0
- package/dist/selectors/abstract.select.handler.d.ts +3 -1
- package/dist/selectors/abstract.select.handler.js +13 -5
- package/dist/selectors/raw-mysql.select.handler.d.ts +3 -1
- package/dist/selectors/raw-mysql.select.handler.js +3 -0
- package/dist/selectors/typeorm.select.handler.d.ts +3 -1
- package/dist/selectors/typeorm.select.handler.js +5 -2
- package/dist/utils/columns.types.d.ts +8 -0
- package/dist/utils/columns.types.js +5 -3
- package/package.json +2 -2
|
@@ -88,6 +88,8 @@ var MySQLMigrations = /** @class */ (function () {
|
|
|
88
88
|
case 0:
|
|
89
89
|
_b.trys.push([0, 11, , 12]);
|
|
90
90
|
options_1 = (0, utils_1.dataSourceOptions)();
|
|
91
|
+
if (options_1.type != 'mysql')
|
|
92
|
+
return [2 /*return*/];
|
|
91
93
|
mysqlInstance_1 = new mysql_connection_1.RawMySQLConnection(options_1);
|
|
92
94
|
return [4 /*yield*/, mysqlInstance_1.takePool()];
|
|
93
95
|
case 1:
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { SelectOptions, SelectResult, TimedStatisticInfo } from '@klapeks/api-creation-tools';
|
|
1
|
+
import type { SelectOptions, SelectResult, TimedStatisticInfo } from '@klapeks/api-creation-tools';
|
|
2
|
+
import { DatabaseOptions } from '@klapeks/utils';
|
|
2
3
|
export interface SelectEntityHandlerOptions<T extends object, K extends string> {
|
|
3
4
|
name: K;
|
|
4
5
|
orderBy?: keyof T | (keyof T)[];
|
|
@@ -12,6 +13,7 @@ export declare abstract class AbstractSelectHandler<T extends object, K extends
|
|
|
12
13
|
readonly options: O;
|
|
13
14
|
constructor(options: O);
|
|
14
15
|
abstract getTableName(): string;
|
|
16
|
+
abstract getDatabaseType(): DatabaseOptions['type'];
|
|
15
17
|
abstract runSQL(query: string, params?: any[]): Promise<any[]>;
|
|
16
18
|
runSQL_One(query: string, params?: any[]): Promise<any>;
|
|
17
19
|
abstract getTotal(): Promise<number>;
|
|
@@ -77,12 +77,20 @@ var AbstractSelectHandler = /** @class */ (function () {
|
|
|
77
77
|
});
|
|
78
78
|
};
|
|
79
79
|
AbstractSelectHandler.prototype.sqlCount = function (field) {
|
|
80
|
-
var _a;
|
|
80
|
+
var _a, _b;
|
|
81
81
|
return __awaiter(this, void 0, void 0, function () {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
case
|
|
82
|
+
var _c, _d;
|
|
83
|
+
return __generator(this, function (_e) {
|
|
84
|
+
switch (_e.label) {
|
|
85
|
+
case 0:
|
|
86
|
+
if (!(this.getDatabaseType() === 'mssql')) return [3 /*break*/, 2];
|
|
87
|
+
_c = Number;
|
|
88
|
+
return [4 /*yield*/, this.runSQL_One("\n SELECT count(".concat(field, ") as [count]\n FROM ").concat(this.getTableName(), ";\n "))];
|
|
89
|
+
case 1: return [2 /*return*/, _c.apply(void 0, [(_a = (_e.sent())) === null || _a === void 0 ? void 0 : _a.count])];
|
|
90
|
+
case 2:
|
|
91
|
+
_d = Number;
|
|
92
|
+
return [4 /*yield*/, this.runSQL_One("\n SELECT count(".concat(field, ") as 'count'\n FROM ").concat(this.getTableName(), ";\n "))];
|
|
93
|
+
case 3: return [2 /*return*/, _d.apply(void 0, [(_b = (_e.sent())) === null || _b === void 0 ? void 0 : _b.count])];
|
|
86
94
|
}
|
|
87
95
|
});
|
|
88
96
|
});
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { SelectOptions } from "@klapeks/api-creation-tools";
|
|
1
|
+
import { type SelectOptions } from "@klapeks/api-creation-tools";
|
|
2
2
|
import { RawMySQLConnection } from "../connections";
|
|
3
3
|
import { AbstractSelectHandler, SelectEntityHandlerOptions } from "./abstract.select.handler";
|
|
4
|
+
import { DatabaseOptions } from "@klapeks/utils";
|
|
4
5
|
export type MySQLSelectEntityHandlerOptions<T extends object, K extends string> = SelectEntityHandlerOptions<T, K> & {
|
|
5
6
|
schemaTableName: string;
|
|
6
7
|
mysql: RawMySQLConnection;
|
|
7
8
|
};
|
|
8
9
|
export declare class MySQLSelectEntityHandler<T extends object, K extends string> extends AbstractSelectHandler<T, K, MySQLSelectEntityHandlerOptions<T, K>> {
|
|
9
10
|
constructor(options: MySQLSelectEntityHandlerOptions<T, K>);
|
|
11
|
+
getDatabaseType(): DatabaseOptions['type'];
|
|
10
12
|
getTableName(): string;
|
|
11
13
|
runSQL(sql: string, params?: any[]): Promise<any[]>;
|
|
12
14
|
getTotal(): Promise<number>;
|
|
@@ -58,6 +58,9 @@ var MySQLSelectEntityHandler = /** @class */ (function (_super) {
|
|
|
58
58
|
function MySQLSelectEntityHandler(options) {
|
|
59
59
|
return _super.call(this, options) || this;
|
|
60
60
|
}
|
|
61
|
+
MySQLSelectEntityHandler.prototype.getDatabaseType = function () {
|
|
62
|
+
return 'mysql';
|
|
63
|
+
};
|
|
61
64
|
MySQLSelectEntityHandler.prototype.getTableName = function () {
|
|
62
65
|
return this.options.schemaTableName;
|
|
63
66
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DataSource, EntitySchema, ObjectLiteral, SelectQueryBuilder } from 'typeorm';
|
|
2
2
|
import { AbstractSelectHandler, SelectEntityHandlerOptions } from './abstract.select.handler';
|
|
3
|
-
import { SelectOptions } from '@klapeks/api-creation-tools';
|
|
3
|
+
import { type SelectOptions } from '@klapeks/api-creation-tools';
|
|
4
|
+
import { DatabaseOptions } from '@klapeks/utils';
|
|
4
5
|
export type TypeormSelectEntityHandlerOptions<T extends ObjectLiteral, K extends string> = SelectEntityHandlerOptions<T, K> & {
|
|
5
6
|
schema: EntitySchema<T>;
|
|
6
7
|
dataSource: DataSource;
|
|
@@ -11,6 +12,7 @@ export declare class SelectEntityHandler<T extends ObjectLiteral, K extends stri
|
|
|
11
12
|
get dataSource(): DataSource;
|
|
12
13
|
get schema(): EntitySchema<T>;
|
|
13
14
|
get repo(): import("typeorm").Repository<T>;
|
|
15
|
+
getDatabaseType(): DatabaseOptions['type'];
|
|
14
16
|
getTableName(): string;
|
|
15
17
|
runSQL(sql: string, params?: any[]): Promise<any[]>;
|
|
16
18
|
getTotal(): Promise<number>;
|
|
@@ -74,6 +74,9 @@ var SelectEntityHandler = /** @class */ (function (_super) {
|
|
|
74
74
|
enumerable: false,
|
|
75
75
|
configurable: true
|
|
76
76
|
});
|
|
77
|
+
SelectEntityHandler.prototype.getDatabaseType = function () {
|
|
78
|
+
return this.dataSource.options.type;
|
|
79
|
+
};
|
|
77
80
|
SelectEntityHandler.prototype.getTableName = function () {
|
|
78
81
|
return this.schema.options.name;
|
|
79
82
|
};
|
|
@@ -139,12 +142,12 @@ var SelectEntityHandler = /** @class */ (function (_super) {
|
|
|
139
142
|
if (typeof where[key] === 'undefined')
|
|
140
143
|
continue;
|
|
141
144
|
if (where[key] == null) {
|
|
142
|
-
qb2 = qb2.andWhere(
|
|
145
|
+
qb2 = qb2.andWhere(key + ' IS NULL');
|
|
143
146
|
continue;
|
|
144
147
|
}
|
|
145
148
|
if (typeof where[key] == 'string' && where[key].startsWith('{like}=')) {
|
|
146
149
|
var strVal = where[key].substring(7).toLowerCase();
|
|
147
|
-
qb2 = qb2.andWhere('
|
|
150
|
+
qb2 = qb2.andWhere('LOWER(' + key + ') LIKE :' + placeholderKey, (_a = {}, _a[placeholderKey] = strVal, _a));
|
|
148
151
|
continue;
|
|
149
152
|
}
|
|
150
153
|
qb2 = qb2.andWhere(key + ' = :' + placeholderKey, (_b = {}, _b[placeholderKey] = where[key], _b));
|
|
@@ -8,6 +8,14 @@ export declare function createRelation(target: string, type: "one-to-many" | "on
|
|
|
8
8
|
cascade: boolean;
|
|
9
9
|
inverseSide: string;
|
|
10
10
|
};
|
|
11
|
+
export declare const MULTISQL_COLUMNS_TYPES: {
|
|
12
|
+
dbtype: "mysql" | "sqlite" | "postgres" | "mssql";
|
|
13
|
+
enum: "enum" | "simple-enum";
|
|
14
|
+
datetime: "timestamp" | "datetime" | "datetime2";
|
|
15
|
+
float32: "double" | "float";
|
|
16
|
+
float64: "double" | "float";
|
|
17
|
+
json: "json" | "simple-json";
|
|
18
|
+
};
|
|
11
19
|
export declare const FloatingColumn: EntitySchemaColumnOptions;
|
|
12
20
|
export declare const NullableFloatingColumn: {
|
|
13
21
|
default: null;
|
|
@@ -11,19 +11,21 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.NullableFloat64Column = exports.Float64Column = exports.NullableFloatingColumn = exports.FloatingColumn = exports.createRelation = void 0;
|
|
14
|
+
exports.NullableFloat64Column = exports.Float64Column = exports.NullableFloatingColumn = exports.FloatingColumn = exports.MULTISQL_COLUMNS_TYPES = exports.createRelation = void 0;
|
|
15
|
+
var utils_1 = require("@klapeks/utils");
|
|
15
16
|
function createRelation(target, type, inverseSide, cascade) {
|
|
16
17
|
if (cascade === void 0) { cascade = true; }
|
|
17
18
|
return { target: target, type: type, cascade: cascade, inverseSide: inverseSide };
|
|
18
19
|
}
|
|
19
20
|
exports.createRelation = createRelation;
|
|
21
|
+
exports.MULTISQL_COLUMNS_TYPES = (0, utils_1.getDatabaseColumnTypes)();
|
|
20
22
|
exports.FloatingColumn = {
|
|
21
|
-
type:
|
|
23
|
+
type: exports.MULTISQL_COLUMNS_TYPES.float32, default: 0
|
|
22
24
|
// type: "decimal", precision: 10, scale: 6, default: 0
|
|
23
25
|
};
|
|
24
26
|
exports.NullableFloatingColumn = __assign(__assign({}, exports.FloatingColumn), { default: null, nullable: true });
|
|
25
27
|
exports.Float64Column = {
|
|
26
|
-
type:
|
|
28
|
+
type: exports.MULTISQL_COLUMNS_TYPES.float64, default: 0
|
|
27
29
|
// type: "decimal", precision: 10, scale: 6, default: 0
|
|
28
30
|
};
|
|
29
31
|
exports.NullableFloat64Column = __assign(__assign({}, exports.Float64Column), { default: null, nullable: true });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@klapeks/micro-db-utils",
|
|
3
3
|
"description": "klapeks utils for db and other storages",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.12",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"author": "Klapeks",
|
|
7
7
|
"license": "ISC",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@aws-sdk/client-s3": "^3.842.0",
|
|
23
23
|
"@aws-sdk/s3-request-presigner": "^3.844.0",
|
|
24
24
|
"@klapeks/api-creation-tools": "^0.0.7",
|
|
25
|
-
"@klapeks/utils": "^0.1.
|
|
25
|
+
"@klapeks/utils": "^0.1.4",
|
|
26
26
|
"@types/node": "^18.11.18",
|
|
27
27
|
"axios": "^1.7.7",
|
|
28
28
|
"ioredis": "^5.6.1",
|