@@ -133,55 +133,37 @@ class Connection extends EventEmitter {
133133 _attachListenersWithSizeLimit ( stream ) {
134134 parse ( stream , ( msg ) => {
135135 var eventName = msg . name === 'error' ? 'errorMessage' : msg . name
136-
136+
137137 // Only track data row messages for result size
138138 if ( msg . name === 'dataRow' ) {
139139 // Approximate size by using message length
140- const msgSize = msg . length || this . _getApproximateMessageSize ( msg )
140+ const msgSize = msg . length || 1024 // Default to 1KB if we don't have lenght info
141141 this . _currentResultSize += msgSize
142-
142+
143143 // Check if we've exceeded the max result size
144144 if ( this . _currentResultSize > this . _maxResultSize ) {
145145 const error = new Error ( 'Query result size exceeded the configured limit' )
146146 error . code = 'RESULT_SIZE_EXCEEDED'
147147 error . resultSize = this . _currentResultSize
148148 error . maxResultSize = this . _maxResultSize
149- this . emit ( 'error ' , error )
149+ this . emit ( 'errorMessage ' , error )
150150 this . end ( ) // Terminate the connection
151151 return
152152 }
153153 }
154-
154+
155155 // Reset counter on query completion
156156 if ( msg . name === 'readyForQuery' ) {
157157 this . _currentResultSize = 0
158158 }
159-
159+
160160 if ( this . _emitMessage ) {
161161 this . emit ( 'message' , msg )
162162 }
163163 this . emit ( eventName , msg )
164164 } )
165165 }
166166
167- // Helper method to approximate message size when length is not available
168- _getApproximateMessageSize ( msg ) {
169- let size = 0
170- if ( msg . fields ) {
171- // Sum up the sizes of field values
172- msg . fields . forEach ( field => {
173- if ( field && typeof field === 'string' ) {
174- size += field . length ;
175- } else if ( field && typeof field === 'object' ) {
176- size += JSON . stringify ( field ) . length ;
177- } else if ( field !== null && field !== undefined ) {
178- size += String ( field ) . length ;
179- }
180- } ) ;
181- }
182- return size > 0 ? size : 1024 ; // Default to 1KB if we can't determine size
183- }
184-
185167 requestSsl ( ) {
186168 this . stream . write ( serialize . requestSsl ( ) )
187169 }
0 commit comments