Skip to content

Commit b369e1e

Browse files
committed
Rename scope to transact
1 parent 12e5e01 commit b369e1e

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

plugin.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const fp = require('fastify-plugin')
44
const oracledb = require('oracledb')
55

6-
function executionScope (pool, fn, cb) {
6+
function transactScope (pool, fn, cb) {
77
pool.getConnection(function (err, conn) {
88
if (err) return cb(err)
99

@@ -34,13 +34,13 @@ function executionScope (pool, fn, cb) {
3434
})
3535
}
3636

37-
function scope (fn, cb) {
37+
function transact (fn, cb) {
3838
if (cb && typeof cb === 'function') {
39-
return executionScope(this, fn, cb)
39+
return transactScope(this, fn, cb)
4040
}
4141

4242
return new Promise((resolve, reject) => {
43-
executionScope(this, fn, function (err, res) {
43+
transactScope(this, fn, function (err, res) {
4444
if (err) { return reject(err) }
4545
return resolve(res)
4646
})
@@ -51,7 +51,7 @@ function decorateFastifyInstance (pool, fastify, options, next) {
5151
const oracle = {
5252
getConnection: pool.getConnection.bind(pool),
5353
pool,
54-
scope: scope.bind(pool)
54+
transact: transact.bind(pool)
5555
}
5656

5757
if (options.name) {

test/plugin.test.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ test('retrieves a cached pool', (t) => {
116116
})
117117
})
118118

119-
test('execution scope with promise', (t) => {
119+
test('transact with promise', (t) => {
120120
t.plan(6)
121121

122122
const fastify = Fastify()
@@ -126,7 +126,7 @@ test('execution scope with promise', (t) => {
126126
t.error(err)
127127
t.ok(fastify.oracle.pool)
128128

129-
fastify.oracle.scope(conn => {
129+
fastify.oracle.transact(conn => {
130130
return conn.execute('SELECT * FROM DUAL')
131131
}).then((res, err) => {
132132
t.error(err)
@@ -140,7 +140,7 @@ test('execution scope with promise', (t) => {
140140
})
141141
})
142142

143-
test('execution scope with callback', (t) => {
143+
test('transact with callback', (t) => {
144144
t.plan(6)
145145

146146
const fastify = Fastify()
@@ -150,7 +150,7 @@ test('execution scope with callback', (t) => {
150150
t.error(err)
151151
t.ok(fastify.oracle.pool)
152152

153-
fastify.oracle.scope(conn => {
153+
fastify.oracle.transact(conn => {
154154
return conn.execute('SELECT * FROM DUAL')
155155
},
156156
function (err, result) {
@@ -164,7 +164,7 @@ test('execution scope with callback', (t) => {
164164
})
165165
})
166166

167-
test('execution scope with execute callback', (t) => {
167+
test('transact with commit callback', (t) => {
168168
t.plan(6)
169169

170170
const fastify = Fastify()
@@ -174,7 +174,7 @@ test('execution scope with execute callback', (t) => {
174174
t.error(err)
175175
t.ok(fastify.oracle.pool)
176176

177-
fastify.oracle.scope((conn, commit) => {
177+
fastify.oracle.transact((conn, commit) => {
178178
conn.execute('SELECT * FROM DUAL', function (err, result) {
179179
commit(err, result)
180180
})
@@ -189,7 +189,7 @@ test('execution scope with execute callback', (t) => {
189189
})
190190
})
191191

192-
test('execution scope with promise (error)', (t) => {
192+
test('transact with promise (error)', (t) => {
193193
t.plan(5)
194194

195195
const fastify = Fastify()
@@ -199,7 +199,7 @@ test('execution scope with promise (error)', (t) => {
199199
t.error(err)
200200
t.ok(fastify.oracle.pool)
201201

202-
fastify.oracle.scope(conn => {
202+
fastify.oracle.transact(conn => {
203203
return conn.execute('SELECT * FROM ??')
204204
}).catch((err) => {
205205
t.is(err.message, 'ORA-00911: invalid character')
@@ -212,7 +212,7 @@ test('execution scope with promise (error)', (t) => {
212212
})
213213
})
214214

215-
test('execution scope with callback (error)', (t) => {
215+
test('transact with callback (error)', (t) => {
216216
t.plan(6)
217217

218218
const fastify = Fastify()
@@ -222,7 +222,7 @@ test('execution scope with callback (error)', (t) => {
222222
t.error(err)
223223
t.ok(fastify.oracle.pool)
224224

225-
fastify.oracle.scope(conn => {
225+
fastify.oracle.transact(conn => {
226226
return conn.execute('SELECT * FROM ??')
227227
},
228228
function (err, res) {
@@ -236,7 +236,7 @@ test('execution scope with callback (error)', (t) => {
236236
})
237237
})
238238

239-
test('execution scope with execute callback (error)', (t) => {
239+
test('transact with commit callback (error)', (t) => {
240240
t.plan(6)
241241

242242
const fastify = Fastify()
@@ -246,7 +246,7 @@ test('execution scope with execute callback (error)', (t) => {
246246
t.error(err)
247247
t.ok(fastify.oracle.pool)
248248

249-
fastify.oracle.scope((conn, commit) => {
249+
fastify.oracle.transact((conn, commit) => {
250250
conn.execute('SELECT * FROM ??', function (err, result) {
251251
commit(err, result)
252252
})
@@ -261,7 +261,7 @@ test('execution scope with execute callback (error)', (t) => {
261261
})
262262
})
263263

264-
test('execution scope with callback + invalid connection pool', (t) => {
264+
test('transact with callback + invalid connection pool', (t) => {
265265
t.plan(6)
266266

267267
const fastify = Fastify()
@@ -271,7 +271,7 @@ test('execution scope with callback + invalid connection pool', (t) => {
271271
t.error(err)
272272
t.ok(fastify.oracle.pool)
273273

274-
fastify.oracle.scope(conn => {
274+
fastify.oracle.transact(conn => {
275275
return conn.execute('SELECT * FROM DUAL')
276276
},
277277
function (err, res) {
@@ -285,7 +285,7 @@ test('execution scope with callback + invalid connection pool', (t) => {
285285
})
286286
})
287287

288-
test('execution scope with promise + invalid connection pool', (t) => {
288+
test('transact with promise + invalid connection pool', (t) => {
289289
t.plan(5)
290290

291291
const fastify = Fastify()
@@ -295,7 +295,7 @@ test('execution scope with promise + invalid connection pool', (t) => {
295295
t.error(err)
296296
t.ok(fastify.oracle.pool)
297297

298-
fastify.oracle.scope(conn => {
298+
fastify.oracle.transact(conn => {
299299
return conn.execute('SELECT * FROM DUAL')
300300
}).catch((err) => {
301301
t.is(err.message, 'ORA-24415: Missing or null username.')

0 commit comments

Comments
 (0)