From ba2e9136fd11f0f7d4302d7802e69cbd35a1d335 Mon Sep 17 00:00:00 2001 From: sonswift Date: Sat, 16 Nov 2024 11:04:40 +0700 Subject: [PATCH 1/2] Bump version of sql-formatter. --- .../library/helper.js | 39 ++++++- SQLFormatter.tableplusplugin/main.js | 6 +- .../package-lock.json | 103 ++++++++++++++---- SQLFormatter.tableplusplugin/package.json | 4 +- 4 files changed, 121 insertions(+), 31 deletions(-) diff --git a/SQLFormatter.tableplusplugin/library/helper.js b/SQLFormatter.tableplusplugin/library/helper.js index c69171d..0bad158 100755 --- a/SQLFormatter.tableplusplugin/library/helper.js +++ b/SQLFormatter.tableplusplugin/library/helper.js @@ -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 }; \ No newline at end of file +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 }; + diff --git a/SQLFormatter.tableplusplugin/main.js b/SQLFormatter.tableplusplugin/main.js index 7a9851b..1ef858d 100755 --- a/SQLFormatter.tableplusplugin/main.js +++ b/SQLFormatter.tableplusplugin/main.js @@ -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 @@ -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); }; diff --git a/SQLFormatter.tableplusplugin/package-lock.json b/SQLFormatter.tableplusplugin/package-lock.json index 6b3de99..7d8c925 100644 --- a/SQLFormatter.tableplusplugin/package-lock.json +++ b/SQLFormatter.tableplusplugin/package-lock.json @@ -1,15 +1,15 @@ { "name": "com.tinyapp.TablePlus.SQLFormatter.tableplusplugin", - "version": "1.0.0", + "version": "1.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "com.tinyapp.TablePlus.SQLFormatter.tableplusplugin", - "version": "1.0.0", + "version": "1.0.1", "license": "MIT", "dependencies": { - "sql-formatter": "^3.0.0" + "sql-formatter": "^15.4.6" }, "devDependencies": { "babel-core": "^6.25.0", @@ -812,13 +812,9 @@ } }, "node_modules/argparse": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", - "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", - "license": "MIT", - "dependencies": { - "sprintf-js": "~1.0.2" - } + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" }, "node_modules/babel-code-frame": { "version": "6.26.0", @@ -1551,7 +1547,6 @@ "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", - "dev": true, "license": "MIT" }, "node_modules/common-path-prefix": { @@ -1622,6 +1617,11 @@ "node": ">=0.10.0" } }, + "node_modules/discontinuous-range": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/discontinuous-range/-/discontinuous-range-1.0.0.tgz", + "integrity": "sha512-c68LpLbO+7kP/b1Hr1qs8/BJ09F5khZGTxqxZuhzxpmwJKOgRFHJWIb9/KmqnqHhLdO55aOxFH/EGBvUQbL/RQ==" + }, "node_modules/electron-to-chromium": { "version": "1.5.62", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.62.tgz", @@ -1846,6 +1846,17 @@ "node": ">=6.9.0" } }, + "node_modules/get-stdin": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-8.0.0.tgz", + "integrity": "sha512-sY22aA6xchAzprjyqmSEQv4UbAAzRN0L2dQB0NlN5acTTK9Don6nhoc3eAbUnpZiCANAMfd/+40kVdKfFygohg==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/glob-to-regexp": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz", @@ -2303,6 +2314,11 @@ "mkdirp": "bin/cmd.js" } }, + "node_modules/moo": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/moo/-/moo-0.5.2.tgz", + "integrity": "sha512-iSAJLHYKnX41mKcJKjqvnAN9sf0LMDTXDEvFv+ffuRR9a1MIuXLjMNL6EsnDHSkKLTWNqQQ5uo61P4EbU4NU+Q==" + }, "node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -2310,6 +2326,27 @@ "dev": true, "license": "MIT" }, + "node_modules/nearley": { + "version": "2.20.1", + "resolved": "https://registry.npmjs.org/nearley/-/nearley-2.20.1.tgz", + "integrity": "sha512-+Mc8UaAebFzgV+KpI5n7DasuuQCHA89dmwm7JXw3TV43ukfNQ9DnBH3Mdb2g/I4Fdxc26pwimBWvjIw0UAILSQ==", + "dependencies": { + "commander": "^2.19.0", + "moo": "^0.5.0", + "railroad-diagrams": "^1.0.0", + "randexp": "0.4.6" + }, + "bin": { + "nearley-railroad": "bin/nearley-railroad.js", + "nearley-test": "bin/nearley-test.js", + "nearley-unparse": "bin/nearley-unparse.js", + "nearleyc": "bin/nearleyc.js" + }, + "funding": { + "type": "individual", + "url": "https://nearley.js.org/#give-to-nearley" + } + }, "node_modules/neo-async": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", @@ -2466,6 +2503,23 @@ "node": ">=6" } }, + "node_modules/railroad-diagrams": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz", + "integrity": "sha512-cz93DjNeLY0idrCNOH6PviZGRN9GJhsdm9hpn1YCS879fj4W+x5IFJhhkRZcwVgMmFF7R82UA/7Oh+R8lLZg6A==" + }, + "node_modules/randexp": { + "version": "0.4.6", + "resolved": "https://registry.npmjs.org/randexp/-/randexp-0.4.6.tgz", + "integrity": "sha512-80WNmd9DA0tmZrw9qQa62GPPWfuXJknrmVmLcxvq4uZBdYqb1wYoKTmnlGUchvVWe0XiLupYkBoXVOxz3C8DYQ==", + "dependencies": { + "discontinuous-range": "1.0.0", + "ret": "~0.1.10" + }, + "engines": { + "node": ">=0.12" + } + }, "node_modules/randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -2620,6 +2674,14 @@ "node": ">=8" } }, + "node_modules/ret": { + "version": "0.1.15", + "resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz", + "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==", + "engines": { + "node": ">=0.12" + } + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -2748,22 +2810,17 @@ "source-map": "^0.5.6" } }, - "node_modules/sprintf-js": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==", - "license": "BSD-3-Clause" - }, "node_modules/sql-formatter": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/sql-formatter/-/sql-formatter-3.1.0.tgz", - "integrity": "sha512-PseQ+fm9VcwXxAD71TiDs8x9Ww3IJbfhSR8Yvq//TwtqxqxVZ8Q9rAmsWiL4w/F0VxBZXCmKxxpw4Cyr0cZZ0w==", - "license": "MIT", + "version": "15.4.6", + "resolved": "https://registry.npmjs.org/sql-formatter/-/sql-formatter-15.4.6.tgz", + "integrity": "sha512-aH6kwvJpylljHqXe+zpie0Q5snL3uerDLLhjPEBjDCVK1NMRFq4nMJbuPJWYp08LaaaJJgBhShAdAfspcBYY0Q==", "dependencies": { - "argparse": "^1.0.10" + "argparse": "^2.0.1", + "get-stdin": "=8.0.0", + "nearley": "^2.20.1" }, "bin": { - "sql-formatter": "bin/sqlfmt.js" + "sql-formatter": "bin/sql-formatter-cli.cjs" } }, "node_modules/strip-ansi": { diff --git a/SQLFormatter.tableplusplugin/package.json b/SQLFormatter.tableplusplugin/package.json index d085196..6cb022d 100755 --- a/SQLFormatter.tableplusplugin/package.json +++ b/SQLFormatter.tableplusplugin/package.json @@ -1,10 +1,10 @@ { "name": "com.tinyapp.TablePlus.SQLFormatter.tableplusplugin", - "version": "1.0.0", + "version": "1.0.1", "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", From 5b509d32d904271c1f0bd80606f3a3d695e88a03 Mon Sep 17 00:00:00 2001 From: sonswift Date: Sat, 16 Nov 2024 11:07:31 +0700 Subject: [PATCH 2/2] Bump version 1.1 --- SQLFormatter.tableplusplugin/manifest.json | 2 +- SQLFormatter.tableplusplugin/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SQLFormatter.tableplusplugin/manifest.json b/SQLFormatter.tableplusplugin/manifest.json index dcff507..73194d8 100755 --- a/SQLFormatter.tableplusplugin/manifest.json +++ b/SQLFormatter.tableplusplugin/manifest.json @@ -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": "nick@tableplus.com", diff --git a/SQLFormatter.tableplusplugin/package.json b/SQLFormatter.tableplusplugin/package.json index 6cb022d..ea71796 100755 --- a/SQLFormatter.tableplusplugin/package.json +++ b/SQLFormatter.tableplusplugin/package.json @@ -1,6 +1,6 @@ { "name": "com.tinyapp.TablePlus.SQLFormatter.tableplusplugin", - "version": "1.0.1", + "version": "1.0.0", "description": "This plugin helps fill your empty table with funny text and quote for testing purpose", "main": "main.js", "dependencies": {