Skip to content

Commit

Permalink
Merge pull request #21 from sonswift/master
Browse files Browse the repository at this point in the history
Update dependency version.
  • Loading branch information
huyphams authored Nov 17, 2024
2 parents c10419f + 5b509d3 commit 632cee0
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 31 deletions.
39 changes: 35 additions & 4 deletions SQLFormatter.tableplusplugin/library/helper.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
'use strict';

import sqlFormatter from "sql-formatter";
import { format } from "sql-formatter";

var formatSQL = function(string) {
var formatterStatement = sqlFormatter.format(string);
var formatSQL = function(string, language) {
var formatterStatement = format(string, {language: language});
return formatterStatement;
}

export { formatSQL };
var languageFromDriver = function(driver) {
if (driver === undefined || driver === null) {
return "postgresql";
}
switch (driver.toLowerCase()) {
case "bigquery":
return "bigquery";
case "mysql":
return "mysql";
case "mariadb":
return "mariadb";
case "duckdb":
case "sqlite":
case "libsql":
case "cloudflared1":
return "sqlite";
case "redshift":
return "redshift";
case "snowflake":
return "snowflake";
case "microsoftsqlserver":
return "transactsql";
case "oracle":
return "plsql"
default:
/** Fallback to default */
return "postgresql";
}
}

export { formatSQL, languageFromDriver };

6 changes: 4 additions & 2 deletions SQLFormatter.tableplusplugin/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import { formatSQL } from './library/helper';
import { formatSQL, languageFromDriver } from './library/helper';

var onRun = function(context) {
// Get table in opening tab
Expand All @@ -9,9 +9,11 @@ var onRun = function(context) {
context.alert('Error', 'No SQL Editor');
return;
}
var driver = context.driver();
var language = languageFromDriver(driver);
var range = queryEditor.currentSelectedRange();
var statement = queryEditor.currentSelectedString();
var formattedStatement = formatSQL(statement);
var formattedStatement = formatSQL(statement, language);
queryEditor.replaceStringInRange(formattedStatement, range);
};

Expand Down
2 changes: 1 addition & 1 deletion SQLFormatter.tableplusplugin/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "SQL Formatter Plugin",
"identifier": "com.tinyapp.TablePlus.SQLFormatter",
"version": "1.0",
"version": "1.1",
"detail": "This plugin helps you format the SQL statement",
"author": "TablePlus",
"authorEmail": "[email protected]",
Expand Down
103 changes: 80 additions & 23 deletions SQLFormatter.tableplusplugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion SQLFormatter.tableplusplugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "This plugin helps fill your empty table with funny text and quote for testing purpose",
"main": "main.js",
"dependencies": {
"sql-formatter": "^3.0.0"
"sql-formatter": "^15.4.6"
},
"devDependencies": {
"babel-core": "^6.25.0",
Expand Down

0 comments on commit 632cee0

Please sign in to comment.