@platformatic/sql-mapper 3.15.0 → 3.17.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/lib/entity.js +4 -0
- package/lib/telemetry.js +13 -8
- package/package.json +3 -3
package/lib/entity.js
CHANGED
|
@@ -43,6 +43,10 @@ function createMapper (
|
|
|
43
43
|
let db = opts?.tx || defaultDb
|
|
44
44
|
if (opts?.ctx?.app?.openTelemetry && opts?.ctx?.reply?.request) {
|
|
45
45
|
const req = opts.ctx.reply.request
|
|
46
|
+
if (db !== defaultDb && !db.connectionInfo) {
|
|
47
|
+
const { connectionInfo } = defaultDb
|
|
48
|
+
db.connectionInfo = connectionInfo
|
|
49
|
+
}
|
|
46
50
|
db = wrapDB(opts.ctx.app, db, req)
|
|
47
51
|
}
|
|
48
52
|
return db
|
package/lib/telemetry.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export function wrapQuery (app, db, request) {
|
|
2
2
|
const { startSpan, endSpan, SpanKind } = app.openTelemetry
|
|
3
|
+
// Bind the query method to preserve the correct 'this' context for private class fields
|
|
4
|
+
const originalQuery = db.query.bind(db)
|
|
3
5
|
async function wrappedQuery () {
|
|
4
6
|
const query = arguments[0]
|
|
5
7
|
const connectionInfo = db.connectionInfo
|
|
@@ -44,7 +46,8 @@ export function wrapQuery (app, db, request) {
|
|
|
44
46
|
let span
|
|
45
47
|
try {
|
|
46
48
|
span = startSpan(spanName, ctx, telemetryAttributes, SpanKind.CLIENT)
|
|
47
|
-
|
|
49
|
+
// Call the bound query method with the original arguments
|
|
50
|
+
const result = await originalQuery(...arguments)
|
|
48
51
|
endSpan(span)
|
|
49
52
|
return result
|
|
50
53
|
} catch (err) /* istanbul ignore next */ {
|
|
@@ -59,13 +62,15 @@ export function wrapDB (app, db, request) {
|
|
|
59
62
|
const newDb = Object.create(db)
|
|
60
63
|
const connectionInfo = db.connectionInfo
|
|
61
64
|
newDb.query = wrapQuery(app, db, request)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
db.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
if (typeof db.tx === 'function') {
|
|
66
|
+
newDb.tx = function wrappedTx (func) {
|
|
67
|
+
return db.tx(txDb => {
|
|
68
|
+
txDb.connectionInfo = connectionInfo
|
|
69
|
+
const _newDb = Object.create(txDb)
|
|
70
|
+
_newDb.query = wrapQuery(app, txDb, request)
|
|
71
|
+
return func(_newDb)
|
|
72
|
+
})
|
|
73
|
+
}
|
|
69
74
|
}
|
|
70
75
|
return newDb
|
|
71
76
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/sql-mapper",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.17.0",
|
|
4
4
|
"description": "A data mapper utility for SQL databases",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"camelcase": "^6.3.0",
|
|
36
36
|
"fastify-plugin": "^5.0.0",
|
|
37
37
|
"inflected": "^2.1.0",
|
|
38
|
-
"@platformatic/foundation": "3.
|
|
39
|
-
"@platformatic/telemetry": "3.
|
|
38
|
+
"@platformatic/foundation": "3.17.0",
|
|
39
|
+
"@platformatic/telemetry": "3.17.0"
|
|
40
40
|
},
|
|
41
41
|
"tsd": {
|
|
42
42
|
"directory": "test/types"
|