File tree Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -254,7 +254,7 @@ test('fastify.pg.test should throw with duplicate connection names', t => {
254254 } )
255255} )
256256
257- test ( 'fastify.pg.test use transact util' , t => {
257+ test ( 'fastify.pg.test use transact util with promise ' , t => {
258258 t . plan ( 3 )
259259
260260 const fastify = Fastify ( )
@@ -293,3 +293,35 @@ test('fastify.pg.test use transact util', t => {
293293 } )
294294 } )
295295} )
296+
297+ test ( 'fastify.pg.test use transact util with callback' , t => {
298+ t . plan ( 2 )
299+
300+ const fastify = Fastify ( )
301+
302+ fastify . register ( fastifyPostgres , {
303+ name : 'test' ,
304+ connectionString : 'postgres://postgres@localhost/postgres'
305+ } )
306+
307+ fastify . ready ( err => {
308+ t . error ( err )
309+ fastify . pg . test
310+ . query ( 'CREATE TABLE users2(id serial PRIMARY KEY, username VARCHAR (50) NOT NULL)' )
311+ . then ( function ( ) {
312+ fastify . pg . test
313+ . transact ( 'INSERT INTO users2(username) VALUES($1) RETURNING id' , [ 'brianc' ] , function ( err , res ) {
314+ if ( err ) {
315+ t . fail ( err )
316+ fastify . close ( )
317+ } else {
318+ t . ok ( res . rows [ 0 ] . id === 1 )
319+ }
320+ } )
321+ } )
322+ . catch ( err => {
323+ t . fail ( err )
324+ fastify . close ( )
325+ } )
326+ } )
327+ } )
You can’t perform that action at this time.
0 commit comments