@hemia/db-connector 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.
@@ -0,0 +1,614 @@
1
+ 'use strict';
2
+
3
+ var mongoose = require('mongoose');
4
+ var sequelize = require('sequelize');
5
+
6
+ exports.CoreSqlTypes = void 0;
7
+ (function (CoreSqlTypes) {
8
+ CoreSqlTypes["Number"] = "Number";
9
+ CoreSqlTypes["string"] = "string";
10
+ CoreSqlTypes["DateTime"] = "DateTime";
11
+ CoreSqlTypes["Decimal"] = "Decimal";
12
+ CoreSqlTypes["Boolean"] = "Boolean";
13
+ CoreSqlTypes["Float"] = "Float";
14
+ })(exports.CoreSqlTypes || (exports.CoreSqlTypes = {}));
15
+
16
+ /******************************************************************************
17
+ Copyright (c) Microsoft Corporation.
18
+
19
+ Permission to use, copy, modify, and/or distribute this software for any
20
+ purpose with or without fee is hereby granted.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
23
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
24
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
25
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
26
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
27
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28
+ PERFORMANCE OF THIS SOFTWARE.
29
+ ***************************************************************************** */
30
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
31
+
32
+
33
+ function __awaiter(thisArg, _arguments, P, generator) {
34
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
35
+ return new (P || (P = Promise))(function (resolve, reject) {
36
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
37
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
38
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
39
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
40
+ });
41
+ }
42
+
43
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
44
+ var e = new Error(message);
45
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
46
+ };
47
+
48
+ class NoSQLConnector {
49
+ constructor() {
50
+ this.config = {};
51
+ this.provider = '';
52
+ this.connection = null;
53
+ }
54
+ }
55
+
56
+ exports.DBNoSQLType = void 0;
57
+ (function (DBNoSQLType) {
58
+ DBNoSQLType["MongoDB"] = "MongoDB";
59
+ DBNoSQLType["Cassandra"] = "Cassandra";
60
+ })(exports.DBNoSQLType || (exports.DBNoSQLType = {}));
61
+
62
+ class MongoDBConnector extends NoSQLConnector {
63
+ constructor(param) {
64
+ super();
65
+ this.currentSession = null;
66
+ this.config = param;
67
+ this.provider = exports.DBNoSQLType.MongoDB;
68
+ this.mongooseConnection = mongoose.connection;
69
+ }
70
+ connect() {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ try {
73
+ if (this.mongooseConnection.readyState === 1) {
74
+ return;
75
+ }
76
+ yield mongoose.connect(`mongodb://${this.config.host}:${this.config.port || 27017}`, {
77
+ user: this.config.user,
78
+ pass: this.config.password,
79
+ dbName: this.config.database,
80
+ });
81
+ this.mongooseConnection = mongoose.connection;
82
+ console.log('Connected to MongoDB');
83
+ }
84
+ catch (error) {
85
+ console.error('Error connecting to MongoDB:', error);
86
+ throw error;
87
+ }
88
+ });
89
+ }
90
+ disconnect() {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ try {
93
+ console.log('Disconnected from MongoDB');
94
+ yield this.mongooseConnection.close();
95
+ }
96
+ catch (error) {
97
+ console.error('Error disconnecting from MongoDB:', error);
98
+ throw error;
99
+ }
100
+ });
101
+ }
102
+ getConnection() {
103
+ return this.mongooseConnection;
104
+ }
105
+ isConnected() {
106
+ return this.mongooseConnection.readyState === 1;
107
+ }
108
+ state() {
109
+ return this.mongooseConnection.readyState;
110
+ }
111
+ getCredentials() {
112
+ return this.config;
113
+ }
114
+ getProvider() {
115
+ return this.provider;
116
+ }
117
+ startSession() {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ if (!this.currentSession) {
120
+ this.currentSession = yield this.mongooseConnection.startSession();
121
+ this.currentSession.startTransaction();
122
+ }
123
+ return this.currentSession;
124
+ });
125
+ }
126
+ commitTransaction() {
127
+ return __awaiter(this, void 0, void 0, function* () {
128
+ if (this.currentSession) {
129
+ yield this.currentSession.commitTransaction();
130
+ this.currentSession.endSession();
131
+ this.currentSession = null;
132
+ }
133
+ });
134
+ }
135
+ abortTransaction() {
136
+ return __awaiter(this, void 0, void 0, function* () {
137
+ if (this.currentSession) {
138
+ yield this.currentSession.abortTransaction();
139
+ this.currentSession.endSession();
140
+ this.currentSession = null;
141
+ }
142
+ });
143
+ }
144
+ withTransaction(transactionFn) {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ const session = yield this.startSession();
147
+ try {
148
+ const result = yield transactionFn(session);
149
+ yield this.commitTransaction();
150
+ return result;
151
+ }
152
+ catch (error) {
153
+ yield this.abortTransaction();
154
+ console.error('Transaction aborted:', error);
155
+ throw error;
156
+ }
157
+ });
158
+ }
159
+ create(model, data, session) {
160
+ return __awaiter(this, void 0, void 0, function* () {
161
+ try {
162
+ const doc = new model(data);
163
+ return yield doc.save({ session });
164
+ }
165
+ catch (error) {
166
+ console.error('Error al crear documento:', error);
167
+ throw error;
168
+ }
169
+ });
170
+ }
171
+ find(model, query, options) {
172
+ return __awaiter(this, void 0, void 0, function* () {
173
+ try {
174
+ let queryBuilder = model.find(query);
175
+ if (options === null || options === void 0 ? void 0 : options.limit)
176
+ queryBuilder = queryBuilder.limit(options.limit);
177
+ if (options === null || options === void 0 ? void 0 : options.skip)
178
+ queryBuilder = queryBuilder.skip(options.skip);
179
+ if (options === null || options === void 0 ? void 0 : options.sort)
180
+ queryBuilder = queryBuilder.sort(options.sort);
181
+ return yield queryBuilder;
182
+ }
183
+ catch (error) {
184
+ console.error('Error al obtener documentos:', error);
185
+ throw error;
186
+ }
187
+ });
188
+ }
189
+ findOne(model, query) {
190
+ return __awaiter(this, void 0, void 0, function* () {
191
+ try {
192
+ return yield model.findOne(query);
193
+ }
194
+ catch (error) {
195
+ console.error('Error al obtener un documento:', error);
196
+ throw error;
197
+ }
198
+ });
199
+ }
200
+ findById(model, id) {
201
+ return __awaiter(this, void 0, void 0, function* () {
202
+ try {
203
+ return yield model.findById(id);
204
+ }
205
+ catch (error) {
206
+ console.error('Error al obtener un documento:', error);
207
+ throw error;
208
+ }
209
+ });
210
+ }
211
+ update(model, query, updateData, session) {
212
+ return __awaiter(this, void 0, void 0, function* () {
213
+ try {
214
+ return yield model.findOneAndUpdate(query, updateData, { new: true, runValidators: false, session });
215
+ }
216
+ catch (error) {
217
+ console.error('Error al actualizar documento:', error);
218
+ throw error;
219
+ }
220
+ });
221
+ }
222
+ updateById(model, id, updateData, session) {
223
+ return __awaiter(this, void 0, void 0, function* () {
224
+ try {
225
+ return yield model.findOneAndUpdate({ _id: id }, updateData, { new: true, runValidators: false, session });
226
+ }
227
+ catch (error) {
228
+ console.error('Error al actualizar documento:', error);
229
+ throw error;
230
+ }
231
+ });
232
+ }
233
+ delete(model, query, session) {
234
+ return __awaiter(this, void 0, void 0, function* () {
235
+ try {
236
+ yield model.findOneAndDelete(query, { session });
237
+ return true;
238
+ }
239
+ catch (error) {
240
+ console.error('Error al eliminar documento:', error);
241
+ throw error;
242
+ }
243
+ });
244
+ }
245
+ deleteById(model, id, session) {
246
+ return __awaiter(this, void 0, void 0, function* () {
247
+ try {
248
+ yield model.findByIdAndDelete(id, { session });
249
+ return true;
250
+ }
251
+ catch (error) {
252
+ console.error('Error al eliminar documento:', error);
253
+ throw error;
254
+ }
255
+ });
256
+ }
257
+ findAllFromMultipleModels(models, filter) {
258
+ return __awaiter(this, void 0, void 0, function* () {
259
+ try {
260
+ const results = yield Promise.all(models.map((model) => model.find(filter).exec()));
261
+ return results.flat();
262
+ }
263
+ catch (error) {
264
+ console.error('Error al buscar documentos en múltiples colecciones:', error);
265
+ throw error;
266
+ }
267
+ });
268
+ }
269
+ aggregate(model, pipeline, options) {
270
+ return __awaiter(this, void 0, void 0, function* () {
271
+ try {
272
+ return yield model.aggregate(pipeline, options);
273
+ }
274
+ catch (error) {
275
+ console.error('Error al buscar documentos la coleccion:', error);
276
+ throw error;
277
+ }
278
+ });
279
+ }
280
+ }
281
+
282
+ class NoSQLConnectionManager {
283
+ static getInstance(type, credentials) {
284
+ switch (type) {
285
+ case exports.DBNoSQLType.MongoDB:
286
+ return new MongoDBConnector(credentials);
287
+ case exports.DBNoSQLType.Cassandra:
288
+ throw new Error(`Tipo de base de datos no soportado: ${type}`);
289
+ default:
290
+ throw new Error(`Tipo de base de datos no soportado: ${type}`);
291
+ }
292
+ }
293
+ }
294
+
295
+ class SqlConnector {
296
+ }
297
+
298
+ class DBError extends Error {
299
+ constructor(code, message, meta) {
300
+ super(message);
301
+ if (Error.captureStackTrace) {
302
+ Error.captureStackTrace(this, this.constructor);
303
+ }
304
+ this.name = 'DatabaseError';
305
+ this.code = code;
306
+ this.sqlState = meta === null || meta === void 0 ? void 0 : meta.sqlState;
307
+ this.errno = meta === null || meta === void 0 ? void 0 : meta.errno;
308
+ this.status = meta === null || meta === void 0 ? void 0 : meta.status;
309
+ }
310
+ }
311
+
312
+ class MySQLConnectionError {
313
+ constructor() { }
314
+ static handleMysqlConnectionError(error) {
315
+ if (error instanceof sequelize.ValidationError) {
316
+ throw new DBError('401', `Validation Error: [${error.message}]`);
317
+ }
318
+ else if (error instanceof sequelize.DatabaseError) {
319
+ throw new DBError('401', `Database Error: [${error.message}]`);
320
+ }
321
+ else if (error instanceof sequelize.AccessDeniedError) {
322
+ throw new DBError('403', `Forbidden: [${error.message}]`);
323
+ }
324
+ else {
325
+ throw new DBError('400', `Unable to connect to the database, ${error}`);
326
+ }
327
+ }
328
+ }
329
+
330
+ class SequelizeSqlConnector extends SqlConnector {
331
+ constructor(creds) {
332
+ var _a, _b;
333
+ super();
334
+ this.creds = creds;
335
+ this.sequelize = new sequelize.Sequelize(creds.database, creds.user || '', creds.password, {
336
+ host: creds.host,
337
+ port: creds.port,
338
+ dialect: (_a = creds.dialect) !== null && _a !== void 0 ? _a : 'mysql',
339
+ logging: (_b = creds.logging) !== null && _b !== void 0 ? _b : false,
340
+ });
341
+ }
342
+ connect() {
343
+ return __awaiter(this, void 0, void 0, function* () {
344
+ try {
345
+ yield this.sequelize.authenticate();
346
+ }
347
+ catch (error) {
348
+ MySQLConnectionError.handleMysqlConnectionError(error);
349
+ }
350
+ });
351
+ }
352
+ disconnect() {
353
+ return __awaiter(this, void 0, void 0, function* () {
354
+ yield this.sequelize.close();
355
+ });
356
+ }
357
+ isConnected() {
358
+ return __awaiter(this, void 0, void 0, function* () {
359
+ try {
360
+ yield this.sequelize.query('SELECT 1', { raw: true });
361
+ return true;
362
+ }
363
+ catch (error) {
364
+ return false;
365
+ }
366
+ });
367
+ }
368
+ getSequelize() {
369
+ return this.sequelize;
370
+ }
371
+ getModel(name) {
372
+ if (!this.sequelize.isDefined(name)) {
373
+ throw new Error(`Modelo no definido: ${name}`);
374
+ }
375
+ return this.sequelize.model(name);
376
+ }
377
+ select(entity, options) {
378
+ return __awaiter(this, void 0, void 0, function* () {
379
+ try {
380
+ const model = this.getModel(entity);
381
+ const records = yield model.findAll(options);
382
+ return records;
383
+ }
384
+ catch (error) {
385
+ console.error(error);
386
+ throw this.createDatabaseError(error);
387
+ }
388
+ });
389
+ }
390
+ insert(entity, values, options) {
391
+ return __awaiter(this, void 0, void 0, function* () {
392
+ try {
393
+ const model = this.getModel(entity);
394
+ const instance = yield model.create(values, options);
395
+ return instance;
396
+ }
397
+ catch (error) {
398
+ console.error(error);
399
+ throw this.createDatabaseError(error);
400
+ }
401
+ });
402
+ }
403
+ update(entity, filter, data, options) {
404
+ return __awaiter(this, void 0, void 0, function* () {
405
+ try {
406
+ const model = this.getModel(entity);
407
+ const updateOpts = Object.assign(Object.assign({}, options), { where: filter });
408
+ const [count] = yield model.update(data, updateOpts);
409
+ return count;
410
+ }
411
+ catch (error) {
412
+ console.error(error);
413
+ throw this.createDatabaseError(error);
414
+ }
415
+ });
416
+ }
417
+ delete(entity, filter, options) {
418
+ return __awaiter(this, void 0, void 0, function* () {
419
+ try {
420
+ const model = this.getModel(entity);
421
+ const destroyOpts = Object.assign({ where: filter }, options);
422
+ const deletedCount = yield model.destroy(destroyOpts);
423
+ return deletedCount;
424
+ }
425
+ catch (error) {
426
+ console.error(error);
427
+ throw this.createDatabaseError(error);
428
+ }
429
+ });
430
+ }
431
+ query(sql, options) {
432
+ return __awaiter(this, void 0, void 0, function* () {
433
+ try {
434
+ const results = yield this.sequelize.query(sql, options);
435
+ return results;
436
+ }
437
+ catch (error) {
438
+ console.error(error);
439
+ throw this.createDatabaseError(error);
440
+ }
441
+ });
442
+ }
443
+ withTransaction(fn) {
444
+ return __awaiter(this, void 0, void 0, function* () {
445
+ const tx = yield this.sequelize.transaction();
446
+ try {
447
+ const result = yield fn(tx);
448
+ yield tx.commit();
449
+ return result;
450
+ }
451
+ catch (error) {
452
+ console.error(error);
453
+ yield tx.rollback();
454
+ throw this.createDatabaseError(error);
455
+ }
456
+ });
457
+ }
458
+ createDatabaseError(err) {
459
+ var _a, _b, _c;
460
+ const SQLSTATE_CODE_MAP = {
461
+ '42S02': 'DB_TABLE_NOT_FOUND',
462
+ '42S22': 'DB_COLUMN_NOT_FOUND',
463
+ '23000': 'DB_INTEGRITY_ERROR',
464
+ };
465
+ const source = (_a = err.original) !== null && _a !== void 0 ? _a : err;
466
+ const sqlState = source.sqlState;
467
+ const errno = source.errno;
468
+ const rawMsg = (_c = (_b = source.sqlMessage) !== null && _b !== void 0 ? _b : err.message) !== null && _c !== void 0 ? _c : String(err);
469
+ let code;
470
+ try {
471
+ const parsed = JSON.parse(rawMsg);
472
+ code = parsed.code || rawMsg;
473
+ }
474
+ catch (_d) {
475
+ code = sqlState && SQLSTATE_CODE_MAP[sqlState]
476
+ ? SQLSTATE_CODE_MAP[sqlState]
477
+ : sqlState == '45000' ? rawMsg : 'DB_UNKNOWN_ERROR';
478
+ }
479
+ const message = `DatabaseError [${code}] (SQLSTATE=${sqlState}, errno=${errno}): ${rawMsg}`;
480
+ return new DBError(code, message, { sqlState, errno });
481
+ }
482
+ }
483
+
484
+ exports.DBSQLType = void 0;
485
+ (function (DBSQLType) {
486
+ DBSQLType["SQLServer"] = "SQLServer";
487
+ DBSQLType["MYSQL"] = "MYSQL";
488
+ })(exports.DBSQLType || (exports.DBSQLType = {}));
489
+
490
+ class SQLConnectionManager {
491
+ static getInstance(type, credentials) {
492
+ switch (type) {
493
+ case exports.DBSQLType.MYSQL:
494
+ return new SequelizeSqlConnector(credentials);
495
+ default:
496
+ throw new Error(`Tipo de base de datos no soportado: ${type}`);
497
+ }
498
+ }
499
+ }
500
+
501
+ class DBConnector {
502
+ constructor() {
503
+ this.connection = null;
504
+ this.sqlConnection = null;
505
+ this.credentials = null;
506
+ this.dbType = null;
507
+ }
508
+ static getInstance() {
509
+ if (!DBConnector.instance) {
510
+ DBConnector.instance = new DBConnector();
511
+ }
512
+ return DBConnector.instance;
513
+ }
514
+ createConnection(type, credentials) {
515
+ return __awaiter(this, void 0, void 0, function* () {
516
+ if (this.connection && this.dbType === type && JSON.stringify(this.credentials) === JSON.stringify(credentials)) {
517
+ return this.sqlConnection;
518
+ }
519
+ if (this.connection) {
520
+ yield this.closeConnection();
521
+ }
522
+ if (Object.values(exports.DBNoSQLType).includes(type)) {
523
+ this.connection = NoSQLConnectionManager.getInstance(type, credentials);
524
+ }
525
+ else if (Object.values(exports.DBSQLType).includes(type)) {
526
+ this.connection = SQLConnectionManager.getInstance(type, credentials);
527
+ }
528
+ else {
529
+ throw new Error(`Unsupported database type: ${type}`);
530
+ }
531
+ yield this.connection.connect();
532
+ this.credentials = credentials;
533
+ this.dbType = type;
534
+ return this.connection;
535
+ });
536
+ }
537
+ getConnection() {
538
+ return this.connection;
539
+ }
540
+ closeConnection() {
541
+ return __awaiter(this, void 0, void 0, function* () {
542
+ if (this.connection) {
543
+ yield this.connection.disconnect();
544
+ this.connection = null;
545
+ this.credentials = null;
546
+ this.dbType = null;
547
+ }
548
+ });
549
+ }
550
+ getEngine(type, credentials) {
551
+ try {
552
+ if (Object.values(exports.DBNoSQLType).includes(type)) {
553
+ this.connection = NoSQLConnectionManager.getInstance(type, credentials);
554
+ }
555
+ else if (Object.values(exports.DBSQLType).includes(type)) {
556
+ this.connection = SQLConnectionManager.getInstance(type, credentials);
557
+ }
558
+ else {
559
+ throw new Error(`Unsupported database type: ${type}`);
560
+ }
561
+ return this.connection;
562
+ }
563
+ catch (error) {
564
+ throw error;
565
+ }
566
+ }
567
+ }
568
+ DBConnector.instance = null;
569
+
570
+ Object.defineProperty(exports, "Document", {
571
+ enumerable: true,
572
+ get: function () { return mongoose.Document; }
573
+ });
574
+ Object.defineProperty(exports, "Model", {
575
+ enumerable: true,
576
+ get: function () { return mongoose.Model; }
577
+ });
578
+ Object.defineProperty(exports, "Schema", {
579
+ enumerable: true,
580
+ get: function () { return mongoose.Schema; }
581
+ });
582
+ Object.defineProperty(exports, "DataTypes", {
583
+ enumerable: true,
584
+ get: function () { return sequelize.DataTypes; }
585
+ });
586
+ Object.defineProperty(exports, "ModelSequelize", {
587
+ enumerable: true,
588
+ get: function () { return sequelize.Model; }
589
+ });
590
+ Object.defineProperty(exports, "Op", {
591
+ enumerable: true,
592
+ get: function () { return sequelize.Op; }
593
+ });
594
+ Object.defineProperty(exports, "QueryTypes", {
595
+ enumerable: true,
596
+ get: function () { return sequelize.QueryTypes; }
597
+ });
598
+ Object.defineProperty(exports, "Sequelize", {
599
+ enumerable: true,
600
+ get: function () { return sequelize.Sequelize; }
601
+ });
602
+ Object.defineProperty(exports, "Transaction", {
603
+ enumerable: true,
604
+ get: function () { return sequelize.Transaction; }
605
+ });
606
+ Object.defineProperty(exports, "fn", {
607
+ enumerable: true,
608
+ get: function () { return sequelize.fn; }
609
+ });
610
+ exports.DBConnector = DBConnector;
611
+ exports.DBError = DBError;
612
+ exports.MySQLConnectionError = MySQLConnectionError;
613
+ exports.NoSQLConnector = NoSQLConnector;
614
+ exports.SqlConnector = SqlConnector;
File without changes
@@ -0,0 +1,30 @@
1
+ import mongoose, { Document, Model, Connection, ClientSession, AggregateOptions } from "mongoose";
2
+ import { CredentialsConnection } from "../types/CredentialsConnection";
3
+ import { NoSQLOptions } from "../types/NoSQLOptions";
4
+ import { NoSQLConnector } from "../abstract/NoSQLConnector";
5
+ export declare class MongoDBConnector extends NoSQLConnector {
6
+ private mongooseConnection;
7
+ private currentSession;
8
+ constructor(param: CredentialsConnection);
9
+ connect(): Promise<void>;
10
+ disconnect(): Promise<void>;
11
+ getConnection(): Connection;
12
+ isConnected(): boolean;
13
+ state(): number;
14
+ getCredentials(): CredentialsConnection;
15
+ getProvider(): String;
16
+ startSession(): Promise<ClientSession>;
17
+ commitTransaction(): Promise<void>;
18
+ abortTransaction(): Promise<void>;
19
+ withTransaction<T>(transactionFn: (session: ClientSession) => Promise<T>): Promise<T>;
20
+ create<T extends Document>(model: Model<T>, data: Partial<T>, session?: ClientSession): Promise<T>;
21
+ find<T extends Document>(model: Model<T>, query: object, options?: NoSQLOptions): Promise<T[]>;
22
+ findOne<T extends Document>(model: Model<T>, query: object): Promise<T | null>;
23
+ findById<T extends Document>(model: Model<T>, id: string): Promise<T | null>;
24
+ update<T extends Document>(model: Model<T>, query: object, updateData: object, session?: ClientSession): Promise<T | null>;
25
+ updateById<T extends Document>(model: Model<T>, id: string, updateData: object, session?: ClientSession): Promise<T | null>;
26
+ delete<T extends Document>(model: Model<T>, query: object, session?: ClientSession): Promise<boolean>;
27
+ deleteById<T extends Document>(model: Model<T>, id: string, session?: ClientSession): Promise<boolean>;
28
+ findAllFromMultipleModels<U extends Document>(models: Array<Model<U>>, filter: object): Promise<U[]>;
29
+ aggregate<T extends Document>(model: Model<T>, pipeline: mongoose.PipelineStage[], options?: AggregateOptions): Promise<any[]>;
30
+ }
@@ -0,0 +1,28 @@
1
+ import { Sequelize, Model, FindOptions, CreateOptions, DestroyOptions, UpdateOptions, WhereOptions, CreationAttributes, QueryOptions, InferAttributes, Transaction } from 'sequelize';
2
+ import { SqlConnector } from '../abstract/SQLConnector';
3
+ import { CredentialsConnection } from '../types/CredentialsConnection';
4
+ export declare class SequelizeSqlConnector extends SqlConnector {
5
+ private readonly creds;
6
+ private readonly sequelize;
7
+ constructor(creds: CredentialsConnection);
8
+ connect(): Promise<void>;
9
+ disconnect(): Promise<void>;
10
+ isConnected(): Promise<boolean>;
11
+ getSequelize(): Sequelize;
12
+ private getModel;
13
+ select<T extends Model<InferAttributes<T>>, O extends FindOptions<InferAttributes<T>> = FindOptions<InferAttributes<T>>>(entity: string, options?: O & {
14
+ where?: WhereOptions<InferAttributes<T>>;
15
+ }): Promise<T[]>;
16
+ insert<T extends Model<InferAttributes<T>>, O extends CreateOptions<InferAttributes<T>> = CreateOptions<InferAttributes<T>>>(entity: string, values: CreationAttributes<T>, options?: O): Promise<O extends {
17
+ returning: false;
18
+ } | {
19
+ ignoreDuplicates: true;
20
+ } ? void : T>;
21
+ update<T extends Model<InferAttributes<T>>, O extends UpdateOptions<InferAttributes<T>> = UpdateOptions<InferAttributes<T>>>(entity: string, filter: WhereOptions<InferAttributes<T>>, data: Partial<InferAttributes<T>>, options?: O & {
22
+ where?: WhereOptions<InferAttributes<T>>;
23
+ }): Promise<number>;
24
+ delete<T extends Model<InferAttributes<T>>, O extends DestroyOptions<InferAttributes<T>> = DestroyOptions<InferAttributes<T>>>(entity: string, filter: WhereOptions<InferAttributes<T>>, options?: O): Promise<number>;
25
+ query<T>(sql: string, options?: QueryOptions): Promise<T[]>;
26
+ withTransaction<T>(fn: (tx: Transaction) => Promise<T>): Promise<T>;
27
+ private createDatabaseError;
28
+ }
@@ -0,0 +1,18 @@
1
+ import { NoSQLConnector } from "./abstract/NoSQLConnector";
2
+ import { SqlConnector } from "./abstract/SQLConnector";
3
+ import { CredentialsConnection } from "./types/CredentialsConnection";
4
+ import { DBNoSQLType } from "./types/DBNoSQLTypes";
5
+ import { DBSQLType } from "./types/DBSQLTypes";
6
+ export declare class DBConnector {
7
+ private static instance;
8
+ private connection;
9
+ private sqlConnection;
10
+ private credentials;
11
+ private dbType;
12
+ constructor();
13
+ static getInstance(): DBConnector;
14
+ createConnection<T extends SqlConnector | NoSQLConnector>(type: DBSQLType | DBNoSQLType, credentials: CredentialsConnection): Promise<T>;
15
+ getConnection<T extends NoSQLConnector | SqlConnector>(): T | null;
16
+ closeConnection(): Promise<void>;
17
+ getEngine<T extends NoSQLConnector | SqlConnector>(type: DBNoSQLType | DBSQLType, credentials: CredentialsConnection): T;
18
+ }