Skip to content

Commit a70dffa

Browse files
author
serhii.zahuba
committed
fix lint 2
1 parent 2a98009 commit a70dffa

File tree

2 files changed

+36
-30
lines changed

2 files changed

+36
-30
lines changed

frontend/src/features/sqlquery/SqlQueryComponent.tsx

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ interface Props {
1818
}
1919

2020
function 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+
3233
function friendlyError(msg: string): string {
3334
const m = msg || 'Unexpected error';
3435
if (/SQLSTATE\s*42P01/i.test(m) || /relation .* does not exist/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">

frontend/src/features/sqlquery/api.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ export interface ExecuteRequest {
88
timeout_sec?: number;
99
}
1010

11+
type SqlValue = string | number | boolean | null;
12+
1113
export interface ExecuteResponse {
12-
columns: string[];
13-
rows: any[][];
14-
row_count: number;
15-
truncated: boolean;
16-
execution_ms: number;
14+
columns: string[];
15+
rows: SqlValue[][];
16+
row_count: number;
17+
truncated: boolean;
18+
execution_ms: number;
1719
}
1820

21+
1922
export const sqlqueryApi = {
2023
execute: async (payload: ExecuteRequest): Promise<ExecuteResponse> => {
2124
const opts = new RequestOptions().setBody(JSON.stringify(payload));

0 commit comments

Comments
 (0)