File tree Expand file tree Collapse file tree
apps/web/src/components/v2Editor/customBlocks/sql
packages/editor/src/blocks Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -180,16 +180,16 @@ function SQLBlock(props: Props) {
180180 ( props . isEditable
181181 ? isCodeHiddenProp
182182 : localCodeHidden === null
183- ? isCodeHiddenProp
184- : localCodeHidden )
183+ ? isCodeHiddenProp
184+ : localCodeHidden )
185185
186186 const isResultHidden =
187187 ( ! props . dashboardMode || ! dashboardModeHasControls ( props . dashboardMode ) ) &&
188188 ( props . isEditable
189189 ? isResultHiddenProp
190190 : localResultHidden === null
191- ? isResultHiddenProp
192- : localResultHidden )
191+ ? isResultHiddenProp
192+ : localResultHidden )
193193
194194 const { startedAt : environmentStartedAt } = useEnvironmentStatus (
195195 props . document . workspaceId
@@ -443,7 +443,10 @@ function SQLBlock(props: Props) {
443443 } , [ router , props . document . workspaceId ] )
444444
445445 const onToggleFormatSQLCode = useCallback ( ( ) => {
446- const sqlCodeFormatted = getSQLCodeFormatted ( source )
446+ const sqlCodeFormatted = getSQLCodeFormatted (
447+ source ,
448+ dataSource ?. config . type ?? null
449+ )
447450
448451 if ( ! sqlCodeFormatted ) {
449452 return
Original file line number Diff line number Diff line change 1+ import { type DataSourceType } from '@briefer/database'
12import * as Y from 'yjs'
23import {
34 RunQueryResult ,
@@ -15,7 +16,7 @@ import {
1516} from './index.js'
1617import { ResultStatus , updateYText } from '../index.js'
1718import { clone } from 'ramda'
18- import { format as formatSQL } from 'sql-formatter'
19+ import { format as formatSQL , SqlLanguage } from 'sql-formatter'
1920
2021export type DataframeName = {
2122 value : string
@@ -354,13 +355,35 @@ export function getSQLBlockErrorMessage(
354355 }
355356}
356357
357- export function getSQLCodeFormatted ( source : Y . Text ) {
358+ export function getSQLCodeFormatted (
359+ source : Y . Text ,
360+ dialect : DataSourceType | null
361+ ) {
358362 if ( ! source . length ) {
359363 return null
360364 }
361365
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+
362385 const formatted = formatSQL ( source . toString ( ) , {
363- language : 'sql' ,
386+ language,
364387 tabWidth : 4 ,
365388 } )
366389
You can’t perform that action at this time.
0 commit comments