Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Here is what the original History section says:
## Usage

The `SqlFormatter` class has a method `format` which takes an SQL string as
input and returns a formatted HTML block inside a `pre` tag.
input and returns a formatted block.

Sample usage:

Expand All @@ -44,7 +44,12 @@ echo (new SqlFormatter())->format($query);

Output:

![](http://jdorn.github.com/sql-formatter/format-highlight.png)
<img src="examples/readme_format_html.svg" width="600" height="450" alt="formatted output with HTML Highlight">
Copy link
Contributor Author

@sasezaki sasezaki Jul 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To enable css style on Github README.md, I chose this hack.
https://css-tricks.com/custom-styles-in-github-readmes/


When you run php under cli and instantiated `SqlFormatter` without argument, highlighted with `CliHighlighter`.

SqlFormatter constructor takes `Highlighter` implementations. `HtmlHighlighter` etc.


### Formatting Only

Expand All @@ -64,7 +69,29 @@ echo (new SqlFormatter(new NullHighlighter()))->format($query);

Output:

![](http://jdorn.github.com/sql-formatter/format.png)
```
SELECT
count(*),
`Column1`,
`Testing`,
`Testing Three`
FROM
`Table1`
WHERE
Column1 = 'testing'
AND (
(
`Column2` = `Column3`
OR Column4 >= NOW()
)
)
GROUP BY
Column1
ORDER BY
Column3 DESC
LIMIT
5, 10
```

### Syntax Highlighting Only

Expand All @@ -81,7 +108,7 @@ echo (new SqlFormatter())->highlight($query);

Output:

![](http://jdorn.github.com/sql-formatter/highlight.png)
<img src="examples/readme_highlight_html.svg" width="800" height="150" alt="HTML Highlight output">

### Compress Query

Expand All @@ -100,7 +127,7 @@ line easily.
```

```php
echo (new SqlFormatter())->compress($query)
echo (new SqlFormatter())->compress($query);
```

Output:
Expand Down
27 changes: 27 additions & 0 deletions examples/readme_format_html.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions examples/readme_highlight_html.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.