{"id":25940501,"url":"https://github.com/minfhs/pgformat","last_synced_at":"2026-05-11T17:35:03.654Z","repository":{"id":277253155,"uuid":"923988787","full_name":"minfhs/pgformat","owner":"minfhs","description":"Highly opinionated PostgreSQL formatter","archived":false,"fork":false,"pushed_at":"2025-10-18T00:05:36.000Z","size":45,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-01T17:45:45.901Z","etag":null,"topics":["formatter","postgres","sql"],"latest_commit_sha":null,"homepage":"","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/minfhs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-01-29T07:53:24.000Z","updated_at":"2025-10-18T00:04:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"a70384a7-fa5c-4280-af3a-f6ff67c21ec2","html_url":"https://github.com/minfhs/pgformat","commit_stats":null,"previous_names":["minfhs/pgformat"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/minfhs/pgformat","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minfhs%2Fpgformat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minfhs%2Fpgformat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minfhs%2Fpgformat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minfhs%2Fpgformat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/minfhs","download_url":"https://codeload.github.com/minfhs/pgformat/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minfhs%2Fpgformat/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32906274,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-11T17:09:15.040Z","status":"ssl_error","status_checked_at":"2026-05-11T17:08:45.420Z","response_time":120,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["formatter","postgres","sql"],"created_at":"2025-03-04T05:16:55.065Z","updated_at":"2026-05-11T17:35:03.639Z","avatar_url":"https://github.com/minfhs.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pgformat - PostgreSQL Formatter\n\nAn opinionated PostgreSQL code formatter built in OCaml with configurable formatting options.\n\n## Features\n\n✨ **Smart SQL Formatting**\n\n- Consistent indentation and line breaks\n- Proper comma placement and spacing\n- Function and procedure formatting\n- Complex query structure normalization\n\n🔧 **Configurable Options**\n\n- Customizable indentation size\n- Adjustable line length limits\n- Boolean formatting preferences\n- Project-level configuration files\n\n🚀 **Multiple Interfaces**\n\n- Command-line tool with rich options\n- VS Code extension support\n- Editor integrations (Helix, etc.)\n- Programmatic FormatterBuilder API\n\n## Installation\n\n### Quick Install\n\n```bash\njust up\njust install # installs to /usr/local/bin\n```\n\n### From Source\n\n```bash\ndune build\ndune install\n```\n\n## Usage\n\n### Basic Command Line\n\n```bash\n# Format a file\npgformat myfile.sql\n\n# Format from stdin\necho \"SELECT a,b FROM users;\" | pgformat\n\n# Format with custom indentation\npgformat myfile.sql -indent-size 2\n\n# Format with custom line length\npgformat myfile.sql -max-line-length 80\n```\n\n### Configuration File\n\nCreate a `.pgformat` file in your project root for consistent formatting:\n\n```ini\n# .pgformat configuration file\nindent-size = 2\nmax-line-length = 80\nnewline-after-semicolon = true\nspace-after-comma = true\n```\n\nCommand-line options override config file settings.\n\n### Help\n\n```bash\npgformat --help\n```\n\n## Editor Integration\n\n### VS Code\n\nInstall the pgformat extension following this [guide](./.vscode/README.md).\n\n### Helix\n\nAdd to your `languages.toml`:\n\n```toml\n[[language]]\nname = \"sql\"\nauto-format = true\nformatter = { command = \"pgformat\" }\n```\n\nCheck with `hx --health sql`.\n\n### Other Editors\n\npgformat works with any editor that supports external formatters. Configure your editor to run `pgformat` on SQL files.\n\n## Configuration Options\n\n| Option                    | Type    | Default | Description                            |\n| ------------------------- | ------- | ------- | -------------------------------------- |\n| `indent-size`             | integer | 4       | Number of spaces per indentation level |\n| `max-line-length`         | integer | 120     | Maximum line length before wrapping    |\n| `newline-after-semicolon` | boolean | true    | Add newline after semicolons           |\n| `space-after-comma`       | boolean | true    | Add space after commas                 |\n\n### Configuration Precedence\n\n1. Command-line arguments (highest priority)\n2. `.pgformat` file in current directory\n3. Default values (fallback)\n\n## Sample Output\n\n### Before\n\n```sql\nSELECT     , reviews.room_id , reviews.user_id , reviews.state AS \"state: ReviewState\"\n    , applicants.state AS \"applicant_state: ApplicantState\"\nFROM applicant_reviews AS reviews LEFT JOIN (\n    SELECT id , fhs_id , state FROM applicants ) AS applicants ON applicants.id\n    = reviews.applicant_id\nWHERE\n    reviews.room_id = ( SELECT id FROM rooms\n        WHERE abbr = $1 AND y = x )\n    AND applicants.state IS NOT NULL AND applicants.fhs_id IS NOT NULL;\n```\n\n### After\n\n```sql\nSELECT\n    reviews.id AS id\n    , applicants.fhs_id AS fhs_id\n    , applicants.id AS applicant_id\n    , reviews.room_id\n    , reviews.user_id\n    , reviews.state AS \"state: ReviewState\"\n    , applicants.state AS \"applicant_state: ApplicantState\"\nFROM applicant_reviews AS reviews\nLEFT JOIN (\n    SELECT\n        id\n        , fhs_id\n        , state\n    FROM applicants\n) AS applicants ON applicants.id = reviews.applicant_id\nWHERE\n    reviews.room_id = (\n        SELECT\n            id\n        FROM rooms\n        WHERE\n            abbr = $1\n            AND y = x\n    )\n    AND applicants.state IS NOT NULL\n    AND applicants.fhs_id IS NOT NULL;\n```\n\n## Development\n\n### Running Tests\n\n```bash\n# Run all tests\ndune runtest\n\n# Run tests in watch mode\ndune runtest -w\n\n# Run specific test\ndune runtest test/\n```\n\n### Testing the Formatter\n\n```bash\n# Test on fixture files\ndune exec bin/main.exe fixture/complex.sql\n\n# Test with different configurations\necho \"SELECT a,b FROM users;\" | dune exec bin/main.exe -- -indent-size 2\n```\n\n### Building\n\n```bash\n# Build library and executables\ndune build\n\n# Build in watch mode\ndune build -w\n```\n\n## Architecture\n\npgformat uses a modular architecture with:\n\n- **Lexer**: Tokenizes SQL input\n- **Parser**: Processes tokens with formatting rules\n- **Formatters**: Specialized modules for different token types\n  - Comment Formatter\n  - Keyword Formatter\n  - Literal Formatter\n  - Punctuation Formatter\n- **Builder Pattern**: Configurable formatter construction\n- **Output Interface**: Pluggable output destinations\n\n### FormatterBuilder API\n\nFor programmatic use:\n\n```ocaml\nopen Pgformat\n\nlet config = { Config.default_config with indent_size = 2 } in\nlet builder = Builder.FormatterBuilder.create ()\n  |\u003e Builder.FormatterBuilder.with_indent_size config.indent_size\n  |\u003e Builder.FormatterBuilder.with_max_line_length config.max_line_length in\nBuilder.FormatterBuilder.format_with_config builder lexbuf\n```\n\n## Examples\n\nCheck the [fixture](./fixture) directory for formatted examples demonstrating various SQL constructs:\n\n- `complex.sql` - Complex queries with functions and nested structures\n- `create.sql` - Table creation statements\n- `select.sql` - Various SELECT query patterns\n- `select_simple.sql` - Basic SELECT statements\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes with tests\n4. Ensure all tests pass: `dune runtest`\n5. Submit a pull request\n\n## License\n\nThis project is licensed under the terms specified in the repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fminfhs%2Fpgformat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fminfhs%2Fpgformat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fminfhs%2Fpgformat/lists"}