@@ -6,6 +6,7 @@ import { io, Socket } from 'socket.io-client'
66import { SQLiteCloudConnection } from './connection'
77import { SQLiteCloudRowset } from './rowset'
88import { ErrorCallback , ResultsCallback , SQLiteCloudCommand , SQLiteCloudConfig , SQLiteCloudError } from './types'
9+ import { decodeBigIntMarkers , encodeBigIntMarkers } from './utilities'
910
1011/**
1112 * Implementation of TransportConnection that connects to the database indirectly
@@ -80,24 +81,34 @@ export class SQLiteCloudWebsocketConnection extends SQLiteCloudConnection {
8081 commands = { query : commands }
8182 }
8283
83- this . socket . emit ( 'GET /v2/weblite/sql' , { sql : commands . query , bind : commands . parameters , row : 'array' } , ( response : any ) => {
84- if ( response ?. error ) {
85- const error = new SQLiteCloudError ( response . error . detail , { ...response . error } )
86- callback ?. call ( this , error )
87- } else {
88- const { data, metadata } = response
89- if ( data && metadata ) {
90- if ( metadata . numberOfRows !== undefined && metadata . numberOfColumns !== undefined && metadata . columns !== undefined ) {
91- console . assert ( Array . isArray ( data ) , 'SQLiteCloudWebsocketConnection.transportCommands - data is not an array' )
92- // we can recreate a SQLiteCloudRowset from the response which we know to be an array of arrays
93- const rowset = new SQLiteCloudRowset ( metadata , data . flat ( ) )
94- callback ?. call ( this , null , rowset )
95- return
84+ this . socket . emit (
85+ 'GET /v2/weblite/sql' ,
86+ {
87+ sql : commands . query ,
88+ bind : encodeBigIntMarkers ( commands . parameters ) ,
89+ row : 'array' ,
90+ safe_integer_mode : this . config . safe_integer_mode
91+ } ,
92+ ( response : any ) => {
93+ if ( response ?. error ) {
94+ const error = new SQLiteCloudError ( response . error . detail , { ...response . error } )
95+ callback ?. call ( this , error )
96+ } else {
97+ const { metadata } = response
98+ const data = decodeBigIntMarkers ( response ?. data , this . config . safe_integer_mode )
99+ if ( data && metadata ) {
100+ if ( metadata . numberOfRows !== undefined && metadata . numberOfColumns !== undefined && metadata . columns !== undefined ) {
101+ console . assert ( Array . isArray ( data ) , 'SQLiteCloudWebsocketConnection.transportCommands - data is not an array' )
102+ // we can recreate a SQLiteCloudRowset from the response which we know to be an array of arrays
103+ const rowset = new SQLiteCloudRowset ( metadata , data . flat ( ) )
104+ callback ?. call ( this , null , rowset )
105+ return
106+ }
96107 }
108+ callback ?. call ( this , null , data )
97109 }
98- callback ?. call ( this , null , response ?. data )
99110 }
100- } )
111+ )
101112
102113 return this
103114 }
0 commit comments