@@ -18,9 +18,9 @@ interface Props {
1818}
1919
2020function toCsv ( resp : ExecuteResponse ) : string {
21- const esc = ( v : any ) => {
21+ const esc = ( v : unknown ) => {
2222 if ( v === null || v === undefined ) return '' ;
23- const s = String ( v ) ;
23+ const s = typeof v === 'object' ? JSON . stringify ( v ) : String ( v ) ;
2424 if ( / [ " , \n \r ] / . test ( s ) ) return `"${ s . replace ( / " / g, '""' ) } "` ;
2525 return s ;
2626 } ;
@@ -29,6 +29,7 @@ function toCsv(resp: ExecuteResponse): string {
2929 return [ header , ...rows ] . join ( '\n' ) ;
3030}
3131
32+
3233function friendlyError ( msg : string ) : string {
3334 const m = msg || 'Unexpected error' ;
3435 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 ) ) {
@@ -59,14 +60,14 @@ export const SqlQueryComponent = ({ databaseId }: Props) => {
5960 } ) ) ;
6061 } , [ resp ] ) ;
6162
62- const dataSource = useMemo ( ( ) => {
63- if ( ! resp ) return [ ] ;
64- return resp . rows . map ( ( row , i ) => {
65- const record : Record < string , any > = { key : i } ;
66- row . forEach ( ( v , idx ) => ( record [ `c${ idx } ` ] = v ) ) ;
67- return record ;
68- } ) ;
69- } , [ resp ] ) ;
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 ] ) ;
7071
7172 const run = async ( ) => {
7273 if ( ! sql . trim ( ) ) {
@@ -91,7 +92,7 @@ export const SqlQueryComponent = ({ databaseId }: Props) => {
9192 timeout_sec : timeoutSec ,
9293 } ) ;
9394 setResp ( r ) ;
94- } catch ( e : any ) {
95+ } catch ( e : unknown ) {
9596 setErrorText ( friendlyError ( e ?. message || 'Unexpected error' ) ) ;
9697 } finally {
9798 setLoading ( false ) ;
@@ -115,21 +116,23 @@ export const SqlQueryComponent = ({ databaseId }: Props) => {
115116 URL . revokeObjectURL ( url ) ;
116117 } ;
117118
118- const downloadJson = ( ) => {
119- if ( ! resp ) return ;
120- const items = resp . rows . map ( ( row ) => {
121- const obj : Record < string , any > = { } ;
122- resp . columns . forEach ( ( name , i ) => ( obj [ name || `col_ ${ i + 1 } ` ] = row [ i ] ) ) ;
123- return obj ;
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 ] ;
124125 } ) ;
125- const blob = new Blob ( [ JSON . stringify ( items , null , 2 ) ] , { type : 'application/json' } ) ;
126- const url = URL . createObjectURL ( blob ) ;
127- const a = document . createElement ( 'a' ) ;
128- a . href = url ;
129- a . download = 'result.json' ;
130- a . click ( ) ;
131- URL . revokeObjectURL ( url ) ;
132- } ;
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+ } ;
133136
134137 return (
135138 < div className = "mt-2 rounded border border-gray-200 bg-white p-3" >
0 commit comments