@@ -510,7 +510,7 @@ async function dbCallAsync(baton, argList, mode) {
510510 // increment db.busy
511511 db . busy += 1 ;
512512 try {
513- return await dbCallAsync ( baton , [ db . ptr , ...argList . slice ( 1 ) ] ) ;
513+ return await dbCallAsync ( baton , [ db . ptr , ...argList . slice ( 1 ) ] , db ) ;
514514 } finally {
515515 // decrement db.busy
516516 db . busy -= 1 ;
@@ -638,6 +638,10 @@ async function dbCallAsync(baton, argList, mode) {
638638 // prepend baton to argList
639639 return [ result . baton , ...result . argList ] ;
640640 } catch ( err ) {
641+ // debug db.filename
642+ if ( mode ?. filename2 || mode ?. filename ) {
643+ err . message += ` (from ${ mode ?. filename2 || mode ?. filename } )` ;
644+ }
641645 err . stack += errStack ;
642646 assertOrThrow ( undefined , err ) ;
643647 }
@@ -660,67 +664,45 @@ async function dbCloseAsync(db) {
660664 } ) ) ;
661665}
662666
663- function dbExecAndReturnLastBlob ( {
664- bindList = [ ] ,
665- db,
666- sql
667- } ) {
667+ function dbExecAndReturnLastBlob ( option ) {
668668
669669// This function will exec <sql> in <db>,
670670// and return last-value retrieved from execution as raw blob/buffer.
671671
672- return dbExecAsync ( {
673- bindList,
674- db,
675- responseType : "lastblob" ,
676- sql
677- } ) ;
672+ return dbExecAsync ( Object . assign ( {
673+ responseType : "lastblob"
674+ } , option ) ) ;
678675}
679676
680- async function dbExecAndReturnLastRow ( {
681- bindList = [ ] ,
682- db,
683- sql
684- } ) {
677+ async function dbExecAndReturnLastRow ( option ) {
685678
686679// This function will exec <sql> in <db>,
687680// and return last-row or empty-object.
688681
689- let result = await dbExecAsync ( { bindList , db , sql } ) ;
682+ let result = await dbExecAsync ( option ) ;
690683 result = result [ result . length - 1 ] || [ ] ;
691684 result = result [ result . length - 1 ] || { } ;
692685 return result ;
693686}
694687
695- async function dbExecAndReturnLastTable ( {
696- bindList = [ ] ,
697- db,
698- sql
699- } ) {
688+ async function dbExecAndReturnLastTable ( option ) {
700689
701690// This function will exec <sql> in <db>,
702691// and return last-table or empty-list.
703692
704- let result = await dbExecAsync ( { bindList , db , sql } ) ;
693+ let result = await dbExecAsync ( option ) ;
705694 result = result [ result . length - 1 ] || [ ] ;
706695 return result ;
707696}
708697
709- function dbExecAndReturnLastValue ( {
710- bindList = [ ] ,
711- db,
712- sql
713- } ) {
698+ function dbExecAndReturnLastValue ( option ) {
714699
715700// This function will exec <sql> in <db>,
716701// and return last-json-value.
717702
718- return dbExecAsync ( {
719- bindList,
720- db,
721- responseType : "lastvalue" ,
722- sql
723- } ) ;
703+ return dbExecAsync ( Object . assign ( {
704+ responseType : "lastvalue"
705+ } , option ) ) ;
724706}
725707
726708async function dbExecAsync ( {
@@ -763,7 +745,9 @@ async function dbExecAsync({
763745 ) ;
764746 } ) ;
765747 }
766- [ baton , ...result ] = await dbCallAsync (
748+ [
749+ baton , ...result
750+ ] = await dbCallAsync (
767751 baton ,
768752 [
769753 // 0. db
@@ -859,6 +843,7 @@ async function dbFileLoadAsync({
859843 typeof filename === "string" && filename ,
860844 `invalid filename ${ filename } `
861845 ) ;
846+ db . filename2 = filename ;
862847 // Save to tmpfile and then atomically-rename to actual-filename.
863848 if ( moduleFs && modeSave ) {
864849 filename2 = filename ;
0 commit comments