File tree Expand file tree Collapse file tree 2 files changed +34
-8
lines changed
apps/web/src/components/v2Editor/customBlocks/sql
packages/editor/src/blocks Expand file tree Collapse file tree 2 files changed +34
-8
lines changed Original file line number Diff line number Diff line change @@ -180,16 +180,16 @@ function SQLBlock(props: Props) {
180
180
( props . isEditable
181
181
? isCodeHiddenProp
182
182
: localCodeHidden === null
183
- ? isCodeHiddenProp
184
- : localCodeHidden )
183
+ ? isCodeHiddenProp
184
+ : localCodeHidden )
185
185
186
186
const isResultHidden =
187
187
( ! props . dashboardMode || ! dashboardModeHasControls ( props . dashboardMode ) ) &&
188
188
( props . isEditable
189
189
? isResultHiddenProp
190
190
: localResultHidden === null
191
- ? isResultHiddenProp
192
- : localResultHidden )
191
+ ? isResultHiddenProp
192
+ : localResultHidden )
193
193
194
194
const { startedAt : environmentStartedAt } = useEnvironmentStatus (
195
195
props . document . workspaceId
@@ -443,7 +443,10 @@ function SQLBlock(props: Props) {
443
443
} , [ router , props . document . workspaceId ] )
444
444
445
445
const onToggleFormatSQLCode = useCallback ( ( ) => {
446
- const sqlCodeFormatted = getSQLCodeFormatted ( source )
446
+ const sqlCodeFormatted = getSQLCodeFormatted (
447
+ source ,
448
+ dataSource ?. config . type ?? null
449
+ )
447
450
448
451
if ( ! sqlCodeFormatted ) {
449
452
return
Original file line number Diff line number Diff line change
1
+ import { type DataSourceType } from '@briefer/database'
1
2
import * as Y from 'yjs'
2
3
import {
3
4
RunQueryResult ,
@@ -15,7 +16,7 @@ import {
15
16
} from './index.js'
16
17
import { ResultStatus , updateYText } from '../index.js'
17
18
import { clone } from 'ramda'
18
- import { format as formatSQL } from 'sql-formatter'
19
+ import { format as formatSQL , SqlLanguage } from 'sql-formatter'
19
20
20
21
export type DataframeName = {
21
22
value : string
@@ -354,13 +355,35 @@ export function getSQLBlockErrorMessage(
354
355
}
355
356
}
356
357
357
- export function getSQLCodeFormatted ( source : Y . Text ) {
358
+ export function getSQLCodeFormatted (
359
+ source : Y . Text ,
360
+ dialect : DataSourceType | null
361
+ ) {
358
362
if ( ! source . length ) {
359
363
return null
360
364
}
361
365
366
+ const language : SqlLanguage = ( ( ) => {
367
+ switch ( dialect ) {
368
+ case 'psql' :
369
+ return 'postgresql'
370
+ case 'bigquery' :
371
+ case 'mysql' :
372
+ case 'snowflake' :
373
+ case 'trino' :
374
+ case 'redshift' :
375
+ return dialect
376
+ case 'athena' :
377
+ case 'oracle' :
378
+ case 'sqlserver' :
379
+ case 'databrickssql' :
380
+ case null :
381
+ return 'sql'
382
+ }
383
+ } ) ( )
384
+
362
385
const formatted = formatSQL ( source . toString ( ) , {
363
- language : 'sql' ,
386
+ language,
364
387
tabWidth : 4 ,
365
388
} )
366
389
You can’t perform that action at this time.
0 commit comments