# SQL Formatter Pre-Commit Hook
This repository includes a pre-configured pre-commit hook to automatically format SQL and PL/SQL files before each commit, ensuring consistent code style across the project. It leverages Trivadis' advanced format settings for alignment, spacing, and other formatting standards.
## Features
- **Automatic Formatting**: Formats SQL files with specified extensions to maintain code consistency.
- **Supported File Types**: Includes common SQL and PL/SQL file extensions such as `.sql`, `.prc`, `.fnc`, `.pks`, `.pkb`, `.trg`, `.pls`, and more.
- **Configurable Settings**: Uses `trivadis_advanced_format.xml` for advanced formatting configurations, which can be customized as needed.
- **Flexible SQLcl Path**: Allows specifying the SQLcl path using the `SQL_PROGRAM` environment variable.
## Requirements
### SQLcl
This pre-commit hook requires Oracle SQLcl (SQL Command Line) to perform SQL formatting. SQLcl provides powerful SQL scripting and formatting capabilities. Follow these steps to download and install it:
- **Download SQLcl**: The latest version can be downloaded from [Oracle SQLcl Downloads](https://www.oracle.com/database/sqldeveloper/technologies/sqlcl/download/).
- **Install SQLcl**: Refer to the [installation guide](https://docs.oracle.com/en/database/oracle/sqlcl/19.4/sclsg/installing-and-getting-started-with-sqlcl.html) if needed.
#### Optional: Set SQLcl Path
If SQLcl is not in your system PATH or if you want to specify a custom path, set the `SQL_PROGRAM` environment variable to the path of the `sql` binary. For example:
```bash
export SQL_PROGRAM="/path/to/sqlcl/bin/sql"
```
### Git
Ensure Git is installed as this pre-commit hook uses Git’s pre-commit hook system.
## Installation
To use this hook with `pre-commit`, add it to your `.pre-commit-config.yaml` file in the target repository. Here’s an example configuration:
```yaml
# .pre-commit-config.yaml
repos:
- repo: https://github.com/GentleGhostCoder/oracle-formatter-pre-commit-hook # Replace with your GitHub repo URL
rev: v1.0.0 # Use a tag, branch name, or commit SHA
hooks:
- id: oracle-formatter-hook
```
Then, install the hook by running:
```bash
pre-commit install
```
This command sets up the pre-commit hook to run automatically before each commit.
## How It Works
1. **Identify Relevant Files**: The hook detects files based on specified extensions.
2. **Format Files**: Each identified file is formatted using `formatter/format.js` via SQLcl, applying the settings in `trivadis_advanced_format.xml`.
## Usage
1. **Stage SQL Files**: Stage files for commit using `git add`.
2. **Commit Changes**: Commit staged files with `git commit`. The pre-commit hook will automatically format applicable files.
### Running Manually with `--all-files`
To format all files, not just staged files, you can run the pre-commit hook manually:
```bash
pre-commit run --all-files
```
This triggers the formatting of all files matching the specified extensions in the repository.
### Manual Formatting with the Python Entry Point
To manually format files without running the pre-commit hook, use the `orafmt` command directly if your module is installed:
```bash
orafmt file1.sql file2.sql
```
Alternatively, you can use the Python script directly:
```bash
python3 -m orafmt file1.sql file2.sql
```
This command will format the specified files according to the configurations.
## Advanced Configuration
To modify formatting settings, edit the `trivadis_advanced_format.xml` file. These options allow customization of alignment, line breaks, and spacing based on project needs.
## License
This formatter uses Trivadis PL/SQL Formatter, licensed under the Apache License, Version 2.0.
The pre-commit hook itself is also available under the Apache License, Version 2.0.
Raw data
{
"_id": null,
"home_page": "https://github.com/YourUsername/orafmt",
"name": "orafmt",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": "oracle, sql, formatter, pre-commit, sqlcl",
"author": "Semjon Geist",
"author_email": "mail@semjon-geist.de",
"download_url": "https://files.pythonhosted.org/packages/87/a3/18ae57aabeaeb6e288a0ee6bf105418100d4181a5be98cb1f42f2fe977d7/orafmt-1.0.2.tar.gz",
"platform": null,
"description": "# SQL Formatter Pre-Commit Hook\n\nThis repository includes a pre-configured pre-commit hook to automatically format SQL and PL/SQL files before each commit, ensuring consistent code style across the project. It leverages Trivadis' advanced format settings for alignment, spacing, and other formatting standards.\n\n## Features\n\n- **Automatic Formatting**: Formats SQL files with specified extensions to maintain code consistency.\n- **Supported File Types**: Includes common SQL and PL/SQL file extensions such as `.sql`, `.prc`, `.fnc`, `.pks`, `.pkb`, `.trg`, `.pls`, and more.\n- **Configurable Settings**: Uses `trivadis_advanced_format.xml` for advanced formatting configurations, which can be customized as needed.\n- **Flexible SQLcl Path**: Allows specifying the SQLcl path using the `SQL_PROGRAM` environment variable.\n\n## Requirements\n\n### SQLcl\n\nThis pre-commit hook requires Oracle SQLcl (SQL Command Line) to perform SQL formatting. SQLcl provides powerful SQL scripting and formatting capabilities. Follow these steps to download and install it:\n\n- **Download SQLcl**: The latest version can be downloaded from [Oracle SQLcl Downloads](https://www.oracle.com/database/sqldeveloper/technologies/sqlcl/download/).\n- **Install SQLcl**: Refer to the [installation guide](https://docs.oracle.com/en/database/oracle/sqlcl/19.4/sclsg/installing-and-getting-started-with-sqlcl.html) if needed.\n\n#### Optional: Set SQLcl Path\n\nIf SQLcl is not in your system PATH or if you want to specify a custom path, set the `SQL_PROGRAM` environment variable to the path of the `sql` binary. For example:\n\n```bash\nexport SQL_PROGRAM=\"/path/to/sqlcl/bin/sql\"\n```\n\n### Git\n\nEnsure Git is installed as this pre-commit hook uses Git\u2019s pre-commit hook system.\n\n## Installation\n\nTo use this hook with `pre-commit`, add it to your `.pre-commit-config.yaml` file in the target repository. Here\u2019s an example configuration:\n\n```yaml\n# .pre-commit-config.yaml\nrepos:\n- repo: https://github.com/GentleGhostCoder/oracle-formatter-pre-commit-hook # Replace with your GitHub repo URL\n rev: v1.0.0 # Use a tag, branch name, or commit SHA\n hooks:\n - id: oracle-formatter-hook\n```\n\nThen, install the hook by running:\n\n```bash\npre-commit install\n```\n\nThis command sets up the pre-commit hook to run automatically before each commit.\n\n## How It Works\n\n1. **Identify Relevant Files**: The hook detects files based on specified extensions.\n2. **Format Files**: Each identified file is formatted using `formatter/format.js` via SQLcl, applying the settings in `trivadis_advanced_format.xml`.\n\n## Usage\n\n1. **Stage SQL Files**: Stage files for commit using `git add`.\n2. **Commit Changes**: Commit staged files with `git commit`. The pre-commit hook will automatically format applicable files.\n\n### Running Manually with `--all-files`\n\nTo format all files, not just staged files, you can run the pre-commit hook manually:\n\n```bash\npre-commit run --all-files\n```\n\nThis triggers the formatting of all files matching the specified extensions in the repository.\n\n### Manual Formatting with the Python Entry Point\n\nTo manually format files without running the pre-commit hook, use the `orafmt` command directly if your module is installed:\n\n```bash\norafmt file1.sql file2.sql\n```\n\nAlternatively, you can use the Python script directly:\n\n```bash\npython3 -m orafmt file1.sql file2.sql\n```\n\nThis command will format the specified files according to the configurations.\n\n## Advanced Configuration\n\nTo modify formatting settings, edit the `trivadis_advanced_format.xml` file. These options allow customization of alignment, line breaks, and spacing based on project needs.\n\n## License\n\nThis formatter uses Trivadis PL/SQL Formatter, licensed under the Apache License, Version 2.0. \nThe pre-commit hook itself is also available under the Apache License, Version 2.0.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python tool for formatting Oracle SQL files with SQLcl and custom formatting options.",
"version": "1.0.2",
"project_urls": {
"Homepage": "https://github.com/YourUsername/orafmt",
"Repository": "https://github.com/YourUsername/orafmt"
},
"split_keywords": [
"oracle",
" sql",
" formatter",
" pre-commit",
" sqlcl"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6258909dd5fb808b22b6064703bbddf3558682ba4a1cc1c86fcafb5124dfa5ca",
"md5": "d895f202d0130f1e9087a697f8cdf830",
"sha256": "6ad34d38a4a40ab34695d3853c571cabb392f88c15d9ad9eb7ba0ef4eddc547b"
},
"downloads": -1,
"filename": "orafmt-1.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d895f202d0130f1e9087a697f8cdf830",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 48849,
"upload_time": "2024-11-22T12:44:08",
"upload_time_iso_8601": "2024-11-22T12:44:08.356123Z",
"url": "https://files.pythonhosted.org/packages/62/58/909dd5fb808b22b6064703bbddf3558682ba4a1cc1c86fcafb5124dfa5ca/orafmt-1.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "87a318ae57aabeaeb6e288a0ee6bf105418100d4181a5be98cb1f42f2fe977d7",
"md5": "9a1c2322d611a1ca1cacb9f7a2fc0e27",
"sha256": "24d43a0c9aebc7d3f02bb05fdb977b938d9a36097b9d6fa57d4ea0d579b33400"
},
"downloads": -1,
"filename": "orafmt-1.0.2.tar.gz",
"has_sig": false,
"md5_digest": "9a1c2322d611a1ca1cacb9f7a2fc0e27",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 46570,
"upload_time": "2024-11-22T12:44:11",
"upload_time_iso_8601": "2024-11-22T12:44:11.467895Z",
"url": "https://files.pythonhosted.org/packages/87/a3/18ae57aabeaeb6e288a0ee6bf105418100d4181a5be98cb1f42f2fe977d7/orafmt-1.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-22 12:44:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "YourUsername",
"github_project": "orafmt",
"github_not_found": true,
"lcname": "orafmt"
}