File tree Expand file tree Collapse file tree 3 files changed +54
-6
lines changed
apps/postgres-new/components/tools Expand file tree Collapse file tree 3 files changed +54
-6
lines changed Original file line number Diff line number Diff line change 1
1
import { m } from 'framer-motion'
2
2
import { Download } from 'lucide-react'
3
+ import { useMemo } from 'react'
4
+ import { format } from 'sql-formatter'
3
5
import { loadFile } from '~/lib/files'
4
6
import { ToolInvocation } from '~/lib/tools'
5
7
import { downloadFile } from '~/lib/util'
@@ -10,19 +12,40 @@ export type CsvExportProps = {
10
12
}
11
13
12
14
export default function CsvExport ( { toolInvocation } : CsvExportProps ) {
15
+ const { sql } = toolInvocation . args
16
+
17
+ const formattedSql = useMemo (
18
+ ( ) =>
19
+ format ( sql , {
20
+ language : 'postgresql' ,
21
+ keywordCase : 'lower' ,
22
+ identifierCase : 'lower' ,
23
+ dataTypeCase : 'lower' ,
24
+ functionCase : 'lower' ,
25
+ } ) ,
26
+ [ sql ]
27
+ )
28
+
13
29
if ( ! ( 'result' in toolInvocation ) ) {
14
30
return null
15
31
}
16
32
17
33
const { result } = toolInvocation
18
34
19
35
if ( ! result . success ) {
20
- return < div className = "bg-destructive-300 px-6 py-4 rounded-md" > Error executing SQL</ div >
36
+ return (
37
+ < CodeAccordion
38
+ title = "Error executing SQL"
39
+ language = "sql"
40
+ code = { formattedSql }
41
+ error = { result . error }
42
+ />
43
+ )
21
44
}
22
45
23
46
return (
24
47
< >
25
- < CodeAccordion title = "Executed SQL" language = "sql" code = { toolInvocation . args . sql } />
48
+ < CodeAccordion title = "Executed SQL" language = "sql" code = { formattedSql } />
26
49
< m . div
27
50
layoutId = { toolInvocation . toolCallId }
28
51
className = "self-start px-5 py-2.5 text-base rounded-full bg-border flex gap-2 items-center text-lighter italic"
Original file line number Diff line number Diff line change 1
1
import { ToolInvocation } from '~/lib/tools'
2
2
import CodeAccordion from '../code-accordion'
3
+ import { useMemo } from 'react'
4
+ import { format } from 'sql-formatter'
3
5
4
6
export type CsvExportProps = {
5
7
toolInvocation : ToolInvocation < 'importCsv' >
6
8
}
7
9
8
10
export default function CsvImport ( { toolInvocation } : CsvExportProps ) {
11
+ const { sql } = toolInvocation . args
12
+
13
+ const formattedSql = useMemo (
14
+ ( ) =>
15
+ format ( sql , {
16
+ language : 'postgresql' ,
17
+ keywordCase : 'lower' ,
18
+ identifierCase : 'lower' ,
19
+ dataTypeCase : 'lower' ,
20
+ functionCase : 'lower' ,
21
+ } ) ,
22
+ [ sql ]
23
+ )
24
+
9
25
if ( ! ( 'result' in toolInvocation ) ) {
10
26
return null
11
27
}
12
28
13
29
const { result } = toolInvocation
14
30
15
31
if ( ! result . success ) {
16
- return < div className = "bg-destructive-300 px-6 py-4 rounded-md" > Error executing SQL</ div >
32
+ return (
33
+ < CodeAccordion
34
+ title = "Error executing SQL"
35
+ language = "sql"
36
+ code = { formattedSql }
37
+ error = { result . error }
38
+ />
39
+ )
17
40
}
18
41
19
- return < CodeAccordion title = "Executed SQL" language = "sql" code = { toolInvocation . args . sql } />
42
+ return < CodeAccordion title = "Executed SQL" language = "sql" code = { formattedSql } />
20
43
}
Original file line number Diff line number Diff line change @@ -26,13 +26,15 @@ export default function ExecutedSql({ toolInvocation }: ExecutedSqlProps) {
26
26
return null
27
27
}
28
28
29
- if ( ! toolInvocation . result . success ) {
29
+ const { result } = toolInvocation
30
+
31
+ if ( ! result . success ) {
30
32
return (
31
33
< CodeAccordion
32
34
title = "Error executing SQL"
33
35
language = "sql"
34
36
code = { formattedSql }
35
- error = { toolInvocation . result . error }
37
+ error = { result . error }
36
38
/>
37
39
)
38
40
}
You can’t perform that action at this time.
0 commit comments