@superhero/db 0.5.2 → 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.
@@ -20,6 +20,11 @@ class AdapterMySql
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) =>
@@ -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
- return await this.adaptor.query(query, ...ctx)
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
- query = await this.getQuery(file),
60
- response = await transaction.query(query, ...ctx)
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.5.2",
3
+ "version": "1.0.0",
4
4
  "description": "Db interaction, designed to separate queries from the source code",
5
- "repository": "git@github.com:superhero/js.db.git",
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": {