@tomsd/mongodbclient 2.7.4 → 2.7.7

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.
@@ -24,9 +24,9 @@ export declare class MClient {
24
24
  get collection(): string;
25
25
  connect(): Promise<any>;
26
26
  protected getConnected(): Promise<any>;
27
- upsert(pobj: any): Promise<unknown>;
28
- read(condition?: any, opt?: any): Promise<unknown>;
29
- distinct(key: string, condition?: any): Promise<unknown>;
27
+ upsert(pobj: any): Promise<any>;
28
+ read(condition?: any, opt?: any): Promise<any>;
29
+ distinct(key: string, condition?: any): Promise<any>;
30
30
  remove(condition: any): Promise<unknown>;
31
31
  stats(): Promise<any>;
32
32
  count(condition?: any): Promise<number>;
@@ -67,56 +67,49 @@ class MClient {
67
67
  });
68
68
  }
69
69
  upsert(pobj) {
70
- const that = this;
71
- pobj._id = "_id" in pobj ? pobj._id : uuid_1.v4();
72
- return new Promise(function (resolve, reject) {
73
- that.getConnected()
74
- .then(function (conn) {
75
- conn.collection.updateOne({ _id: pobj._id }, { $set: pobj }, { upsert: true, writeConcern: { w: 1 } })
76
- .then(function (r) {
77
- conn.client.close();
78
- resolve(r);
79
- })
80
- .catch(function (e) {
81
- conn.client.close();
82
- reject(e);
83
- });
84
- }, reject);
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const savingObj = Object.assign({ _id: uuid_1.v4() }, pobj);
72
+ const connection = yield this.getConnected();
73
+ try {
74
+ return yield connection.collection.updateOne({ _id: savingObj._id }, { $set: savingObj }, { upsert: true, writeConcern: { w: 1 } });
75
+ }
76
+ catch (e) {
77
+ throw e;
78
+ }
79
+ finally {
80
+ connection.client.close();
81
+ }
85
82
  });
86
83
  }
87
84
  read(condition = {}, opt) {
88
- const that = this;
89
- return new Promise(function (resolve, reject) {
90
- that.getConnected()
91
- .then(function (conn) {
92
- conn.collection.find(condition, opt)
93
- .toArray()
94
- .then(function (docs) {
95
- conn.client.close();
96
- resolve(docs);
97
- })
98
- .catch(function (e) {
99
- conn.client.close();
100
- reject(e);
101
- });
102
- });
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ const connection = yield this.getConnected();
87
+ try {
88
+ return yield connection
89
+ .collection
90
+ .find(condition, opt)
91
+ .toArray();
92
+ }
93
+ catch (e) {
94
+ throw e;
95
+ }
96
+ finally {
97
+ connection.client.close();
98
+ }
103
99
  });
104
100
  }
105
101
  distinct(key, condition = {}) {
106
- const that = this;
107
- return new Promise(function (resolve, reject) {
108
- that.getConnected()
109
- .then(function (conn) {
110
- conn.collection.distinct(key, condition)
111
- .then(function (values) {
112
- conn.client.close();
113
- resolve(values);
114
- })
115
- .catch(function (e) {
116
- conn.client.close();
117
- reject(e);
118
- });
119
- });
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ const connection = yield this.getConnected();
104
+ try {
105
+ return yield connection.collection.distinct(key, condition);
106
+ }
107
+ catch (e) {
108
+ throw e;
109
+ }
110
+ finally {
111
+ connection.client.close();
112
+ }
120
113
  });
121
114
  }
122
115
  remove(condition) {
@@ -24,9 +24,9 @@ export declare class MClient {
24
24
  get collection(): string;
25
25
  connect(): Promise<any>;
26
26
  protected getConnected(): Promise<any>;
27
- upsert(pobj: any): Promise<unknown>;
28
- read(condition?: any, opt?: any): Promise<unknown>;
29
- distinct(key: string, condition?: any): Promise<unknown>;
27
+ upsert(pobj: any): Promise<any>;
28
+ read(condition?: any, opt?: any): Promise<any>;
29
+ distinct(key: string, condition?: any): Promise<any>;
30
30
  remove(condition: any): Promise<unknown>;
31
31
  stats(): Promise<any>;
32
32
  count(condition?: any): Promise<number>;
@@ -63,56 +63,49 @@ export class MClient {
63
63
  });
64
64
  }
65
65
  upsert(pobj) {
66
- const that = this;
67
- pobj._id = "_id" in pobj ? pobj._id : uuidv4();
68
- return new Promise(function (resolve, reject) {
69
- that.getConnected()
70
- .then(function (conn) {
71
- conn.collection.updateOne({ _id: pobj._id }, { $set: pobj }, { upsert: true, writeConcern: { w: 1 } })
72
- .then(function (r) {
73
- conn.client.close();
74
- resolve(r);
75
- })
76
- .catch(function (e) {
77
- conn.client.close();
78
- reject(e);
79
- });
80
- }, reject);
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const savingObj = Object.assign({ _id: uuidv4() }, pobj);
68
+ const connection = yield this.getConnected();
69
+ try {
70
+ return yield connection.collection.updateOne({ _id: savingObj._id }, { $set: savingObj }, { upsert: true, writeConcern: { w: 1 } });
71
+ }
72
+ catch (e) {
73
+ throw e;
74
+ }
75
+ finally {
76
+ connection.client.close();
77
+ }
81
78
  });
82
79
  }
83
80
  read(condition = {}, opt) {
84
- const that = this;
85
- return new Promise(function (resolve, reject) {
86
- that.getConnected()
87
- .then(function (conn) {
88
- conn.collection.find(condition, opt)
89
- .toArray()
90
- .then(function (docs) {
91
- conn.client.close();
92
- resolve(docs);
93
- })
94
- .catch(function (e) {
95
- conn.client.close();
96
- reject(e);
97
- });
98
- });
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ const connection = yield this.getConnected();
83
+ try {
84
+ return yield connection
85
+ .collection
86
+ .find(condition, opt)
87
+ .toArray();
88
+ }
89
+ catch (e) {
90
+ throw e;
91
+ }
92
+ finally {
93
+ connection.client.close();
94
+ }
99
95
  });
100
96
  }
101
97
  distinct(key, condition = {}) {
102
- const that = this;
103
- return new Promise(function (resolve, reject) {
104
- that.getConnected()
105
- .then(function (conn) {
106
- conn.collection.distinct(key, condition)
107
- .then(function (values) {
108
- conn.client.close();
109
- resolve(values);
110
- })
111
- .catch(function (e) {
112
- conn.client.close();
113
- reject(e);
114
- });
115
- });
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ const connection = yield this.getConnected();
100
+ try {
101
+ return yield connection.collection.distinct(key, condition);
102
+ }
103
+ catch (e) {
104
+ throw e;
105
+ }
106
+ finally {
107
+ connection.client.close();
108
+ }
116
109
  });
117
110
  }
118
111
  remove(condition) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomsd/mongodbclient",
3
- "version": "2.7.4",
3
+ "version": "2.7.7",
4
4
  "description": "",
5
5
  "main": "dist/cjs/mongodbclient.js",
6
6
  "module": "dist/esm/mongodbclient.js",