@superhero/db 0.5.1 → 1.0.0
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/adapter/mysql/index.js +5 -0
- package/adapter/mysql2/index.js +6 -1
- package/index.js +15 -4
- package/package.json +5 -2
package/adapter/mysql/index.js
CHANGED
package/adapter/mysql2/index.js
CHANGED
|
@@ -12,7 +12,7 @@ class AdapterMySql2
|
|
|
12
12
|
const resolve = (accept, reject, i = 0) =>
|
|
13
13
|
this.pool.query(query, ctx, (error, response) =>
|
|
14
14
|
error
|
|
15
|
-
?
|
|
15
|
+
? ['ETIMEDOUT', 'ECONNREFUSED', 'ECONNRESET'].includes(error.code) && i < 3
|
|
16
16
|
? resolve(accept, reject, ++i)
|
|
17
17
|
: reject(error)
|
|
18
18
|
: accept(response))
|
|
@@ -20,6 +20,11 @@ class AdapterMySql2
|
|
|
20
20
|
return new Promise(resolve)
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
getFormattedQuery(query, ...ctx)
|
|
24
|
+
{
|
|
25
|
+
return this.pool.format(query, ...ctx)
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
getConnection()
|
|
24
29
|
{
|
|
25
30
|
const resolve = (accept, reject, i = 0) =>
|
package/index.js
CHANGED
|
@@ -29,8 +29,19 @@ class Db
|
|
|
29
29
|
{
|
|
30
30
|
query = query.replace('?%s', ctx.shift())
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
|
|
33
|
+
try
|
|
34
|
+
{
|
|
35
|
+
return await this.adaptor.query(query, ...ctx)
|
|
36
|
+
}
|
|
37
|
+
catch(reason)
|
|
38
|
+
{
|
|
39
|
+
const error = new Error(`DB query '${file}' failed`)
|
|
40
|
+
error.code = 'DB_QUERY_ERROR'
|
|
41
|
+
error.query = this.adaptor.getFormattedQuery?.(query, ...ctx) ?? query
|
|
42
|
+
error.cause = reason
|
|
43
|
+
throw error
|
|
44
|
+
}
|
|
34
45
|
}
|
|
35
46
|
|
|
36
47
|
async formatQuery(file, formatCtx, sqlCtx)
|
|
@@ -56,8 +67,8 @@ class Db
|
|
|
56
67
|
: async (file, ...ctx) =>
|
|
57
68
|
{
|
|
58
69
|
const
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
query = await this.getQuery(file),
|
|
71
|
+
response = await transaction.query(query, ...ctx)
|
|
61
72
|
|
|
62
73
|
return response
|
|
63
74
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superhero/db",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Db interaction, designed to separate queries from the source code",
|
|
5
|
-
"repository":
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+ssh://git@github.com/superhero/js.db.git"
|
|
8
|
+
},
|
|
6
9
|
"main": "index.js",
|
|
7
10
|
"license": "MIT",
|
|
8
11
|
"author": {
|