Skip to content

Commit 964316b

Browse files
committed
added conditional db connection.
1 parent 6ab7df7 commit 964316b

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ src
22
test
33
.github
44
.gitignore
5+
TODO.md

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"url": "https://github.com/ariflogs/SQL-to-NoSQL"
1111
},
1212
"homepage": "https://github.com/ariflogs/SQL-to-NoSQL",
13-
"main": "dist/index.js",
13+
"main": "dist/index.mjs",
1414
"scripts": {
1515
"dev": "tsc -w",
16-
"start": "tsc && node dist/index.js",
16+
"start": "tsc && node dist/index.mjs",
1717
"build": "npx prettier . --check && tsc",
1818
"test": "echo \"Error: no test specified\" && exit 1",
1919
"pretty": "npx prettier . --write"
@@ -37,4 +37,4 @@
3737
"dependencies": {
3838
"mongodb": "^6.1.0"
3939
}
40-
}
40+
}

src/index.mts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export class SqlToNoSql {
2121
}
2222

2323
const q = parseQuery(query);
24-
this.client = await connect(this.config.connection);
2524

2625
const filters: {
2726
[key: string]: {
@@ -47,9 +46,14 @@ export class SqlToNoSql {
4746
};
4847

4948
try {
50-
await this.client.connect();
49+
if (!this.client) {
50+
this.client = await connect(this.config.connection);
51+
await this.client.connect();
52+
}
53+
5154
const db = this.client.db();
5255
const collection = db.collection(mongoQuery.collection);
56+
5357
const data = await collection[mongoQuery[q.command]](
5458
mongoQuery.query,
5559
).toArray();

0 commit comments

Comments
 (0)