{"id":43903,"library":"sql-formatter-with-sql-server","title":"SQL Formatter with SQL Server support","description":"A JavaScript library for pretty-printing SQL queries, forked to add SQL Server dialect support. Current stable version is 1.0.2. Low release cadence (last update 2020). Key differentiators: supports Standard SQL, N1QL, DB2, Oracle PL/SQL, and now SQL Server; parameter placeholder replacement; works in Node.js and browsers. Alternatives like prettier-plugin-sql have broader community but this fork fills the gap for T-SQL formatting.","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/akbar1991ali/sql-formatter","tags":["javascript","sql","formatter","format","n1ql","whitespaces"],"install":[{"cmd":"npm install sql-formatter-with-sql-server","lang":"bash","label":"npm"},{"cmd":"yarn add sql-formatter-with-sql-server","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-formatter-with-sql-server","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default ESM export. CommonJS require() may work in Node but is not officially supported.","wrong":"const sqlFormatter = require('sql-formatter-with-sql-server')","symbol":"sqlFormatter","correct":"import sqlFormatter from 'sql-formatter-with-sql-server'"},{"note":"The default export is an object with a format method, not a named export.","wrong":"import { format } from 'sql-formatter-with-sql-server'","symbol":"format (default)","correct":"import sqlFormatter from 'sql-formatter-with-sql-server'; sqlFormatter.format(...)"},{"note":"When used via script tag, the library is exposed as window.sqlFormatter.","wrong":"import sqlFormatter from 'sql-formatter-with-sql-server'","symbol":"sqlFormatter (script tag)","correct":"<script src='dist/sql-formatter.min.js'></script>; window.sqlFormatter.format(...)"}],"quickstart":{"code":"import sqlFormatter from 'sql-formatter-with-sql-server';\n\nconst formatted = sqlFormatter.format(\"SELECT a, b, c FROM tbl WHERE a = 1 AND b = 2\", {\n  language: 'sql',\n  indent: '    '\n});\n\nconsole.log(formatted);\n// Output:\n// SELECT\n//     a,\n//     b,\n//     c\n// FROM\n//     tbl\n// WHERE\n//     a = 1\n//     AND b = 2","lang":"javascript","description":"Demonstrates basic SQL formatting with custom indent and a multi-line query using the default export."},"warnings":[{"fix":"Use underyling 'sql' dialect as fallback or open an issue on GitHub.","message":"SQL Server dialect may not handle all T-SQL syntax (e.g., GO, DECLARE). Test extensively.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always specify language explicitly: { language: 'sql' }","message":"The default language option might become deprecated in future versions as more dialects are added.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use dynamic import or switch to ESM syntax: import sqlFormatter from 'sql-formatter-with-sql-server'","message":"CommonJS require() may not work if the package is used in a strict ESM environment (e.g., Node with \"type\": \"module\").","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.2':27 '2020':33 'add':18 'altern':55 'broader':62 'browser':54 'cadenc':30 'communiti':63 'current':23 'db2':40 'dialect':21 'differenti':35 'fill':67 'fork':16,66 'format':74,78 'formatt':2,77 'gap':69 'javascript':8,75 'key':34 'last':31 'librari':9 'like':56 'low':28 'n1ql':39,79 'node.js':52 'oracl':41 'paramet':47 'pl/sql':42 'placehold':48 'plugin':59 'pretti':12 'prettier':58 'prettier-plugin-sql':57 'pretty-print':11 'print':13 'queri':15 'releas':29 'replac':49 'server':5,20,46 'sql':1,4,14,19,38,45,60,73,76 'stabl':24 'standard':37 'support':6,22,36 't-sql':71 'updat':32 'version':25 'whitespac':80 'work':50","created_at":"2026-06-05T17:02:01.917694+00:00","updated_at":"2026-06-05T17:02:01.917694+00:00","problems":[{"fix":"Run 'npm install sql-formatter-with-sql-server' and require/import with exact name.","cause":"Package not installed or misspelled (note the 'sql-formatter-with-sql-server' name).","error":"Cannot find module 'sql-formatter-with-sql-server'"},{"fix":"Use 'import sqlFormatter from ...' then call sqlFormatter.format(...)","cause":"Incorrect import: default export is an object, not a function.","error":"TypeError: sqlFormatter.format is not a function"},{"fix":"Ensure the dist file is loaded before use. The global is 'sqlFormatter', not 'SqlFormatter'.","cause":"Using script tag without loading the file, or global variable name mismatch.","error":"Uncaught ReferenceError: sqlFormatter is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/akbar1991ali/sql-formatter#readme","github":"https://github.com/akbar1991ali/sql-formatter","docs":null,"changelog":null,"pypi":null,"npm":"sql-formatter-with-sql-server","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}