Skip to content

Commit

Permalink
updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mvisani committed Apr 5, 2024
1 parent 8d35798 commit 094fcf1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Documentation](https://docs.rs/sql_minifier/badge.svg)](https://docs.rs/sql_minifier)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

This crate provides a simple SQL minifier. It removes comments and unnecessary whitespaces from SQL files.
This crate provides a simple SQL minifier. It removes comments and unnecessary whitespaces from SQL files.

## Installation
Add the following to your `Cargo.toml` file:
Expand All @@ -19,9 +19,20 @@ cargo add sql_minifier
```

## Usage
The create provides two main functions:
- `minifiy_sql_to_string` which reads an SQL file and returns a `String` of the
minified SQL.
- `minifiy_sql_to_file` which reads an SQL file and writes the minified SQL
to a new file specified by the user.

Additionally, the crate provides a macro `minify_sql_files!` that can be used to minify SQL files at compile time. The macro accepts file paths as input.

It's important to note that the macro will write the minified SQL to a new file with the same name as the input file, but with the suffix `_minified`. Additionally, it will append the `_minified` suffix just before the last `.` in the file name. For instance, if the input file is `test_data/test_file_1.sql`, the minified file will be named `test_data/test_file_1_minified.sql`.

The macro can be utilized as follows:
```rust
use sql_minifier::prelude::*;
minify_sql_files!("test_data/test_file_1.sql");
minify_sql_files!("test_data/test_file_1.sql", "test_data/test_file_2.sql");
```

## Example
Expand All @@ -42,4 +53,7 @@ CREATE TABLE IF NOT EXISTS taxa (
will be minified to:
```sql
CREATE TABLE IF NOT EXISTS taxa ( id UUID PRIMARY KEY, name TEXT NOT NULL, ncbi_taxon_id INT);
```
```

## Limitations
The crate currently does not support the removal of SQL `/*`...`*/` multiline comments.
1 change: 1 addition & 0 deletions test_data/test_file_2_minified.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE projects ( id UUID PRIMARY KEY, name TEXT NOT NULL UNIQUE, description TEXT NOT NULL, public BOOL NOT NULL DEFAULT TRUE, state_id UUID NOT NULL REFERENCES project_states(id), parent_project_id UUID REFERENCES projects(id) ON DELETE CASCADE, budget FLOAT DEFAULT NULL, expenses FLOAT DEFAULT NULL, created_by UUID NOT NULL REFERENCES users(id), created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, expected_end_date TIMESTAMP DEFAULT NULL, end_date TIMESTAMP DEFAULT NULL);

0 comments on commit 094fcf1

Please sign in to comment.