@ductape/sdk 0.0.4-v42 → 0.0.4-v43
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/apps/services/app.service.d.ts +10 -0
- package/dist/apps/services/app.service.js +22 -0
- package/dist/apps/services/app.service.js.map +1 -1
- package/dist/database/adapters/base.adapter.d.ts +176 -0
- package/dist/database/adapters/base.adapter.js +31 -0
- package/dist/database/adapters/base.adapter.js.map +1 -0
- package/dist/database/adapters/dynamodb.adapter.d.ts +83 -0
- package/dist/database/adapters/dynamodb.adapter.js +1237 -0
- package/dist/database/adapters/dynamodb.adapter.js.map +1 -0
- package/dist/database/adapters/mongodb.adapter.d.ts +70 -0
- package/dist/database/adapters/mongodb.adapter.js +717 -0
- package/dist/database/adapters/mongodb.adapter.js.map +1 -0
- package/dist/database/adapters/mysql.adapter.d.ts +141 -0
- package/dist/database/adapters/mysql.adapter.js +1221 -0
- package/dist/database/adapters/mysql.adapter.js.map +1 -0
- package/dist/database/adapters/postgresql.adapter.d.ts +142 -0
- package/dist/database/adapters/postgresql.adapter.js +1288 -0
- package/dist/database/adapters/postgresql.adapter.js.map +1 -0
- package/dist/database/database.service.d.ts +190 -0
- package/dist/database/database.service.js +552 -0
- package/dist/database/database.service.js.map +1 -0
- package/dist/database/index.d.ts +18 -0
- package/dist/database/index.js +98 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/types/aggregation.types.d.ts +202 -0
- package/dist/database/types/aggregation.types.js +21 -0
- package/dist/database/types/aggregation.types.js.map +1 -0
- package/dist/database/types/connection.types.d.ts +132 -0
- package/dist/database/types/connection.types.js +6 -0
- package/dist/database/types/connection.types.js.map +1 -0
- package/dist/database/types/database.types.d.ts +173 -0
- package/dist/database/types/database.types.js +73 -0
- package/dist/database/types/database.types.js.map +1 -0
- package/dist/database/types/index.d.ts +12 -0
- package/dist/database/types/index.js +37 -0
- package/dist/database/types/index.js.map +1 -0
- package/dist/database/types/index.types.d.ts +220 -0
- package/dist/database/types/index.types.js +27 -0
- package/dist/database/types/index.types.js.map +1 -0
- package/dist/database/types/migration.types.d.ts +205 -0
- package/dist/database/types/migration.types.js +44 -0
- package/dist/database/types/migration.types.js.map +1 -0
- package/dist/database/types/query.types.d.ts +274 -0
- package/dist/database/types/query.types.js +57 -0
- package/dist/database/types/query.types.js.map +1 -0
- package/dist/database/types/result.types.d.ts +218 -0
- package/dist/database/types/result.types.js +6 -0
- package/dist/database/types/result.types.js.map +1 -0
- package/dist/database/types/schema.types.d.ts +190 -0
- package/dist/database/types/schema.types.js +69 -0
- package/dist/database/types/schema.types.js.map +1 -0
- package/dist/database/utils/helpers.d.ts +66 -0
- package/dist/database/utils/helpers.js +501 -0
- package/dist/database/utils/helpers.js.map +1 -0
- package/dist/database/utils/migration.utils.d.ts +151 -0
- package/dist/database/utils/migration.utils.js +476 -0
- package/dist/database/utils/migration.utils.js.map +1 -0
- package/dist/database/utils/transaction.d.ts +64 -0
- package/dist/database/utils/transaction.js +130 -0
- package/dist/database/utils/transaction.js.map +1 -0
- package/dist/database/validators/connection.validator.d.ts +20 -0
- package/dist/database/validators/connection.validator.js +267 -0
- package/dist/database/validators/connection.validator.js.map +1 -0
- package/dist/database/validators/query.validator.d.ts +31 -0
- package/dist/database/validators/query.validator.js +305 -0
- package/dist/database/validators/query.validator.js.map +1 -0
- package/dist/database/validators/schema.validator.d.ts +31 -0
- package/dist/database/validators/schema.validator.js +334 -0
- package/dist/database/validators/schema.validator.js.map +1 -0
- package/dist/index.d.ts +25 -4
- package/dist/index.js +36 -4
- package/dist/index.js.map +1 -1
- package/dist/processor/services/processor.service.js +10 -8
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/types/processor.types.d.ts +2 -2
- package/package.json +3 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Database module index
|
|
4
|
+
* Exports the main database service and all types
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.assertValidColumn = exports.assertValidTableSchema = exports.validateIndexDefinition = exports.validateColumnDefinition = exports.validateTableSchema = exports.assertValidConnection = exports.validateConnection = exports.deepClone = exports.snakeToCamel = exports.camelToSnake = exports.sanitizeTableName = exports.retryOperation = exports.isForeignKeyError = exports.isDuplicateKeyError = exports.isConnectionError = exports.formatDatabaseError = exports.escapeValue = exports.escapeIdentifier = exports.buildMongoQuery = exports.buildWhereClause = exports.mapColumnTypeToNative = exports.generateMigrationTemplate = exports.generateMigrationFileContent = exports.SchemaHelpers = exports.addIndexMigration = exports.addColumnMigration = exports.createTableMigration = exports.rawSql = exports.dropConstraint = exports.addConstraint = exports.dropIndex = exports.addIndex = exports.renameColumn = exports.modifyColumn = exports.dropColumn = exports.addColumn = exports.dropTable = exports.createTable = exports.createMigration = exports.generateMigrationTimestamp = exports.generateMigrationTag = exports.TransactionFactory = exports.Savepoint = exports.Transaction = exports.DynamoDBAdapter = exports.MySQLAdapter = exports.MongoDBAdapter = exports.PostgreSQLAdapter = exports.BaseDatabaseAdapter = exports.DatabaseService = void 0;
|
|
22
|
+
exports.assertValidUpdateData = exports.assertValidInsertData = exports.assertValidQueryOptions = exports.validateUpdateData = exports.validateInsertData = exports.validateQueryOptions = exports.assertValidIndex = void 0;
|
|
23
|
+
// Export main service
|
|
24
|
+
var database_service_1 = require("./database.service");
|
|
25
|
+
Object.defineProperty(exports, "DatabaseService", { enumerable: true, get: function () { return database_service_1.DatabaseService; } });
|
|
26
|
+
// Export all types
|
|
27
|
+
__exportStar(require("./types"), exports);
|
|
28
|
+
// Export adapters (for advanced usage)
|
|
29
|
+
var base_adapter_1 = require("./adapters/base.adapter");
|
|
30
|
+
Object.defineProperty(exports, "BaseDatabaseAdapter", { enumerable: true, get: function () { return base_adapter_1.BaseDatabaseAdapter; } });
|
|
31
|
+
var postgresql_adapter_1 = require("./adapters/postgresql.adapter");
|
|
32
|
+
Object.defineProperty(exports, "PostgreSQLAdapter", { enumerable: true, get: function () { return postgresql_adapter_1.PostgreSQLAdapter; } });
|
|
33
|
+
var mongodb_adapter_1 = require("./adapters/mongodb.adapter");
|
|
34
|
+
Object.defineProperty(exports, "MongoDBAdapter", { enumerable: true, get: function () { return mongodb_adapter_1.MongoDBAdapter; } });
|
|
35
|
+
var mysql_adapter_1 = require("./adapters/mysql.adapter");
|
|
36
|
+
Object.defineProperty(exports, "MySQLAdapter", { enumerable: true, get: function () { return mysql_adapter_1.MySQLAdapter; } });
|
|
37
|
+
var dynamodb_adapter_1 = require("./adapters/dynamodb.adapter");
|
|
38
|
+
Object.defineProperty(exports, "DynamoDBAdapter", { enumerable: true, get: function () { return dynamodb_adapter_1.DynamoDBAdapter; } });
|
|
39
|
+
// Export utilities
|
|
40
|
+
var transaction_1 = require("./utils/transaction");
|
|
41
|
+
Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return transaction_1.Transaction; } });
|
|
42
|
+
Object.defineProperty(exports, "Savepoint", { enumerable: true, get: function () { return transaction_1.Savepoint; } });
|
|
43
|
+
Object.defineProperty(exports, "TransactionFactory", { enumerable: true, get: function () { return transaction_1.TransactionFactory; } });
|
|
44
|
+
var migration_utils_1 = require("./utils/migration.utils");
|
|
45
|
+
Object.defineProperty(exports, "generateMigrationTag", { enumerable: true, get: function () { return migration_utils_1.generateMigrationTag; } });
|
|
46
|
+
Object.defineProperty(exports, "generateMigrationTimestamp", { enumerable: true, get: function () { return migration_utils_1.generateMigrationTimestamp; } });
|
|
47
|
+
Object.defineProperty(exports, "createMigration", { enumerable: true, get: function () { return migration_utils_1.createMigration; } });
|
|
48
|
+
Object.defineProperty(exports, "createTable", { enumerable: true, get: function () { return migration_utils_1.createTable; } });
|
|
49
|
+
Object.defineProperty(exports, "dropTable", { enumerable: true, get: function () { return migration_utils_1.dropTable; } });
|
|
50
|
+
Object.defineProperty(exports, "addColumn", { enumerable: true, get: function () { return migration_utils_1.addColumn; } });
|
|
51
|
+
Object.defineProperty(exports, "dropColumn", { enumerable: true, get: function () { return migration_utils_1.dropColumn; } });
|
|
52
|
+
Object.defineProperty(exports, "modifyColumn", { enumerable: true, get: function () { return migration_utils_1.modifyColumn; } });
|
|
53
|
+
Object.defineProperty(exports, "renameColumn", { enumerable: true, get: function () { return migration_utils_1.renameColumn; } });
|
|
54
|
+
Object.defineProperty(exports, "addIndex", { enumerable: true, get: function () { return migration_utils_1.addIndex; } });
|
|
55
|
+
Object.defineProperty(exports, "dropIndex", { enumerable: true, get: function () { return migration_utils_1.dropIndex; } });
|
|
56
|
+
Object.defineProperty(exports, "addConstraint", { enumerable: true, get: function () { return migration_utils_1.addConstraint; } });
|
|
57
|
+
Object.defineProperty(exports, "dropConstraint", { enumerable: true, get: function () { return migration_utils_1.dropConstraint; } });
|
|
58
|
+
Object.defineProperty(exports, "rawSql", { enumerable: true, get: function () { return migration_utils_1.rawSql; } });
|
|
59
|
+
Object.defineProperty(exports, "createTableMigration", { enumerable: true, get: function () { return migration_utils_1.createTableMigration; } });
|
|
60
|
+
Object.defineProperty(exports, "addColumnMigration", { enumerable: true, get: function () { return migration_utils_1.addColumnMigration; } });
|
|
61
|
+
Object.defineProperty(exports, "addIndexMigration", { enumerable: true, get: function () { return migration_utils_1.addIndexMigration; } });
|
|
62
|
+
Object.defineProperty(exports, "SchemaHelpers", { enumerable: true, get: function () { return migration_utils_1.SchemaHelpers; } });
|
|
63
|
+
Object.defineProperty(exports, "generateMigrationFileContent", { enumerable: true, get: function () { return migration_utils_1.generateMigrationFileContent; } });
|
|
64
|
+
Object.defineProperty(exports, "generateMigrationTemplate", { enumerable: true, get: function () { return migration_utils_1.generateMigrationTemplate; } });
|
|
65
|
+
var helpers_1 = require("./utils/helpers");
|
|
66
|
+
Object.defineProperty(exports, "mapColumnTypeToNative", { enumerable: true, get: function () { return helpers_1.mapColumnTypeToNative; } });
|
|
67
|
+
Object.defineProperty(exports, "buildWhereClause", { enumerable: true, get: function () { return helpers_1.buildWhereClause; } });
|
|
68
|
+
Object.defineProperty(exports, "buildMongoQuery", { enumerable: true, get: function () { return helpers_1.buildMongoQuery; } });
|
|
69
|
+
Object.defineProperty(exports, "escapeIdentifier", { enumerable: true, get: function () { return helpers_1.escapeIdentifier; } });
|
|
70
|
+
Object.defineProperty(exports, "escapeValue", { enumerable: true, get: function () { return helpers_1.escapeValue; } });
|
|
71
|
+
Object.defineProperty(exports, "formatDatabaseError", { enumerable: true, get: function () { return helpers_1.formatDatabaseError; } });
|
|
72
|
+
Object.defineProperty(exports, "isConnectionError", { enumerable: true, get: function () { return helpers_1.isConnectionError; } });
|
|
73
|
+
Object.defineProperty(exports, "isDuplicateKeyError", { enumerable: true, get: function () { return helpers_1.isDuplicateKeyError; } });
|
|
74
|
+
Object.defineProperty(exports, "isForeignKeyError", { enumerable: true, get: function () { return helpers_1.isForeignKeyError; } });
|
|
75
|
+
Object.defineProperty(exports, "retryOperation", { enumerable: true, get: function () { return helpers_1.retryOperation; } });
|
|
76
|
+
Object.defineProperty(exports, "sanitizeTableName", { enumerable: true, get: function () { return helpers_1.sanitizeTableName; } });
|
|
77
|
+
Object.defineProperty(exports, "camelToSnake", { enumerable: true, get: function () { return helpers_1.camelToSnake; } });
|
|
78
|
+
Object.defineProperty(exports, "snakeToCamel", { enumerable: true, get: function () { return helpers_1.snakeToCamel; } });
|
|
79
|
+
Object.defineProperty(exports, "deepClone", { enumerable: true, get: function () { return helpers_1.deepClone; } });
|
|
80
|
+
// Export validators
|
|
81
|
+
var connection_validator_1 = require("./validators/connection.validator");
|
|
82
|
+
Object.defineProperty(exports, "validateConnection", { enumerable: true, get: function () { return connection_validator_1.validateConnection; } });
|
|
83
|
+
Object.defineProperty(exports, "assertValidConnection", { enumerable: true, get: function () { return connection_validator_1.assertValidConnection; } });
|
|
84
|
+
var schema_validator_1 = require("./validators/schema.validator");
|
|
85
|
+
Object.defineProperty(exports, "validateTableSchema", { enumerable: true, get: function () { return schema_validator_1.validateTableSchema; } });
|
|
86
|
+
Object.defineProperty(exports, "validateColumnDefinition", { enumerable: true, get: function () { return schema_validator_1.validateColumnDefinition; } });
|
|
87
|
+
Object.defineProperty(exports, "validateIndexDefinition", { enumerable: true, get: function () { return schema_validator_1.validateIndexDefinition; } });
|
|
88
|
+
Object.defineProperty(exports, "assertValidTableSchema", { enumerable: true, get: function () { return schema_validator_1.assertValidTableSchema; } });
|
|
89
|
+
Object.defineProperty(exports, "assertValidColumn", { enumerable: true, get: function () { return schema_validator_1.assertValidColumn; } });
|
|
90
|
+
Object.defineProperty(exports, "assertValidIndex", { enumerable: true, get: function () { return schema_validator_1.assertValidIndex; } });
|
|
91
|
+
var query_validator_1 = require("./validators/query.validator");
|
|
92
|
+
Object.defineProperty(exports, "validateQueryOptions", { enumerable: true, get: function () { return query_validator_1.validateQueryOptions; } });
|
|
93
|
+
Object.defineProperty(exports, "validateInsertData", { enumerable: true, get: function () { return query_validator_1.validateInsertData; } });
|
|
94
|
+
Object.defineProperty(exports, "validateUpdateData", { enumerable: true, get: function () { return query_validator_1.validateUpdateData; } });
|
|
95
|
+
Object.defineProperty(exports, "assertValidQueryOptions", { enumerable: true, get: function () { return query_validator_1.assertValidQueryOptions; } });
|
|
96
|
+
Object.defineProperty(exports, "assertValidInsertData", { enumerable: true, get: function () { return query_validator_1.assertValidInsertData; } });
|
|
97
|
+
Object.defineProperty(exports, "assertValidUpdateData", { enumerable: true, get: function () { return query_validator_1.assertValidUpdateData; } });
|
|
98
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;AAEH,sBAAsB;AACtB,uDAAqD;AAA5C,mHAAA,eAAe,OAAA;AAExB,mBAAmB;AACnB,0CAAwB;AAExB,uCAAuC;AACvC,wDAA8D;AAArD,mHAAA,mBAAmB,OAAA;AAC5B,oEAAkE;AAAzD,uHAAA,iBAAiB,OAAA;AAC1B,8DAA4D;AAAnD,iHAAA,cAAc,OAAA;AACvB,0DAAwD;AAA/C,6GAAA,YAAY,OAAA;AACrB,gEAA8D;AAArD,mHAAA,eAAe,OAAA;AAExB,mBAAmB;AACnB,mDAAiF;AAAxE,0GAAA,WAAW,OAAA;AAAE,wGAAA,SAAS,OAAA;AAAE,iHAAA,kBAAkB,OAAA;AACnD,2DAqBiC;AApB/B,uHAAA,oBAAoB,OAAA;AACpB,6HAAA,0BAA0B,OAAA;AAC1B,kHAAA,eAAe,OAAA;AACf,8GAAA,WAAW,OAAA;AACX,4GAAA,SAAS,OAAA;AACT,4GAAA,SAAS,OAAA;AACT,6GAAA,UAAU,OAAA;AACV,+GAAA,YAAY,OAAA;AACZ,+GAAA,YAAY,OAAA;AACZ,2GAAA,QAAQ,OAAA;AACR,4GAAA,SAAS,OAAA;AACT,gHAAA,aAAa,OAAA;AACb,iHAAA,cAAc,OAAA;AACd,yGAAA,MAAM,OAAA;AACN,uHAAA,oBAAoB,OAAA;AACpB,qHAAA,kBAAkB,OAAA;AAClB,oHAAA,iBAAiB,OAAA;AACjB,gHAAA,aAAa,OAAA;AACb,+HAAA,4BAA4B,OAAA;AAC5B,4HAAA,yBAAyB,OAAA;AAE3B,2CAeyB;AAdvB,gHAAA,qBAAqB,OAAA;AACrB,2GAAA,gBAAgB,OAAA;AAChB,0GAAA,eAAe,OAAA;AACf,2GAAA,gBAAgB,OAAA;AAChB,sGAAA,WAAW,OAAA;AACX,8GAAA,mBAAmB,OAAA;AACnB,4GAAA,iBAAiB,OAAA;AACjB,8GAAA,mBAAmB,OAAA;AACnB,4GAAA,iBAAiB,OAAA;AACjB,yGAAA,cAAc,OAAA;AACd,4GAAA,iBAAiB,OAAA;AACjB,uGAAA,YAAY,OAAA;AACZ,uGAAA,YAAY,OAAA;AACZ,oGAAA,SAAS,OAAA;AAGX,oBAAoB;AACpB,0EAA8F;AAArF,0HAAA,kBAAkB,OAAA;AAAE,6HAAA,qBAAqB,OAAA;AAElD,kEAOuC;AANrC,uHAAA,mBAAmB,OAAA;AACnB,4HAAA,wBAAwB,OAAA;AACxB,2HAAA,uBAAuB,OAAA;AACvB,0HAAA,sBAAsB,OAAA;AACtB,qHAAA,iBAAiB,OAAA;AACjB,oHAAA,gBAAgB,OAAA;AAElB,gEAOsC;AANpC,uHAAA,oBAAoB,OAAA;AACpB,qHAAA,kBAAkB,OAAA;AAClB,qHAAA,kBAAkB,OAAA;AAClB,0HAAA,uBAAuB,OAAA;AACvB,wHAAA,qBAAqB,OAAA;AACrB,wHAAA,qBAAqB,OAAA"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aggregation type definitions for database operations
|
|
3
|
+
*/
|
|
4
|
+
import { WhereClause, IOrderBy } from './query.types';
|
|
5
|
+
/**
|
|
6
|
+
* Aggregation function types
|
|
7
|
+
*/
|
|
8
|
+
export declare enum AggregationFunction {
|
|
9
|
+
COUNT = "count",
|
|
10
|
+
SUM = "sum",
|
|
11
|
+
AVG = "avg",
|
|
12
|
+
MIN = "min",
|
|
13
|
+
MAX = "max",
|
|
14
|
+
GROUP_CONCAT = "group_concat",// MySQL
|
|
15
|
+
STRING_AGG = "string_agg",// PostgreSQL
|
|
16
|
+
ARRAY_AGG = "array_agg"
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Single aggregation operation
|
|
20
|
+
*/
|
|
21
|
+
export interface IAggregationOperation {
|
|
22
|
+
/** Aggregation function */
|
|
23
|
+
function: AggregationFunction;
|
|
24
|
+
/** Column to aggregate */
|
|
25
|
+
column: string;
|
|
26
|
+
/** Alias for the result */
|
|
27
|
+
alias?: string;
|
|
28
|
+
/** Distinct values only */
|
|
29
|
+
distinct?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Count options
|
|
33
|
+
*/
|
|
34
|
+
export interface ICountOptions {
|
|
35
|
+
/** Table/Collection name */
|
|
36
|
+
table: string;
|
|
37
|
+
/** Environment slug */
|
|
38
|
+
env: string;
|
|
39
|
+
/** Product tag */
|
|
40
|
+
product?: string;
|
|
41
|
+
/** Database tag */
|
|
42
|
+
database?: string;
|
|
43
|
+
/** Where clause */
|
|
44
|
+
where?: WhereClause;
|
|
45
|
+
/** Column to count (default: '*') */
|
|
46
|
+
column?: string;
|
|
47
|
+
/** Count distinct values only */
|
|
48
|
+
distinct?: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Sum options
|
|
52
|
+
*/
|
|
53
|
+
export interface ISumOptions {
|
|
54
|
+
/** Table/Collection name */
|
|
55
|
+
table: string;
|
|
56
|
+
/** Environment slug */
|
|
57
|
+
env: string;
|
|
58
|
+
/** Product tag */
|
|
59
|
+
product?: string;
|
|
60
|
+
/** Database tag */
|
|
61
|
+
database?: string;
|
|
62
|
+
/** Column to sum */
|
|
63
|
+
column: string;
|
|
64
|
+
/** Where clause */
|
|
65
|
+
where?: WhereClause;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Average options
|
|
69
|
+
*/
|
|
70
|
+
export interface IAvgOptions {
|
|
71
|
+
/** Table/Collection name */
|
|
72
|
+
table: string;
|
|
73
|
+
/** Environment slug */
|
|
74
|
+
env: string;
|
|
75
|
+
/** Product tag */
|
|
76
|
+
product?: string;
|
|
77
|
+
/** Database tag */
|
|
78
|
+
database?: string;
|
|
79
|
+
/** Column to average */
|
|
80
|
+
column: string;
|
|
81
|
+
/** Where clause */
|
|
82
|
+
where?: WhereClause;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Min options
|
|
86
|
+
*/
|
|
87
|
+
export interface IMinOptions {
|
|
88
|
+
/** Table/Collection name */
|
|
89
|
+
table: string;
|
|
90
|
+
/** Environment slug */
|
|
91
|
+
env: string;
|
|
92
|
+
/** Product tag */
|
|
93
|
+
product?: string;
|
|
94
|
+
/** Database tag */
|
|
95
|
+
database?: string;
|
|
96
|
+
/** Column to find minimum */
|
|
97
|
+
column: string;
|
|
98
|
+
/** Where clause */
|
|
99
|
+
where?: WhereClause;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Max options
|
|
103
|
+
*/
|
|
104
|
+
export interface IMaxOptions {
|
|
105
|
+
/** Table/Collection name */
|
|
106
|
+
table: string;
|
|
107
|
+
/** Environment slug */
|
|
108
|
+
env: string;
|
|
109
|
+
/** Product tag */
|
|
110
|
+
product?: string;
|
|
111
|
+
/** Database tag */
|
|
112
|
+
database?: string;
|
|
113
|
+
/** Column to find maximum */
|
|
114
|
+
column: string;
|
|
115
|
+
/** Where clause */
|
|
116
|
+
where?: WhereClause;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Group by options
|
|
120
|
+
*/
|
|
121
|
+
export interface IGroupByOptions {
|
|
122
|
+
/** Table/Collection name */
|
|
123
|
+
table: string;
|
|
124
|
+
/** Environment slug */
|
|
125
|
+
env: string;
|
|
126
|
+
/** Product tag */
|
|
127
|
+
product?: string;
|
|
128
|
+
/** Database tag */
|
|
129
|
+
database?: string;
|
|
130
|
+
/** Columns to group by */
|
|
131
|
+
groupBy: string[];
|
|
132
|
+
/** Aggregation operations */
|
|
133
|
+
aggregate?: Record<string, IAggregationOperation>;
|
|
134
|
+
/** Where clause (applied before grouping) */
|
|
135
|
+
where?: WhereClause;
|
|
136
|
+
/** Having clause (applied after grouping) */
|
|
137
|
+
having?: WhereClause;
|
|
138
|
+
/** Order by */
|
|
139
|
+
orderBy?: IOrderBy | IOrderBy[];
|
|
140
|
+
/** Limit results */
|
|
141
|
+
limit?: number;
|
|
142
|
+
/** Offset */
|
|
143
|
+
offset?: number;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Aggregate options (multiple aggregations)
|
|
147
|
+
*/
|
|
148
|
+
export interface IAggregateOptions {
|
|
149
|
+
/** Table/Collection name */
|
|
150
|
+
table: string;
|
|
151
|
+
/** Environment slug */
|
|
152
|
+
env: string;
|
|
153
|
+
/** Product tag */
|
|
154
|
+
product?: string;
|
|
155
|
+
/** Database tag */
|
|
156
|
+
database?: string;
|
|
157
|
+
/** Aggregation operations */
|
|
158
|
+
operations: Record<string, IAggregationOperation>;
|
|
159
|
+
/** Where clause */
|
|
160
|
+
where?: WhereClause;
|
|
161
|
+
/** Group by columns (optional) */
|
|
162
|
+
groupBy?: string[];
|
|
163
|
+
/** Having clause */
|
|
164
|
+
having?: WhereClause;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Aggregation result for a single operation
|
|
168
|
+
*/
|
|
169
|
+
export interface IAggregationResult {
|
|
170
|
+
/** Result value */
|
|
171
|
+
value: number | string | null;
|
|
172
|
+
/** Column that was aggregated */
|
|
173
|
+
column?: string;
|
|
174
|
+
/** Function used */
|
|
175
|
+
function: AggregationFunction;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Group by result
|
|
179
|
+
*/
|
|
180
|
+
export interface IGroupByResult {
|
|
181
|
+
/** Grouped columns and their values */
|
|
182
|
+
groupedBy: Record<string, any>;
|
|
183
|
+
/** Aggregated values */
|
|
184
|
+
aggregates: Record<string, number | string | null>;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Statistics result (multiple aggregations)
|
|
188
|
+
*/
|
|
189
|
+
export interface IStatisticsResult {
|
|
190
|
+
/** Count */
|
|
191
|
+
count?: number;
|
|
192
|
+
/** Sum */
|
|
193
|
+
sum?: number;
|
|
194
|
+
/** Average */
|
|
195
|
+
avg?: number;
|
|
196
|
+
/** Minimum */
|
|
197
|
+
min?: number | string;
|
|
198
|
+
/** Maximum */
|
|
199
|
+
max?: number | string;
|
|
200
|
+
/** Additional custom aggregations */
|
|
201
|
+
[key: string]: any;
|
|
202
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Aggregation type definitions for database operations
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AggregationFunction = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Aggregation function types
|
|
9
|
+
*/
|
|
10
|
+
var AggregationFunction;
|
|
11
|
+
(function (AggregationFunction) {
|
|
12
|
+
AggregationFunction["COUNT"] = "count";
|
|
13
|
+
AggregationFunction["SUM"] = "sum";
|
|
14
|
+
AggregationFunction["AVG"] = "avg";
|
|
15
|
+
AggregationFunction["MIN"] = "min";
|
|
16
|
+
AggregationFunction["MAX"] = "max";
|
|
17
|
+
AggregationFunction["GROUP_CONCAT"] = "group_concat";
|
|
18
|
+
AggregationFunction["STRING_AGG"] = "string_agg";
|
|
19
|
+
AggregationFunction["ARRAY_AGG"] = "array_agg";
|
|
20
|
+
})(AggregationFunction || (exports.AggregationFunction = AggregationFunction = {}));
|
|
21
|
+
//# sourceMappingURL=aggregation.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregation.types.js","sourceRoot":"","sources":["../../../src/database/types/aggregation.types.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAIH;;GAEG;AACH,IAAY,mBASX;AATD,WAAY,mBAAmB;IAC7B,sCAAe,CAAA;IACf,kCAAW,CAAA;IACX,kCAAW,CAAA;IACX,kCAAW,CAAA;IACX,kCAAW,CAAA;IACX,oDAA6B,CAAA;IAC7B,gDAAyB,CAAA;IACzB,8CAAuB,CAAA;AACzB,CAAC,EATW,mBAAmB,mCAAnB,mBAAmB,QAS9B"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection configuration types for different database systems
|
|
3
|
+
*/
|
|
4
|
+
import { DatabaseType } from './database.types';
|
|
5
|
+
/**
|
|
6
|
+
* Base connection configuration
|
|
7
|
+
*/
|
|
8
|
+
export interface IBaseConnectionConfig {
|
|
9
|
+
/** Database type */
|
|
10
|
+
type: DatabaseType;
|
|
11
|
+
/** Environment slug */
|
|
12
|
+
env: string;
|
|
13
|
+
/** Optional connection tag */
|
|
14
|
+
connectionTag?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Product-based connection configuration
|
|
18
|
+
* Connects using a configured database in a product
|
|
19
|
+
*/
|
|
20
|
+
export interface IProductConnectionConfig {
|
|
21
|
+
/** Environment slug */
|
|
22
|
+
env: string;
|
|
23
|
+
/** Product tag */
|
|
24
|
+
product: string;
|
|
25
|
+
/** Database tag within the product */
|
|
26
|
+
database: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* PostgreSQL connection configuration
|
|
30
|
+
*/
|
|
31
|
+
export interface IPostgreSQLConfig extends IBaseConnectionConfig {
|
|
32
|
+
type: DatabaseType.POSTGRESQL;
|
|
33
|
+
host: string;
|
|
34
|
+
port?: number;
|
|
35
|
+
database: string;
|
|
36
|
+
user: string;
|
|
37
|
+
password: string;
|
|
38
|
+
ssl?: boolean | {
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
};
|
|
41
|
+
poolSize?: number;
|
|
42
|
+
connectionTimeout?: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* MySQL connection configuration
|
|
46
|
+
*/
|
|
47
|
+
export interface IMySQLConfig extends IBaseConnectionConfig {
|
|
48
|
+
type: DatabaseType.MYSQL;
|
|
49
|
+
host: string;
|
|
50
|
+
port?: number;
|
|
51
|
+
database: string;
|
|
52
|
+
user: string;
|
|
53
|
+
password: string;
|
|
54
|
+
ssl?: boolean | {
|
|
55
|
+
[key: string]: any;
|
|
56
|
+
};
|
|
57
|
+
poolSize?: number;
|
|
58
|
+
connectionTimeout?: number;
|
|
59
|
+
charset?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* MongoDB connection configuration
|
|
63
|
+
*/
|
|
64
|
+
export interface IMongoDBConfig extends IBaseConnectionConfig {
|
|
65
|
+
type: DatabaseType.MONGODB;
|
|
66
|
+
uri: string;
|
|
67
|
+
database: string;
|
|
68
|
+
options?: {
|
|
69
|
+
useNewUrlParser?: boolean;
|
|
70
|
+
useUnifiedTopology?: boolean;
|
|
71
|
+
poolSize?: number;
|
|
72
|
+
serverSelectionTimeoutMS?: number;
|
|
73
|
+
[key: string]: any;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* DynamoDB connection configuration
|
|
78
|
+
*/
|
|
79
|
+
export interface IDynamoDBConfig extends IBaseConnectionConfig {
|
|
80
|
+
type: DatabaseType.DYNAMODB;
|
|
81
|
+
region: string;
|
|
82
|
+
accessKeyId: string;
|
|
83
|
+
secretAccessKey: string;
|
|
84
|
+
endpoint?: string;
|
|
85
|
+
options?: {
|
|
86
|
+
maxRetries?: number;
|
|
87
|
+
httpOptions?: {
|
|
88
|
+
timeout?: number;
|
|
89
|
+
};
|
|
90
|
+
[key: string]: any;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* SQLite connection configuration
|
|
95
|
+
*/
|
|
96
|
+
export interface ISQLiteConfig extends IBaseConnectionConfig {
|
|
97
|
+
type: DatabaseType.SQLITE;
|
|
98
|
+
filename: string;
|
|
99
|
+
mode?: number;
|
|
100
|
+
options?: {
|
|
101
|
+
readonly?: boolean;
|
|
102
|
+
fileMustExist?: boolean;
|
|
103
|
+
timeout?: number;
|
|
104
|
+
[key: string]: any;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Union type for all connection configurations
|
|
109
|
+
*/
|
|
110
|
+
export type DatabaseConnectionConfig = IPostgreSQLConfig | IMySQLConfig | IMongoDBConfig | IDynamoDBConfig | ISQLiteConfig | IProductConnectionConfig;
|
|
111
|
+
/**
|
|
112
|
+
* Connection pool configuration
|
|
113
|
+
*/
|
|
114
|
+
export interface IConnectionPoolConfig {
|
|
115
|
+
min?: number;
|
|
116
|
+
max?: number;
|
|
117
|
+
idleTimeoutMillis?: number;
|
|
118
|
+
connectionTimeoutMillis?: number;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Connection options
|
|
122
|
+
*/
|
|
123
|
+
export interface IConnectionOptions {
|
|
124
|
+
/** Auto-retry connection on failure */
|
|
125
|
+
autoRetry?: boolean;
|
|
126
|
+
/** Max retry attempts */
|
|
127
|
+
maxRetries?: number;
|
|
128
|
+
/** Retry delay in milliseconds */
|
|
129
|
+
retryDelay?: number;
|
|
130
|
+
/** Connection pool configuration */
|
|
131
|
+
pool?: IConnectionPoolConfig;
|
|
132
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.types.js","sourceRoot":"","sources":["../../../src/database/types/connection.types.ts"],"names":[],"mappings":";AAAA;;GAEG"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core database type definitions for the Ductape Database ORM
|
|
3
|
+
* Provides unified interface for SQL and NoSQL databases
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Supported database types
|
|
7
|
+
*/
|
|
8
|
+
export declare enum DatabaseType {
|
|
9
|
+
POSTGRESQL = "postgresql",
|
|
10
|
+
MYSQL = "mysql",
|
|
11
|
+
MONGODB = "mongodb",
|
|
12
|
+
DYNAMODB = "dynamodb",
|
|
13
|
+
SQLITE = "sqlite"
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Database connection status
|
|
17
|
+
*/
|
|
18
|
+
export declare enum ConnectionStatus {
|
|
19
|
+
DISCONNECTED = "disconnected",
|
|
20
|
+
CONNECTING = "connecting",
|
|
21
|
+
CONNECTED = "connected",
|
|
22
|
+
ERROR = "error"
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Base database configuration
|
|
26
|
+
*/
|
|
27
|
+
export interface IDatabaseConfig {
|
|
28
|
+
/** Database type */
|
|
29
|
+
type: DatabaseType;
|
|
30
|
+
/** Environment slug */
|
|
31
|
+
env: string;
|
|
32
|
+
/** Optional connection tag for reusing existing connections */
|
|
33
|
+
connectionTag?: string;
|
|
34
|
+
/** Optional database name */
|
|
35
|
+
database?: string;
|
|
36
|
+
/** Custom connection options */
|
|
37
|
+
options?: Record<string, any>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Database connection interface
|
|
41
|
+
*/
|
|
42
|
+
export interface IConnection {
|
|
43
|
+
/** Unique connection ID */
|
|
44
|
+
id: string;
|
|
45
|
+
/** Database type */
|
|
46
|
+
type: DatabaseType;
|
|
47
|
+
/** Connection status */
|
|
48
|
+
status: ConnectionStatus;
|
|
49
|
+
/** Connect to database */
|
|
50
|
+
connect(): Promise<void>;
|
|
51
|
+
/** Disconnect from database */
|
|
52
|
+
disconnect(): Promise<void>;
|
|
53
|
+
/** Check if connected */
|
|
54
|
+
isConnected(): boolean;
|
|
55
|
+
/** Get native client */
|
|
56
|
+
getClient<T = any>(): T;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Base database adapter interface
|
|
60
|
+
* All database-specific adapters must implement this interface
|
|
61
|
+
*/
|
|
62
|
+
export interface IDatabaseAdapter {
|
|
63
|
+
/** Database type this adapter handles */
|
|
64
|
+
readonly type: DatabaseType;
|
|
65
|
+
/** Create a connection */
|
|
66
|
+
createConnection(config: IDatabaseConfig): Promise<IConnection>;
|
|
67
|
+
/** Close a connection */
|
|
68
|
+
closeConnection(connection: IConnection): Promise<void>;
|
|
69
|
+
/** Execute a query */
|
|
70
|
+
executeQuery(connection: IConnection, query: string, params?: any[]): Promise<any>;
|
|
71
|
+
/** Begin transaction */
|
|
72
|
+
beginTransaction(connection: IConnection): Promise<any>;
|
|
73
|
+
/** Commit transaction */
|
|
74
|
+
commitTransaction(connection: IConnection, transaction: any): Promise<void>;
|
|
75
|
+
/** Rollback transaction */
|
|
76
|
+
rollbackTransaction(connection: IConnection, transaction: any): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Database error types
|
|
80
|
+
*/
|
|
81
|
+
export declare enum DatabaseErrorType {
|
|
82
|
+
CONNECTION_ERROR = "connection_error",
|
|
83
|
+
QUERY_ERROR = "query_error",
|
|
84
|
+
VALIDATION_ERROR = "validation_error",
|
|
85
|
+
MIGRATION_ERROR = "migration_error",
|
|
86
|
+
SCHEMA_ERROR = "schema_error",
|
|
87
|
+
INDEX_ERROR = "index_error"
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Database error class
|
|
91
|
+
*/
|
|
92
|
+
export declare class DatabaseError extends Error {
|
|
93
|
+
type: DatabaseErrorType;
|
|
94
|
+
originalError?: Error;
|
|
95
|
+
constructor(type: DatabaseErrorType, message: string, originalError?: Error);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Transaction isolation levels
|
|
99
|
+
*/
|
|
100
|
+
export declare enum TransactionIsolationLevel {
|
|
101
|
+
READ_UNCOMMITTED = "READ_UNCOMMITTED",
|
|
102
|
+
READ_COMMITTED = "READ_COMMITTED",
|
|
103
|
+
REPEATABLE_READ = "REPEATABLE_READ",
|
|
104
|
+
SERIALIZABLE = "SERIALIZABLE"
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Transaction status
|
|
108
|
+
*/
|
|
109
|
+
export declare enum TransactionStatus {
|
|
110
|
+
ACTIVE = "active",
|
|
111
|
+
COMMITTED = "committed",
|
|
112
|
+
ROLLED_BACK = "rolled_back",
|
|
113
|
+
FAILED = "failed"
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Transaction interface
|
|
117
|
+
*/
|
|
118
|
+
export interface ITransaction {
|
|
119
|
+
/** Unique transaction ID */
|
|
120
|
+
id: string;
|
|
121
|
+
/** Connection this transaction belongs to */
|
|
122
|
+
connection: IConnection;
|
|
123
|
+
/** Transaction status */
|
|
124
|
+
status: TransactionStatus;
|
|
125
|
+
/** Isolation level */
|
|
126
|
+
isolationLevel?: TransactionIsolationLevel;
|
|
127
|
+
/** Parent transaction (for nested transactions) */
|
|
128
|
+
parent?: ITransaction;
|
|
129
|
+
/** Created timestamp */
|
|
130
|
+
createdAt: Date;
|
|
131
|
+
/** Native transaction object */
|
|
132
|
+
native: any;
|
|
133
|
+
/** Commit the transaction */
|
|
134
|
+
commit(): Promise<void>;
|
|
135
|
+
/** Rollback the transaction */
|
|
136
|
+
rollback(): Promise<void>;
|
|
137
|
+
/** Create a savepoint (for nested transactions) */
|
|
138
|
+
savepoint(name: string): Promise<ISavepoint>;
|
|
139
|
+
/** Check if transaction is active */
|
|
140
|
+
isActive(): boolean;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Savepoint interface
|
|
144
|
+
*/
|
|
145
|
+
export interface ISavepoint {
|
|
146
|
+
/** Savepoint name */
|
|
147
|
+
name: string;
|
|
148
|
+
/** Transaction this savepoint belongs to */
|
|
149
|
+
transaction: ITransaction;
|
|
150
|
+
/** Created timestamp */
|
|
151
|
+
createdAt: Date;
|
|
152
|
+
/** Rollback to this savepoint */
|
|
153
|
+
rollback(): Promise<void>;
|
|
154
|
+
/** Release this savepoint */
|
|
155
|
+
release(): Promise<void>;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Transaction options
|
|
159
|
+
*/
|
|
160
|
+
export interface ITransactionOptions {
|
|
161
|
+
/** Isolation level */
|
|
162
|
+
isolationLevel?: TransactionIsolationLevel;
|
|
163
|
+
/** Read only transaction */
|
|
164
|
+
readOnly?: boolean;
|
|
165
|
+
/** Timeout in milliseconds */
|
|
166
|
+
timeout?: number;
|
|
167
|
+
/** Deferrable (PostgreSQL) */
|
|
168
|
+
deferrable?: boolean;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Transaction callback function
|
|
172
|
+
*/
|
|
173
|
+
export type TransactionCallback<T> = (transaction: ITransaction) => Promise<T>;
|