{"id":34973113,"url":"https://github.com/harryplusplus/prettier-plugin-sql-exec","last_synced_at":"2026-05-24T04:34:33.437Z","repository":{"id":321165889,"uuid":"1084697626","full_name":"harryplusplus/prettier-plugin-sql-exec","owner":"harryplusplus","description":"A Prettier plugin for extensible SQL formatting via any command-line formatter.","archived":false,"fork":false,"pushed_at":"2025-11-27T19:25:48.000Z","size":205,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-02T05:08:07.044Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/harryplusplus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-28T03:18:58.000Z","updated_at":"2025-10-29T00:51:59.000Z","dependencies_parsed_at":"2025-10-28T07:17:00.666Z","dependency_job_id":"499c515d-aa9c-4ba7-9e12-93ba192a44ab","html_url":"https://github.com/harryplusplus/prettier-plugin-sql-exec","commit_stats":null,"previous_names":["harryplusplus/prettier-plugin-sql-exec"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/harryplusplus/prettier-plugin-sql-exec","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harryplusplus%2Fprettier-plugin-sql-exec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harryplusplus%2Fprettier-plugin-sql-exec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harryplusplus%2Fprettier-plugin-sql-exec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harryplusplus%2Fprettier-plugin-sql-exec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harryplusplus","download_url":"https://codeload.github.com/harryplusplus/prettier-plugin-sql-exec/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harryplusplus%2Fprettier-plugin-sql-exec/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33421781,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-23T22:14:44.296Z","status":"online","status_checked_at":"2026-05-24T02:00:06.296Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-26T23:53:27.919Z","updated_at":"2026-05-24T04:34:33.432Z","avatar_url":"https://github.com/harryplusplus.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# prettier-plugin-sql-exec\n\nA Prettier plugin for extensible SQL formatting via any command-line formatter.\n\n[![npm version](https://img.shields.io/npm/v/prettier-plugin-sql-exec)](https://www.npmjs.com/package/prettier-plugin-sql-exec)\n\n## Table of Contents\n\n\u003c!-- toc --\u003e\n\n- [Why I Created This Library](#why-i-created-this-library)\n- [Usage](#usage)\n  - [Example](#example)\n- [Options](#options)\n  - [`sqlExecCommand`](#sqlexeccommand)\n- [Development](#development)\n  - [Integration Tests](#integration-tests)\n- [License](#license)\n\n\u003c!-- tocstop --\u003e\n\n## Why I Created This Library\n\nFor most projects, using [prettier-plugin-embed](https://www.npmjs.com/package/prettier-plugin-embed) together with [prettier-plugin-sql](https://www.npmjs.com/package/prettier-plugin-sql) can be sufficient for formatting embedded SQL in TypeScript.\n\nHowever, those plugins did not fully support my PL/pgSQL syntax requirements and often produced results that weren't visually pleasing.\n\nWhen formatting SQL blocks inside TypeScript code, the embedded SQL should be indented both according to its own structure and by the indentation level already present in the TypeScript source—but [pgFormatter](https://github.com/darold/pgFormatter) alone was unable to consistently apply this extra indentation.\n\nTo avoid tying this library to the ongoing maintenance cycles of external formatters, or evolving it into an overly general-purpose solution, I chose a direct command execution model. This does introduce some shell execution overhead.\n\nBut in practice, this overhead is minimal because embedded SQL template blocks in my projects are typically limited to repository, utility, or other specialized files. Regular application and service code rarely trigger the formatter, so the performance impact remains strictly local and manageable.\n\n## Usage\n\n### Example\n\nThis example demonstrates how to use [VS Code Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) and prettier-plugin-embed to format SQL template strings in TypeScript files via pgFormatter.\n\nInstall the required packages:\n\n```bash\n# Formatting plugins\npnpm add -D prettier prettier-plugin-embed prettier-plugin-sql-exec\n# PostgreSQL client\npnpm add postgres\n```\n\n\u003e [!NOTE]  \n\u003e This example uses pnpm, but other package managers work as well.\n\nClone pgFormatter:\n\n```bash\ngit clone --branch v5.8 --depth 1 https://github.com/darold/pgFormatter.git\n```\n\n\u003e [!NOTE]  \n\u003e pgFormatter requires a Perl runtime.\n\u003e Perl is included by default on macOS.\n\nSample Prettier config (.prettierrc.json):\n\n```json\n{\n  \"plugins\": [\"prettier-plugin-embed\", \"prettier-plugin-sql-exec\"],\n  \"sqlExecCommand\": \"perl pgFormatter/pg_format\"\n}\n```\n\nTypeScript before formatting:\n\n```typescript\nimport postgres from \"postgres\";\n\nconst sql = postgres();\n\nconst name = \"John Doe\";\nconst age = 30;\n\nconst users =\n  await sql`INSERT INTO users(name, age) VALUES (${name}, ${age}) RETURNING name, age`;\n```\n\nAfter formatting:\n\n```typescript\nimport postgres from \"postgres\";\n\nconst sql = postgres();\n\nconst name = \"John Doe\";\nconst age = 30;\n\nconst users = await sql`\n  INSERT INTO users (name, age)\n      VALUES (${name}, ${age})\n  RETURNING\n      name, age\n`;\n```\n\n## Options\n\n### `sqlExecCommand`\n\n_**(required)**_\n\nFormatting command to execute.\n\nIt must take input from **STDIN** and output the formatted text to **STDOUT**, then **exit**.\nIf your formatter doesn’t support this or needs **environment variables** set, wrap it with a simple shell script, Node.js, or Python script.\n\nThe command’s working directory is resolved from the `PWD` environment variable if present; otherwise, the default value (`process.cwd()`) is used.\nWithin the VS Code Prettier extension service, `process.cwd()` is always set to `\"/\"`, while the actual project path is provided through the `PWD` environment variable.\n\n## Development\n\n### Integration Tests\n\nRun the following commands to execute integration tests:\n\n```bash\n# Build the project before running tests\npnpm build\n\n# Ensure all submodules are up to date\ngit submodule update --init --recursive\n\n# Run integration tests\npnpm test:integration\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharryplusplus%2Fprettier-plugin-sql-exec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharryplusplus%2Fprettier-plugin-sql-exec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharryplusplus%2Fprettier-plugin-sql-exec/lists"}