{"id":15409554,"url":"https://github.com/bradymholt/psqlformat","last_synced_at":"2025-04-15T03:54:05.769Z","repository":{"id":29084129,"uuid":"117386442","full_name":"bradymholt/psqlformat","owner":"bradymholt","description":"A PostgreSQL SQL syntax formatter","archived":false,"fork":false,"pushed_at":"2025-03-25T13:09:15.000Z","size":566,"stargazers_count":7,"open_issues_count":1,"forks_count":9,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T03:53:58.251Z","etag":null,"topics":["formatter","postgresql","sql"],"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/bradymholt.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}},"created_at":"2018-01-13T23:23:33.000Z","updated_at":"2025-03-25T13:09:19.000Z","dependencies_parsed_at":"2025-03-24T16:43:34.803Z","dependency_job_id":null,"html_url":"https://github.com/bradymholt/psqlformat","commit_stats":{"total_commits":191,"total_committers":11,"mean_commits":"17.363636363636363","dds":"0.23560209424083767","last_synced_commit":"ab484f5d1125717f59a93e0c8e785a7b7485b48d"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradymholt%2Fpsqlformat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradymholt%2Fpsqlformat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradymholt%2Fpsqlformat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradymholt%2Fpsqlformat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bradymholt","download_url":"https://codeload.github.com/bradymholt/psqlformat/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249003955,"owners_count":21196794,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["formatter","postgresql","sql"],"created_at":"2024-10-01T16:40:36.415Z","updated_at":"2025-04-15T03:54:05.752Z","avatar_url":"https://github.com/bradymholt.png","language":"TypeScript","readme":"# psqlformat [![Build](https://github.com/bradymholt/psqlformat/actions/workflows/build.yml/badge.svg)](https://github.com/bradymholt/psqlformat/actions/workflows/build.yml) [![NPM Package](https://img.shields.io/npm/v/psqlformat.svg)](https://www.npmjs.com/package/psqlformat)\n\n\u003cimg align=\"left\" src=\"https://user-images.githubusercontent.com/759811/210273710-b13913e2-0a71-4d9d-94da-1fe538b8a73e.gif\"/\u003e\n\n\u003cbr/\u003e\n\n \u0026nbsp;**Would you take a quick second and ⭐️ my repo?**\n\n\u003cbr/\u003e\n\nA PostgreSQL SQL syntax formatter that supports a CLI and library / module interface.\n\nThis package is a wrapper for [darold/pgFormatter](https://github.com/darold/pgFormatter) and requires Perl to be available.\n\n## Command Line Interface\n\nTo run psqlformat on Node.js, install it first with the following command:\n\n```\nnpm i -g psqlformat\n```\n\nTo run it, use this command format:\n\n```\npsqlformat [options] [file|dir|glob]*\n```\n\nExamples:\n\n```\npsqlformat --write --spaces=2 query.sql\npsqlformat --commaEnd --spaces=4 \"db/*.sql\"\npsqlformat --commaEnd --spaces=4 \"db/**/*.sql\"\n```\n\nWhen passing a glob as a parameter, it will be expanded by your shell.  If you want to use node glob syntax, you have to quote your parameter (using double quotes if you need it to run in Windows), as follows:\n\n```\npsqlformat --noComment \"db/**\"\n```\n\n### npx\n\nBundled with npm starting in version 5.2, the [npx](https://github.com/zkat/npx) tool can be used to run psqlformat without installing it globally.  If you have installed psqlformat locally (npm install psqlformat), npx will use the installed version and if you have not installed it, the latest version will be pulled down and used automatically.  To use this tool, simply prefix psqlformat with `npx` like this:\n\n```\nnpx psqlformat --write --spaces=2 query.sql\n```\n\n### Options\n\nThe command line utility has several options. You can view the options by running `psqlformat -h`.\n\n```\nUsage: bin.ts [options] \u003cfile/glob ...\u003e\n\nBy default, output is written to stdout. (use --write option to edit files\nin-place)\n\n\nOptions:\n  --help             Show help                                         [boolean]\n  --version          Show version number                               [boolean]\n  --write            Edit files in-place. (Beware!)                    [boolean]\n  --spaces           Number of spaces to indent the code   [number] [default: 4]\n  --tabs             Use tabs instead of spaces (spaces option is ignored)\n                                                                       [boolean]\n  --maxLength        Maximum length of a query                          [number]\n  --commaStart       Use preceding comma in parameter list             [boolean]\n  --commaBreak       In insert statement, add a newline after each comma\n                                                                       [boolean]\n  --commaEnd         Use trailing comma in parameter list\n                                                       [boolean] [default: true]\n  --noComment        Remove any comments                               [boolean]\n  --noGrouping       Add a newline between statements in transaction\n                     regroupement                     [boolean] [default: false]\n  --functionCase     Case to use for function names\n         [string] [choices: \"unchanged\", \"lowercase\", \"uppercase\", \"capitalize\"]\n                                                          [default: \"unchanged\"]\n  --keywordCase      Case to use for reserved keywords\n         [string] [choices: \"unchanged\", \"lowercase\", \"uppercase\", \"capitalize\"]\n                                                          [default: \"uppercase\"]\n  --typeCase         Case to use for data type names\n         [string] [choices: \"unchanged\", \"lowercase\", \"uppercase\", \"capitalize\"]\n                                                          [default: \"lowercase\"]\n  --formatType       Use another formatting type for some statements   [boolean]\n  --wrapLimit        Wrap queries at a certain length                   [number]\n  --wrapComment      When wrapLimit is true, apply formatting to comments\n                                                                       [boolean]\n  --placeholder      Regex to find code that must not be changed        [string]\n  --extraFunction    Path to file containing a list of function names   [string]\n  --noSpaceFunction  Remove the space character between a function call and the\n                     open parenthesis that follows                     [boolean]\n  --configFile       Specify a pg_format config file                    [string]\n  --perlBinPath      The path to the perl executable  [string] [default: \"perl\"]\n  --pgFormatterPath  Path to a custom pg_format version                 [string]\n  --keepNewline      Preserve empty lines             [boolean] [default: false]\n  --noExtraLine      Do not add an extra empty line at end of formatted output\n                                                                       [boolean]\n  --chunkSize        How many files to pass to pgFormatter at once\n                                                        [number] [default: \"25\"]\n```\n\n## Module usage\n\npsqlformat can also be used as a module so that it can be integrated into an existing project.  Simply install it locally like this:\n\n```\nnpm install psqlformat\n```\n\nThen, require it with `require(\"psqlformat\")` and use either the `formatSql` or `formatFiles` method.  Here are the method signatures in TypeScript declaration file format:\n\n```\n/**\n *\n * @param fileOrGlob The file path or glob to use (i.e. /tmp/query.sql or *.sql)\n * @param options\n */\nexport declare function formatFiles(filesOrGlobs: string | string[], editInPlace: boolean, options?: IOptions, log?: (text: string) =\u003e void): string;\n\n/**\n * Format SQL\n * @param sqlText The SQL to be formatted\n * @param options\n */\nexport declare function formatSql(sqlText: string, options?: IOptions): string;\n\n```\n\nExample usage:\n\n```\nconst psqlformat = require(\"psqlformat\");\n\n// Format SQL text\nlet formatted = psqlformat.formatSql(\"select id from people\", {\n  spaces: 2\n \n  /* Other available options:\n  maxLength\n  commaStart\n  commaBreak\n  commaEnd\n  noComment\n  functionCase\n  keywordCase\n  formatType\n  placeholder\n  extraFunction\n  configFile\n  perlBinPath\n  pgFormatterPath\n  */\n});\n\nconsole.log(formatted);\n\n/* Expected Output:\nSELECT\n  id\nFROM\n  people\n*/\n\n// Format a file\nconst path = require(\"path\");\npsqlformat.formatFiles(path.resolve(__dirname, \"query.sql\"), true, {    \n  spaces: 3 \n});\n\n// query.sql file should have been edited in-place.\n```\n\n### TypeScript\n\npsqlformat is written using TypeScript and has declaration files (`.d.ts`) available so that if you are using TypeScript in your own project,\nyou can import psqlformat.  The entry declaration file, dist/index.d.ts, is specified in package.json file under the \"types\" field and should automatically be recognized by the TypeScript compiler.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbradymholt%2Fpsqlformat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbradymholt%2Fpsqlformat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbradymholt%2Fpsqlformat/lists"}