{"id":17359793,"url":"https://github.com/mvisani/sql-minifier","last_synced_at":"2025-04-15T00:31:25.548Z","repository":{"id":231694861,"uuid":"782459480","full_name":"mvisani/SQL-minifier","owner":"mvisani","description":"Crate providing methods and procedural macros to minify SQL code, optionally at compile time.","archived":false,"fork":false,"pushed_at":"2024-06-13T09:00:29.000Z","size":55,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-08T10:22:32.584Z","etag":null,"topics":["rust","sql"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/sql_minifier","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mvisani.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":"2024-04-05T10:50:07.000Z","updated_at":"2025-01-05T15:50:50.000Z","dependencies_parsed_at":"2024-04-08T09:27:29.898Z","dependency_job_id":"e4ca22a2-ff1b-4c79-833b-0c7796a179da","html_url":"https://github.com/mvisani/SQL-minifier","commit_stats":null,"previous_names":["mvisani/sql-minifier"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvisani%2FSQL-minifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvisani%2FSQL-minifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvisani%2FSQL-minifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvisani%2FSQL-minifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mvisani","download_url":"https://codeload.github.com/mvisani/SQL-minifier/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248984231,"owners_count":21193712,"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":["rust","sql"],"created_at":"2024-10-15T19:12:18.159Z","updated_at":"2025-04-15T00:31:25.274Z","avatar_url":"https://github.com/mvisani.png","language":"Rust","readme":"# SQL minifier\n[![Build status](https://github.com/mvisani/SQL-minifier/actions/workflows/build.yml/badge.svg)](https://github.com/mvisani/SQL-minifier/actions)\n[![Crates.io](https://img.shields.io/crates/v/SQL-minifier.svg)](https://crates.io/crates/SQL-minifier)\n[![Documentation](https://docs.rs/sql_minifier/badge.svg)](https://docs.rs/sql_minifier)\n[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)\n\n[SQL minifier](https://github.com/mvisani/SQL-minifier) provides methods and procedural macros to minify SQL code, optionally at compile time.\nIt removes both single-line `--` and multi-line `/* ... */` comments, unnecessary whitespaces, and shortens SQL keywords such as `INTEGER` to `INT`.\n\n## Installation\nAdd the following to your `Cargo.toml` file:\n```toml\n[dependencies]\nsql_minifier = \"0.1.5\"\n```\n\nor use the following command:\n```bash\ncargo add sql_minifier\n```\n\n## Examples\nSuppose you have an SQL string and you want to minify it. You can use the [`minify_sql`](https://github.com/mvisani/SQL-minifier/blob/b22627d27905ea5ce92d3a683ac10d11bccbfae9/minify_sql/src/lib.rs#L35) function:\n\n```rust\nuse sql_minifier::minify_sql;\n\nlet minified: String = minify_sql(\n    \"-- Your SQL goes here\nCREATE TABLE IF NOT EXISTS taxa (\n    -- The unique identifier for the taxon\n    id UUID PRIMARY KEY,\n    -- The scientific name of the taxon\n    name TEXT NOT NULL,\n    -- The NCBI Taxon ID is a unique identifier for a taxon in the NCBI Taxonomy database\n    -- which may be NULL when this taxon is not present in the NCBI Taxonomy database.\n    ncbi_taxon_id INTEGER\n);\"\n);\n\nassert_eq!(\n    minified,\n    \"CREATE TABLE IF NOT EXISTS taxa(id UUID PRIMARY KEY,name TEXT NOT NULL,ncbi_taxon_id INT)\"\n);\n```\n\nIf you want this to be done at compile time, you can use the [`minify_sql`](https://github.com/mvisani/SQL-minifier/blob/b22627d27905ea5ce92d3a683ac10d11bccbfae9/minify_sql_proc/src/lib.rs#L39) macro:\n```rust\nuse sql_minifier::macros::minify_sql;\n\nconst SQL_CONTENT: \u0026str = minify_sql!(\n    \"-- Your SQL goes here\nCREATE TABLE IF NOT EXISTS taxa (\n    -- The unique identifier for the taxon\n    id UUID PRIMARY KEY,\n    -- The scientific name of the taxon\n    name TEXT NOT NULL,\n    -- The NCBI Taxon ID is a unique identifier for a taxon in the NCBI Taxonomy database\n    -- which may be NULL when this taxon is not present in the NCBI Taxonomy database.\n    ncbi_taxon_id INTEGER\n);\"\n);\n\nassert_eq!(\n    SQL_CONTENT,\n    \"CREATE TABLE IF NOT EXISTS taxa(id UUID PRIMARY KEY,name TEXT NOT NULL,ncbi_taxon_id INT)\"\n);\n```\n\nA more complex [SQL file](tests/test_file_3.sql) such as:\n```sql\n-- SQL defining the container_horizontal_rules table.\n-- The container horizontal rules define whether an item type can be placed next to another item type.\n-- For instance a acid product cannot be placed next to a base product. Generally speaking, most items\n-- can be placed next to each other, but some items cannot be placed next to each other. These rules\n-- are defined in the form of a deny-list, meaning that if a rule is not defined, then the item type\n-- can be placed next to any other item type. The rules are defined by an admin user, and are used to\n-- enforce the placement rules when creating or updating items. Some items may only be placed next to\n-- items that are within a certain temperature, humidity, or pressure range. These constraints are also\n-- defined in the container rules.\nCREATE TABLE container_horizontal_rules (\n    id UUID PRIMARY KEY REFERENCES describables(id) ON DELETE CASCADE,\n    item_type_id UUID REFERENCES item_categories(id) ON\n    DELETE\n        CASCADE,\n        other_item_type_id UUID REFERENCES item_categories(id) ON\n    DELETE\n        CASCADE,\n        minimum_temperature FLOAT DEFAULT NULL,\n        maximum_temperature FLOAT DEFAULT NULL,\n        minimum_humidity FLOAT DEFAULT NULL,\n        maximum_humidity FLOAT DEFAULT NULL,\n        minimum_pressure FLOAT DEFAULT NULL,\n        maximum_pressure FLOAT DEFAULT NULL,\n        CHECK (\n            minimum_temperature IS NULL\n            OR maximum_temperature IS NULL\n            OR minimum_temperature \u003c= maximum_temperature\n        ),\n        /* The minimum humidity must be less than or\n        equal to the maximum humidity. */\n        CHECK (\n            minimum_humidity IS NULL\n            OR maximum_humidity IS NULL\n            OR minimum_humidity \u003c= maximum_humidity\n        ),\n        CHECK (\n            minimum_pressure IS NULL\n            OR maximum_pressure IS NULL\n            OR minimum_pressure \u003c= maximum_pressure\n        )\n);\n/* and other multiline comment */\n```\n\nWe can load it and minify it at compile time using the [`load_sql`](https://github.com/mvisani/SQL-minifier/blob/b22627d27905ea5ce92d3a683ac10d11bccbfae9/load_sql_proc/src/lib.rs#L26) macro:\n```rust\nuse sql_minifier::macros::load_sql;\n\nconst SQL_CONTENT: \u0026str = load_sql!(\"tests/test_file_3.sql\");\n\nassert_eq!(\n    SQL_CONTENT,\n    \"CREATE TABLE container_horizontal_rules(id UUID PRIMARY KEY REFERENCES describables(id)ON DELETE CASCADE,item_type_id UUID REFERENCES item_categories(id)ON DELETE CASCADE,other_item_type_id UUID REFERENCES item_categories(id)ON DELETE CASCADE,minimum_temperature FLOAT DEFAULT NULL,maximum_temperature FLOAT DEFAULT NULL,minimum_humidity FLOAT DEFAULT NULL,maximum_humidity FLOAT DEFAULT NULL,minimum_pressure FLOAT DEFAULT NULL,maximum_pressure FLOAT DEFAULT NULL,CHECK(minimum_temperature IS NULL OR maximum_temperature IS NULL OR minimum_temperature\u003c=maximum_temperature),CHECK(minimum_humidity IS NULL OR maximum_humidity IS NULL OR minimum_humidity\u003c=maximum_humidity),CHECK(minimum_pressure IS NULL OR maximum_pressure IS NULL OR minimum_pressure\u003c=maximum_pressure))\"\n);\n```\n\n## Features\nWe support the following features:\n- `gluesql`: When enabled, the minifier will not minify BOOLEAN keywords to BOOL, as it is not supported by [GlueSQL](https://gluesql.org/docs/0.14/).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmvisani%2Fsql-minifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmvisani%2Fsql-minifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmvisani%2Fsql-minifier/lists"}