@@ -25,6 +25,10 @@ export async function createDatabase(
2525 let db : any ;
2626 const statements = new Map < string , Statement > ( ) ;
2727 const dbFileName = database ;
28+ const DEBUG = process . env . SQLITE3_VEC_DEBUG === '1' ;
29+ const dlog = ( ...args : any [ ] ) => {
30+ if ( DEBUG ) console . log ( '[sqlite3-vec][node]' , ...args ) ;
31+ } ;
2832
2933 const open = ( ) => {
3034 if ( db && db . open ) return db ;
@@ -37,7 +41,8 @@ export async function createDatabase(
3741 } catch { }
3842 const extPath = loadExtension || resolveNativeExtensionPath ( ) ;
3943 if ( extPath ) {
40- loadVecExtension ( db , extPath , process . env . SQLITE3_VEC_DEBUG === '1' ) ;
44+ dlog ( 'loading vec extension from' , extPath ) ;
45+ loadVecExtension ( db , extPath , DEBUG ) ;
4146 }
4247 return db ;
4348 } ;
@@ -76,6 +81,24 @@ export async function createDatabase(
7681 }
7782 return v ;
7883 } ;
84+ const summarize = ( v : any ) : any => {
85+ if ( v == null ) return v ;
86+ if ( typeof v === 'number' || typeof v === 'boolean' ) return v ;
87+ if ( typeof v === 'string' ) return `string(len=${ v . length } )` ;
88+ if ( typeof Buffer !== 'undefined' && Buffer . isBuffer ?.( v ) ) return `Buffer(${ v . byteLength } )` ;
89+ if ( v instanceof ArrayBuffer ) return `ArrayBuffer(${ v . byteLength } )` ;
90+ if ( typeof ArrayBuffer !== 'undefined' && ArrayBuffer . isView ?.( v ) ) {
91+ const ctor = ( v as any ) . constructor ?. name || 'TypedArray' ;
92+ const len = ( v as any ) . length ?? ( v . byteLength ?? '?' ) ;
93+ return `${ ctor } (${ len } )` ;
94+ }
95+ if ( typeof v === 'object' ) {
96+ const out : Record < string , any > = { } ;
97+ for ( const k of Object . keys ( v ) ) out [ k ] = summarize ( ( v as any ) [ k ] ) ;
98+ return out ;
99+ }
100+ return typeof v ;
101+ } ;
79102 const normVals = ( values ?: any [ ] | undefined ) : any [ ] | undefined =>
80103 values ? values . map ( ( x ) => toBuffer ( x ) ) : values ;
81104 const normObj = ( obj : any ) : any => {
@@ -99,6 +122,7 @@ export async function createDatabase(
99122 } ;
100123 const callWithParams = ( stmt : any , method : Method , v : any ) => {
101124 const params = mapParams ( v ) ;
125+ if ( DEBUG ) dlog ( `stmt.${ method } ()` , { params : summarize ( params ) } ) ;
102126 if ( params === undefined ) return stmt [ method ] ( ) ;
103127 // Deterministic: bind first, then call without inline params.
104128 stmt . bind ( params ) ;
@@ -140,10 +164,12 @@ export async function createDatabase(
140164 close,
141165 drop,
142166 exec ( sql : string ) {
143- return open ( ) . exec ( sql ) ;
167+ if ( DEBUG ) dlog ( 'exec' , sql ) ;
168+ return open ( ) . exec ( sql ) ;
144169 } ,
145170 async prepare ( sql : string , id ?: string ) {
146171 open ( ) ;
172+ if ( DEBUG ) dlog ( 'prepare' , { id, sql } ) ;
147173 if ( id != null && statements . has ( id ) ) {
148174 const prev = statements . get ( id ) ! ;
149175 await ( prev . reset ?.( ) as any ) ;
0 commit comments