@hemia/db-connector 0.0.2 → 0.0.3

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.
@@ -1,5 +1,5 @@
1
- import mongoose from 'mongoose';
2
- export { Document, Model, Schema } from 'mongoose';
1
+ import mongoose__default from 'mongoose';
2
+ export * from 'mongoose';
3
3
  import { ValidationError, DatabaseError, AccessDeniedError, Sequelize } from 'sequelize';
4
4
  export { DataTypes, Model as ModelSequelize, Op, QueryTypes, Sequelize, Transaction, fn } from 'sequelize';
5
5
 
@@ -65,7 +65,7 @@ class MongoDBConnector extends NoSQLConnector {
65
65
  this.currentSession = null;
66
66
  this.config = param;
67
67
  this.provider = DBNoSQLType.MongoDB;
68
- this.mongooseConnection = mongoose.connection;
68
+ this.mongooseConnection = mongoose__default.connection;
69
69
  }
70
70
  connect() {
71
71
  return __awaiter(this, void 0, void 0, function* () {
@@ -73,13 +73,13 @@ class MongoDBConnector extends NoSQLConnector {
73
73
  if (this.mongooseConnection.readyState === 1) {
74
74
  return;
75
75
  }
76
- yield mongoose.connect(`mongodb://${this.config.host}:${this.config.port || 27017}`, {
76
+ yield mongoose__default.connect(`mongodb://${this.config.host}:${this.config.port || 27017}`, {
77
77
  user: this.config.user,
78
78
  pass: this.config.password,
79
79
  dbName: this.config.database,
80
80
  authSource: this.config.authSource
81
81
  });
82
- this.mongooseConnection = mongoose.connection;
82
+ this.mongooseConnection = mongoose__default.connection;
83
83
  console.log('Connected to MongoDB');
84
84
  }
85
85
  catch (error) {
@@ -278,6 +278,17 @@ class MongoDBConnector extends NoSQLConnector {
278
278
  }
279
279
  });
280
280
  }
281
+ executeWithModel(model, operation, session) {
282
+ return __awaiter(this, void 0, void 0, function* () {
283
+ try {
284
+ return yield operation(model, session);
285
+ }
286
+ catch (error) {
287
+ console.error('Error en operación personalizada:', error);
288
+ throw error;
289
+ }
290
+ });
291
+ }
281
292
  }
282
293
 
283
294
  class NoSQLConnectionManager {
@@ -278,6 +278,17 @@ class MongoDBConnector extends NoSQLConnector {
278
278
  }
279
279
  });
280
280
  }
281
+ executeWithModel(model, operation, session) {
282
+ return __awaiter(this, void 0, void 0, function* () {
283
+ try {
284
+ return yield operation(model, session);
285
+ }
286
+ catch (error) {
287
+ console.error('Error en operación personalizada:', error);
288
+ throw error;
289
+ }
290
+ });
291
+ }
281
292
  }
282
293
 
283
294
  class NoSQLConnectionManager {
@@ -568,18 +579,6 @@ class DBConnector {
568
579
  }
569
580
  DBConnector.instance = null;
570
581
 
571
- Object.defineProperty(exports, "Document", {
572
- enumerable: true,
573
- get: function () { return mongoose.Document; }
574
- });
575
- Object.defineProperty(exports, "Model", {
576
- enumerable: true,
577
- get: function () { return mongoose.Model; }
578
- });
579
- Object.defineProperty(exports, "Schema", {
580
- enumerable: true,
581
- get: function () { return mongoose.Schema; }
582
- });
583
582
  Object.defineProperty(exports, "DataTypes", {
584
583
  enumerable: true,
585
584
  get: function () { return sequelize.DataTypes; }
@@ -613,3 +612,9 @@ exports.DBError = DBError;
613
612
  exports.MySQLConnectionError = MySQLConnectionError;
614
613
  exports.NoSQLConnector = NoSQLConnector;
615
614
  exports.SqlConnector = SqlConnector;
615
+ Object.keys(mongoose).forEach(function (k) {
616
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
617
+ enumerable: true,
618
+ get: function () { return mongoose[k]; }
619
+ });
620
+ });
@@ -27,4 +27,5 @@ export declare class MongoDBConnector extends NoSQLConnector {
27
27
  deleteById<T extends Document>(model: Model<T>, id: string, session?: ClientSession): Promise<boolean>;
28
28
  findAllFromMultipleModels<U extends Document>(models: Array<Model<U>>, filter: object): Promise<U[]>;
29
29
  aggregate<T extends Document>(model: Model<T>, pipeline: mongoose.PipelineStage[], options?: AggregateOptions): Promise<any[]>;
30
+ executeWithModel<T extends Document, R>(model: Model<T>, operation: (model: Model<T>, session?: ClientSession) => Promise<R>, session?: ClientSession): Promise<R>;
30
31
  }
@@ -37,4 +37,5 @@ export declare abstract class NoSQLConnector {
37
37
  abstract findAllFromMultipleModels<U extends Document>(models: Array<Model<U>>, filter: object): Promise<U[]>;
38
38
  abstract aggregate<T>(model: any, pipeline: PipelineStage[]): Promise<any[]>;
39
39
  abstract aggregate<T extends Document>(model: Model<T>, pipeline: PipelineStage[], options?: AggregateOptions): Promise<any[]>;
40
+ abstract executeWithModel<T extends Document, R>(model: Model<T>, operation: (model: Model<T>, session?: ClientSession) => Promise<R>, session?: ClientSession): Promise<R>;
40
41
  }
@@ -7,7 +7,7 @@ export { DBNoSQLType } from "./types/DBNoSQLTypes";
7
7
  export { NoSQLConnector } from "./abstract/NoSQLConnector";
8
8
  export { SqlConnector, Filter } from "./abstract/SQLConnector";
9
9
  export { NoSQLOptions } from "./types/NoSQLOptions";
10
- export { Document, Model, Schema, UpdateQuery, FilterQuery, ClientSession, PipelineStage, SortOrder, AggregateOptions } from 'mongoose';
10
+ export * from 'mongoose';
11
11
  export { Model as ModelSequelize, Sequelize, DataTypes, CreateOptions, UpdateOptions, DestroyOptions, FindOptions, Attributes, WhereOptions, QueryOptions, InferAttributes, CreationAttributes, InferCreationAttributes, QueryTypes, QueryOptionsWithType, Transaction, Op, fn } from "sequelize";
12
12
  export { DBError } from "./errors/DBError";
13
13
  export { MySQLConnectionError } from "./errors/MySQLConnectionError";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hemia/db-connector",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Hemia Database Conector",
5
5
  "main": "dist/hemia-db-connector.js",
6
6
  "module": "dist/hemia-db-connector.esm.js",