@klapeks/micro-db-utils 0.0.1

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.
Files changed (49) hide show
  1. package/dist/backups/mysql.backup.d.ts +7 -0
  2. package/dist/backups/mysql.backup.js +156 -0
  3. package/dist/connections/cloud/s3.d.ts +23 -0
  4. package/dist/connections/cloud/s3.js +169 -0
  5. package/dist/connections/index.d.ts +5 -0
  6. package/dist/connections/index.js +25 -0
  7. package/dist/connections/kafka/index.d.ts +3 -0
  8. package/dist/connections/kafka/index.js +21 -0
  9. package/dist/connections/kafka/kafka.consumer.d.ts +13 -0
  10. package/dist/connections/kafka/kafka.consumer.js +128 -0
  11. package/dist/connections/kafka/kafka.d.ts +16 -0
  12. package/dist/connections/kafka/kafka.js +205 -0
  13. package/dist/connections/kafka/kafka.producer.d.ts +11 -0
  14. package/dist/connections/kafka/kafka.producer.js +101 -0
  15. package/dist/connections/mysql.connection.d.ts +15 -0
  16. package/dist/connections/mysql.connection.js +165 -0
  17. package/dist/connections/nosql/mongo.d.ts +56 -0
  18. package/dist/connections/nosql/mongo.js +192 -0
  19. package/dist/connections/nosql/redis.d.ts +310 -0
  20. package/dist/connections/nosql/redis.js +129 -0
  21. package/dist/connections/quiet.require.d.ts +1 -0
  22. package/dist/connections/quiet.require.js +12 -0
  23. package/dist/index.d.ts +4 -0
  24. package/dist/index.js +20 -0
  25. package/dist/migrations/index.d.ts +1 -0
  26. package/dist/migrations/index.js +17 -0
  27. package/dist/migrations/mysql.migrations.d.ts +6 -0
  28. package/dist/migrations/mysql.migrations.js +220 -0
  29. package/dist/selectors/abstract.select.handler.d.ts +26 -0
  30. package/dist/selectors/abstract.select.handler.js +202 -0
  31. package/dist/selectors/index.d.ts +3 -0
  32. package/dist/selectors/index.js +19 -0
  33. package/dist/selectors/raw-mysql.select.handler.d.ts +17 -0
  34. package/dist/selectors/raw-mysql.select.handler.js +149 -0
  35. package/dist/selectors/typeorm.select.handler.d.ts +21 -0
  36. package/dist/selectors/typeorm.select.handler.js +187 -0
  37. package/dist/utils/columns.types.d.ts +100 -0
  38. package/dist/utils/columns.types.js +29 -0
  39. package/dist/utils/index.d.ts +3 -0
  40. package/dist/utils/index.js +21 -0
  41. package/dist/utils/iso.date.time.d.ts +2 -0
  42. package/dist/utils/iso.date.time.js +27 -0
  43. package/dist/utils/sqlite3.utils.d.ts +4 -0
  44. package/dist/utils/sqlite3.utils.js +60 -0
  45. package/dist/utils/where.utils.d.ts +3 -0
  46. package/dist/utils/where.utils.js +22 -0
  47. package/index.d.ts +1 -0
  48. package/index.js +2 -0
  49. package/package.json +37 -0
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.MySQLSelectEntityHandler = void 0;
55
+ var abstract_select_handler_1 = require("./abstract.select.handler");
56
+ var MySQLSelectEntityHandler = /** @class */ (function (_super) {
57
+ __extends(MySQLSelectEntityHandler, _super);
58
+ function MySQLSelectEntityHandler(options) {
59
+ return _super.call(this, options) || this;
60
+ }
61
+ MySQLSelectEntityHandler.prototype.getTableName = function () {
62
+ return this.options.schemaTableName;
63
+ };
64
+ MySQLSelectEntityHandler.prototype.runSQL = function (sql, params) {
65
+ return __awaiter(this, void 0, void 0, function () {
66
+ return __generator(this, function (_a) {
67
+ return [2 /*return*/, this.options.mysql.runSQL(sql, params)];
68
+ });
69
+ });
70
+ };
71
+ MySQLSelectEntityHandler.prototype.getTotal = function () {
72
+ var _a;
73
+ return __awaiter(this, void 0, void 0, function () {
74
+ return __generator(this, function (_b) {
75
+ switch (_b.label) {
76
+ case 0: return [4 /*yield*/, this.runSQL_One("\n SELECT count(1) as 'count'\n FROM ".concat(this.getTableName(), ";\n "))];
77
+ case 1: return [2 /*return*/, (_a = (_b.sent())) === null || _a === void 0 ? void 0 : _a.count];
78
+ }
79
+ });
80
+ });
81
+ };
82
+ MySQLSelectEntityHandler.prototype.rawSelect = function (options) {
83
+ var _a;
84
+ return __awaiter(this, void 0, void 0, function () {
85
+ var where, orderBy, limit, addOrderBy, i, whereCondition, result, totalCount;
86
+ var _this = this;
87
+ return __generator(this, function (_b) {
88
+ switch (_b.label) {
89
+ case 0:
90
+ where = [];
91
+ orderBy = '';
92
+ limit = '';
93
+ // if (options.where) {
94
+ // const W = options.where as any;
95
+ // for (let key of Object.keys(W)) {
96
+ // if (typeof W[key] == 'undefined' || W[key] === null) continue;
97
+ // where.push([key, W[key]]);
98
+ // }
99
+ // }
100
+ if (this.options.orderBy) {
101
+ orderBy = 'ORDER BY ';
102
+ addOrderBy = function (field, _index) {
103
+ if (_index === void 0) { _index = 0; }
104
+ var orderType = 'ASC';
105
+ if (Array.isArray(_this.options.orderType)) {
106
+ orderType = _this.options.orderType[_index] || _this.options.orderType[0];
107
+ }
108
+ else {
109
+ orderType = _this.options.orderType || 'ASC';
110
+ }
111
+ orderBy += field + ' ' + orderType.toUpperCase();
112
+ };
113
+ if (Array.isArray(this.options.orderBy)) {
114
+ for (i = 0; i < this.options.orderBy.length; i++) {
115
+ if (i)
116
+ orderBy += ', ';
117
+ addOrderBy(this.options.orderBy[i], i);
118
+ }
119
+ }
120
+ else {
121
+ addOrderBy(this.options.orderBy, 0);
122
+ }
123
+ }
124
+ if (options.limit) {
125
+ limit = 'LIMIT ' + options.limit;
126
+ if (options.offset) {
127
+ limit += ' OFFSET ' + options.offset;
128
+ }
129
+ }
130
+ whereCondition = (where === null || where === void 0 ? void 0 : where.length) ? ('WHERE ' + where.map(function (w) { return w[0] + ' = ?'; }).join(' AND ')) : '';
131
+ return [4 /*yield*/, this.runSQL("\n SELECT * FROM ".concat(this.getTableName(), "\n ").concat(whereCondition, " ").concat(orderBy, " ").concat(limit, "\n "), where.map(function (d) { return d[1]; }))];
132
+ case 1:
133
+ result = _b.sent();
134
+ return [4 /*yield*/, this.runSQL("\n SELECT count(1) as 'count' \n FROM ".concat(this.getTableName(), "\n ").concat(whereCondition, "\n "), where.map(function (d) { return d[1]; }))];
135
+ case 2:
136
+ totalCount = _b.sent();
137
+ if (!this.options.afterSelect) return [3 /*break*/, 4];
138
+ return [4 /*yield*/, this.options.afterSelect(result, options)];
139
+ case 3:
140
+ result = _b.sent();
141
+ _b.label = 4;
142
+ case 4: return [2 /*return*/, { objects: result, total: ((_a = totalCount === null || totalCount === void 0 ? void 0 : totalCount[0]) === null || _a === void 0 ? void 0 : _a.count) || NaN }];
143
+ }
144
+ });
145
+ });
146
+ };
147
+ return MySQLSelectEntityHandler;
148
+ }(abstract_select_handler_1.AbstractSelectHandler));
149
+ exports.MySQLSelectEntityHandler = MySQLSelectEntityHandler;
@@ -0,0 +1,21 @@
1
+ import { DataSource, EntitySchema, ObjectLiteral, SelectQueryBuilder } from 'typeorm';
2
+ import { AbstractSelectHandler, SelectEntityHandlerOptions } from './abstract.select.handler';
3
+ import { SelectOptions } from '@klapeks/api-creation-tools';
4
+ export type TypeormSelectEntityHandlerOptions<T extends ObjectLiteral, K extends string> = SelectEntityHandlerOptions<T, K> & {
5
+ schema: EntitySchema<T>;
6
+ dataSource: DataSource;
7
+ beforeGetMany?: (builder: SelectQueryBuilder<T>, options: SelectOptions<T>) => Promise<void> | void;
8
+ };
9
+ export declare class SelectEntityHandler<T extends ObjectLiteral, K extends string> extends AbstractSelectHandler<T, K, TypeormSelectEntityHandlerOptions<T, K>> {
10
+ constructor(options: TypeormSelectEntityHandlerOptions<T, K>);
11
+ get dataSource(): DataSource;
12
+ get schema(): EntitySchema<T>;
13
+ get repo(): import("typeorm").Repository<T>;
14
+ getTableName(): string;
15
+ runSQL(sql: string, params?: any[]): Promise<any[]>;
16
+ getTotal(): Promise<number>;
17
+ rawSelect(options: SelectOptions<T>): Promise<{
18
+ objects: T[];
19
+ total: number;
20
+ }>;
21
+ }
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.SelectEntityHandler = void 0;
55
+ var typeorm_1 = require("typeorm");
56
+ var abstract_select_handler_1 = require("./abstract.select.handler");
57
+ var SelectEntityHandler = /** @class */ (function (_super) {
58
+ __extends(SelectEntityHandler, _super);
59
+ function SelectEntityHandler(options) {
60
+ return _super.call(this, options) || this;
61
+ }
62
+ Object.defineProperty(SelectEntityHandler.prototype, "dataSource", {
63
+ get: function () { return this.options.dataSource; },
64
+ enumerable: false,
65
+ configurable: true
66
+ });
67
+ Object.defineProperty(SelectEntityHandler.prototype, "schema", {
68
+ get: function () { return this.options.schema; },
69
+ enumerable: false,
70
+ configurable: true
71
+ });
72
+ Object.defineProperty(SelectEntityHandler.prototype, "repo", {
73
+ get: function () { return this.dataSource.getRepository(this.schema); },
74
+ enumerable: false,
75
+ configurable: true
76
+ });
77
+ SelectEntityHandler.prototype.getTableName = function () {
78
+ return this.schema.options.name;
79
+ };
80
+ SelectEntityHandler.prototype.runSQL = function (sql, params) {
81
+ return __awaiter(this, void 0, void 0, function () {
82
+ return __generator(this, function (_a) {
83
+ return [2 /*return*/, this.dataSource.query(sql, params)];
84
+ });
85
+ });
86
+ };
87
+ SelectEntityHandler.prototype.getTotal = function () {
88
+ return __awaiter(this, void 0, void 0, function () {
89
+ return __generator(this, function (_a) {
90
+ return [2 /*return*/, this.repo.count()];
91
+ });
92
+ });
93
+ };
94
+ SelectEntityHandler.prototype.rawSelect = function (options) {
95
+ return __awaiter(this, void 0, void 0, function () {
96
+ var builder, addOrderBy, i, multipleWheres_1, result;
97
+ var _a;
98
+ var _this = this;
99
+ return __generator(this, function (_b) {
100
+ switch (_b.label) {
101
+ case 0:
102
+ builder = this.repo.createQueryBuilder(this.schema.options.name);
103
+ builder.select(this.schema.options.name + '.*');
104
+ // if (this.options.preBuilder) this.options.preBuilder(builder);
105
+ if (this.options.orderBy) {
106
+ addOrderBy = function (field, _index) {
107
+ if (_index === void 0) { _index = 0; }
108
+ var orderType = 'ASC';
109
+ if (Array.isArray(_this.options.orderType)) {
110
+ orderType = _this.options.orderType[_index] || _this.options.orderType[0];
111
+ }
112
+ else {
113
+ orderType = _this.options.orderType || 'ASC';
114
+ }
115
+ if (_index)
116
+ builder.addOrderBy(field, orderType.toUpperCase());
117
+ else
118
+ builder.orderBy(field, orderType.toUpperCase());
119
+ };
120
+ if (Array.isArray(this.options.orderBy)) {
121
+ for (i = 0; i < this.options.orderBy.length; i++) {
122
+ addOrderBy(this.options.orderBy[i], i);
123
+ }
124
+ }
125
+ else {
126
+ addOrderBy(this.options.orderBy, 0);
127
+ }
128
+ }
129
+ if (options.where) {
130
+ multipleWheres_1 = Array.isArray(options.where) ? options.where : [options.where];
131
+ builder.andWhere(new typeorm_1.Brackets(function (qb1) {
132
+ var _loop_1 = function (i) {
133
+ var where = multipleWheres_1[i];
134
+ qb1 = qb1.orWhere(new typeorm_1.Brackets(function (qb2) {
135
+ var _a, _b;
136
+ for (var _i = 0, _c = Object.keys(where); _i < _c.length; _i++) {
137
+ var key = _c[_i];
138
+ var placeholderKey = key + "_" + i;
139
+ if (typeof where[key] == undefined)
140
+ continue;
141
+ if (where[key] == null) {
142
+ qb2 = qb2.andWhere('key is NULL');
143
+ continue;
144
+ }
145
+ if (typeof where[key] == 'string' && where[key].startsWith('{like}=')) {
146
+ var strVal = where[key].substring(7).toLowerCase();
147
+ qb2 = qb2.andWhere('lower(' + key + ') like :' + placeholderKey, (_a = {}, _a[placeholderKey] = strVal, _a));
148
+ continue;
149
+ }
150
+ qb2 = qb2.andWhere(key + ' = :' + placeholderKey, (_b = {}, _b[placeholderKey] = where[key], _b));
151
+ }
152
+ }));
153
+ };
154
+ // qb1 = qb1.where('0 = 1');
155
+ for (var i = 0; i < multipleWheres_1.length; i++) {
156
+ _loop_1(i);
157
+ }
158
+ }));
159
+ }
160
+ if (!this.options.beforeGetMany) return [3 /*break*/, 2];
161
+ return [4 /*yield*/, this.options.beforeGetMany(builder, options)];
162
+ case 1:
163
+ _b.sent();
164
+ _b.label = 2;
165
+ case 2:
166
+ builder.limit(options.limit);
167
+ if (options.offset)
168
+ builder.offset(options.offset);
169
+ return [4 /*yield*/, builder.getRawMany()];
170
+ case 3:
171
+ result = _b.sent();
172
+ if (!this.options.afterSelect) return [3 /*break*/, 5];
173
+ return [4 /*yield*/, this.options.afterSelect(result, options)];
174
+ case 4:
175
+ result = _b.sent();
176
+ _b.label = 5;
177
+ case 5:
178
+ _a = { objects: result };
179
+ return [4 /*yield*/, builder.getCount()];
180
+ case 6: return [2 /*return*/, (_a.total = _b.sent(), _a)];
181
+ }
182
+ });
183
+ });
184
+ };
185
+ return SelectEntityHandler;
186
+ }(abstract_select_handler_1.AbstractSelectHandler));
187
+ exports.SelectEntityHandler = SelectEntityHandler;
@@ -0,0 +1,100 @@
1
+ import mongoose from "mongoose";
2
+ import { EntitySchemaColumnOptions, EntitySchemaOptions } from "typeorm";
3
+ export type RequiredColumns<T> = Required<EntitySchemaOptions<T>['columns']>;
4
+ export type RequiredMongoColumns<T> = Required<mongoose.Schema<T>>;
5
+ export declare function createRelation(target: string, type: "one-to-many" | "one-to-one", inverseSide: string, cascade?: boolean): {
6
+ target: string;
7
+ type: "one-to-many" | "one-to-one";
8
+ cascade: boolean;
9
+ inverseSide: string;
10
+ };
11
+ export declare const FloatingColumn: EntitySchemaColumnOptions;
12
+ export declare const NullableFloatingColumn: {
13
+ default: null;
14
+ nullable: boolean;
15
+ primary?: boolean | undefined;
16
+ objectId?: boolean | undefined;
17
+ createDate?: boolean | undefined;
18
+ updateDate?: boolean | undefined;
19
+ deleteDate?: boolean | undefined;
20
+ version?: boolean | undefined;
21
+ treeChildrenCount?: boolean | undefined;
22
+ treeLevel?: boolean | undefined;
23
+ virtualProperty?: boolean | undefined;
24
+ type: import("typeorm").ColumnType;
25
+ name?: string | undefined;
26
+ length?: string | number | undefined;
27
+ width?: number | undefined;
28
+ readonly?: boolean | undefined;
29
+ update?: boolean | undefined;
30
+ select?: boolean | undefined;
31
+ insert?: boolean | undefined;
32
+ generated?: true | "uuid" | "increment" | "rowid" | undefined;
33
+ unique?: boolean | undefined;
34
+ columnDefinition?: string | undefined;
35
+ comment?: string | undefined;
36
+ onUpdate?: string | undefined;
37
+ precision?: number | undefined;
38
+ scale?: number | undefined;
39
+ zerofill?: boolean | undefined;
40
+ unsigned?: boolean | undefined;
41
+ charset?: string | undefined;
42
+ collation?: string | undefined;
43
+ enum?: Object | any[] | undefined;
44
+ enumName?: string | undefined;
45
+ asExpression?: string | undefined;
46
+ generatedType?: "VIRTUAL" | "STORED" | undefined;
47
+ hstoreType?: "string" | "object" | undefined;
48
+ array?: boolean | undefined;
49
+ transformer?: import("typeorm").ValueTransformer | import("typeorm").ValueTransformer[] | undefined;
50
+ primaryKeyConstraintName?: string | undefined;
51
+ foreignKey?: import("typeorm/entity-schema/EntitySchemaColumnForeignKeyOptions").EntitySchemaColumnForeignKeyOptions | undefined;
52
+ query?: ((alias: string) => string) | undefined;
53
+ spatialFeatureType?: "Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon" | "GeometryCollection" | undefined;
54
+ srid?: number | undefined;
55
+ };
56
+ export declare const Float64Column: EntitySchemaColumnOptions;
57
+ export declare const NullableFloat64Column: {
58
+ default: null;
59
+ nullable: boolean;
60
+ primary?: boolean | undefined;
61
+ objectId?: boolean | undefined;
62
+ createDate?: boolean | undefined;
63
+ updateDate?: boolean | undefined;
64
+ deleteDate?: boolean | undefined;
65
+ version?: boolean | undefined;
66
+ treeChildrenCount?: boolean | undefined;
67
+ treeLevel?: boolean | undefined;
68
+ virtualProperty?: boolean | undefined;
69
+ type: import("typeorm").ColumnType;
70
+ name?: string | undefined;
71
+ length?: string | number | undefined;
72
+ width?: number | undefined;
73
+ readonly?: boolean | undefined;
74
+ update?: boolean | undefined;
75
+ select?: boolean | undefined;
76
+ insert?: boolean | undefined;
77
+ generated?: true | "uuid" | "increment" | "rowid" | undefined;
78
+ unique?: boolean | undefined;
79
+ columnDefinition?: string | undefined;
80
+ comment?: string | undefined;
81
+ onUpdate?: string | undefined;
82
+ precision?: number | undefined;
83
+ scale?: number | undefined;
84
+ zerofill?: boolean | undefined;
85
+ unsigned?: boolean | undefined;
86
+ charset?: string | undefined;
87
+ collation?: string | undefined;
88
+ enum?: Object | any[] | undefined;
89
+ enumName?: string | undefined;
90
+ asExpression?: string | undefined;
91
+ generatedType?: "VIRTUAL" | "STORED" | undefined;
92
+ hstoreType?: "string" | "object" | undefined;
93
+ array?: boolean | undefined;
94
+ transformer?: import("typeorm").ValueTransformer | import("typeorm").ValueTransformer[] | undefined;
95
+ primaryKeyConstraintName?: string | undefined;
96
+ foreignKey?: import("typeorm/entity-schema/EntitySchemaColumnForeignKeyOptions").EntitySchemaColumnForeignKeyOptions | undefined;
97
+ query?: ((alias: string) => string) | undefined;
98
+ spatialFeatureType?: "Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon" | "GeometryCollection" | undefined;
99
+ srid?: number | undefined;
100
+ };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.NullableFloat64Column = exports.Float64Column = exports.NullableFloatingColumn = exports.FloatingColumn = exports.createRelation = void 0;
15
+ function createRelation(target, type, inverseSide, cascade) {
16
+ if (cascade === void 0) { cascade = true; }
17
+ return { target: target, type: type, cascade: cascade, inverseSide: inverseSide };
18
+ }
19
+ exports.createRelation = createRelation;
20
+ exports.FloatingColumn = {
21
+ type: "float", default: 0
22
+ // type: "decimal", precision: 10, scale: 6, default: 0
23
+ };
24
+ exports.NullableFloatingColumn = __assign(__assign({}, exports.FloatingColumn), { default: null, nullable: true });
25
+ exports.Float64Column = {
26
+ type: "double", default: 0
27
+ // type: "decimal", precision: 10, scale: 6, default: 0
28
+ };
29
+ exports.NullableFloat64Column = __assign(__assign({}, exports.Float64Column), { default: null, nullable: true });
@@ -0,0 +1,3 @@
1
+ export * from './columns.types';
2
+ export * from './sqlite3.utils';
3
+ export * from './where.utils';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ // LOCAL, DON'T EXPORT
3
+ // export * from './iso.date.time';
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ __exportStar(require("./columns.types"), exports);
20
+ __exportStar(require("./sqlite3.utils"), exports);
21
+ __exportStar(require("./where.utils"), exports);
@@ -0,0 +1,2 @@
1
+ export declare function toISODate(date: Date, type?: 'yyyy-mm-dd' | "full"): string;
2
+ export declare function dateFromNow(func: (date: Date) => void, date?: Date): Date;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dateFromNow = exports.toISODate = void 0;
4
+ var pad2 = function (p) {
5
+ return p.toString().padStart(2, '0');
6
+ };
7
+ function toISODate(date, type) {
8
+ if (type === 'yyyy-mm-dd') {
9
+ return date.getFullYear()
10
+ + '-' + pad2(date.getMonth() + 1)
11
+ + '-' + pad2(date.getDate());
12
+ }
13
+ return date.getFullYear()
14
+ + '-' + pad2(date.getMonth() + 1)
15
+ + '-' + pad2(date.getDate())
16
+ + ' ' + pad2(date.getHours())
17
+ + ':' + pad2(date.getMinutes())
18
+ + ':' + pad2(date.getSeconds());
19
+ }
20
+ exports.toISODate = toISODate;
21
+ function dateFromNow(func, date) {
22
+ if (!date)
23
+ date = new Date();
24
+ func(date);
25
+ return date;
26
+ }
27
+ exports.dateFromNow = dateFromNow;
@@ -0,0 +1,4 @@
1
+ import type { Database } from "sqlite3";
2
+ export declare const sqlite3_utils: (db: Database) => {
3
+ all: <T>(query: string) => Promise<T[]>;
4
+ };
@@ -0,0 +1,60 @@
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
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.sqlite3_utils = void 0;
40
+ var sqlite3_utils = function (db) {
41
+ function all(query) {
42
+ return __awaiter(this, void 0, void 0, function () {
43
+ return __generator(this, function (_a) {
44
+ switch (_a.label) {
45
+ case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
46
+ db.all(query, function (err, data) {
47
+ if (err)
48
+ reject(err);
49
+ else
50
+ resolve(data);
51
+ });
52
+ })];
53
+ case 1: return [2 /*return*/, _a.sent()];
54
+ }
55
+ });
56
+ });
57
+ }
58
+ return { all: all };
59
+ };
60
+ exports.sqlite3_utils = sqlite3_utils;
@@ -0,0 +1,3 @@
1
+ import { ObjectLiteral, SelectQueryBuilder } from "typeorm";
2
+ export declare function addTimedWhere<T extends ObjectLiteral>(builder: SelectQueryBuilder<T>, dateAlias: string, from: Date, to?: Date): SelectQueryBuilder<T>;
3
+ export declare function rawTimedWhere(dateAlias: string, from: Date, to?: Date): string;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rawTimedWhere = exports.addTimedWhere = void 0;
4
+ var iso_date_time_1 = require("./iso.date.time");
5
+ function addTimedWhere(builder, dateAlias, from, to) {
6
+ builder.where("date(" + dateAlias + ") >= date(:from)", {
7
+ from: (0, iso_date_time_1.toISODate)(from, "yyyy-mm-dd")
8
+ });
9
+ if (to)
10
+ builder.andWhere("date(" + dateAlias + ") <= date(:to)", {
11
+ to: (0, iso_date_time_1.toISODate)(to, "yyyy-mm-dd")
12
+ });
13
+ return builder;
14
+ }
15
+ exports.addTimedWhere = addTimedWhere;
16
+ function rawTimedWhere(dateAlias, from, to) {
17
+ var sql = "date(" + dateAlias + ") >= date('" + (0, iso_date_time_1.toISODate)(from, "yyyy-mm-dd") + "') ";
18
+ if (to)
19
+ sql += "AND date(" + dateAlias + ") <= date('" + (0, iso_date_time_1.toISODate)(to, "yyyy-mm-dd") + "')";
20
+ return sql;
21
+ }
22
+ exports.rawTimedWhere = rawTimedWhere;
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/index.d';
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+ module.exports = require('./dist/index');