@@ -29,7 +29,6 @@ function toCsv(resp: ExecuteResponse): string {
2929 return [ header , ...rows ] . join ( '\n' ) ;
3030}
3131
32-
3332function friendlyError ( msg : string ) : string {
3433 const m = msg || 'Unexpected error' ;
3534 if ( / S Q L S T A T E \s * 4 2 P 0 1 / i. test ( m ) || / r e l a t i o n .* d o e s n o t e x i s t / i. test ( m ) ) {
@@ -60,14 +59,16 @@ export const SqlQueryComponent = ({ databaseId }: Props) => {
6059 } ) ) ;
6160 } , [ resp ] ) ;
6261
63- const dataSource = useMemo ( ( ) => {
64- if ( ! resp ) return [ ] ;
65- return resp . rows . map ( ( row , i ) => {
66- const record : Record < string , unknown > = { key : i } ;
67- row . forEach ( ( v , idx ) => { record [ `c${ idx } ` ] = v ; } ) ;
68- return record ;
69- } ) ;
70- } , [ resp ] ) ;
62+ const dataSource = useMemo ( ( ) => {
63+ if ( ! resp ) return [ ] ;
64+ return resp . rows . map ( ( row , i ) => {
65+ const record : Record < string , unknown > = { key : i } ;
66+ row . forEach ( ( v , idx ) => {
67+ record [ `c${ idx } ` ] = v ;
68+ } ) ;
69+ return record ;
70+ } ) ;
71+ } , [ resp ] ) ;
7172
7273 const run = async ( ) => {
7374 if ( ! sql . trim ( ) ) {
@@ -116,23 +117,23 @@ const dataSource = useMemo(() => {
116117 URL . revokeObjectURL ( url ) ;
117118 } ;
118119
119- const downloadJson = ( ) => {
120- if ( ! resp ) return ;
121- const items = resp . rows . map ( ( row ) => {
122- const obj : Record < string , unknown > = { } ;
123- resp . columns . forEach ( ( name , i ) => {
124- obj [ name || `col_${ i + 1 } ` ] = row [ i ] ;
120+ const downloadJson = ( ) => {
121+ if ( ! resp ) return ;
122+ const items = resp . rows . map ( ( row ) => {
123+ const obj : Record < string , unknown > = { } ;
124+ resp . columns . forEach ( ( name , i ) => {
125+ obj [ name || `col_${ i + 1 } ` ] = row [ i ] ;
126+ } ) ;
127+ return obj ;
125128 } ) ;
126- return obj ;
127- } ) ;
128- const blob = new Blob ( [ JSON . stringify ( items , null , 2 ) ] , { type : 'application/json' } ) ;
129- const url = URL . createObjectURL ( blob ) ;
130- const a = document . createElement ( 'a' ) ;
131- a . href = url ;
132- a . download = 'result.json' ;
133- a . click ( ) ;
134- URL . revokeObjectURL ( url ) ;
135- } ;
129+ const blob = new Blob ( [ JSON . stringify ( items , null , 2 ) ] , { type : 'application/json' } ) ;
130+ const url = URL . createObjectURL ( blob ) ;
131+ const a = document . createElement ( 'a' ) ;
132+ a . href = url ;
133+ a . download = 'result.json' ;
134+ a . click ( ) ;
135+ URL . revokeObjectURL ( url ) ;
136+ } ;
136137
137138 return (
138139 < div className = "mt-2 rounded border border-gray-200 bg-white p-3" >
0 commit comments