https://github.com/sasakiyori/sqltext
Simplify the plain sql text which contents comments and line feeds, also do simple grammar analysis for it.
https://github.com/sasakiyori/sqltext
go postgresql sql sqltext text
Last synced: 5 months ago
JSON representation
Simplify the plain sql text which contents comments and line feeds, also do simple grammar analysis for it.
- Host: GitHub
- URL: https://github.com/sasakiyori/sqltext
- Owner: sasakiyori
- License: mit
- Created: 2022-06-14T10:24:23.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-28T02:47:50.000Z (about 4 years ago)
- Last Synced: 2024-11-17T04:11:45.317Z (over 1 year ago)
- Topics: go, postgresql, sql, sqltext, text
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sqltext



[](https://coveralls.io/github/sasakiyori/sqltext)
[](https://goreportcard.com/report/github.com/sasakiyori/sqltext)
## Table of contents
- [Background](#background)
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Contributing](#contributing)
- [License](#license)
## Background
In some scenarios, programs will receive a plain sql text from upstream and then transfer to others or execute it locally.
We can't expect the sql text is always concise and highly readable, because the habits of sql writers are different. This will confuse coders when they want to do some analysis out of database tools. Since the sql text may has messy format with a lot of comments, meaningless blank spaces and line feeds, we may need some methods to simplify the sql text.
Also the logic of a sql text can be very complex, we may need a method to find out what it does and what it affects.
## Features
This repository supports simple grammar analysis and plain text simplifying for different query languages.
| | mysql | postgresql | ... |
| :----: | :----: | :----: | :----: |
| Simplify Text | | :heavy_check_mark: | |
| Get Command Type | | :heavy_check_mark: | |
## Installation
```shell
go get github.com/sasakiyori/sqltext
```
## Usage
```go
// use New() to create a processor with a specific sql type
processor := sqltext.New(sqltext.Postgresql)
// or use the specific sql type function to create a processor
processor = sqltext.WithPostgresql()
// only remove comments
rc := processor.RemoveComments(text)
// remove comments, then decrease blank spaces and line feeds, finally get an one-line sql text.
ft := processor.FormatText(text)
// get the command type of sql text
cmdType := processor.CommandType(text)
// maybe you only consider about if the sql text is involved in write-operation or not
readonly := processor.Readonly(text)
```
## Contributing
[Issues](https://github.com/sasakiyori/sqltext/issues/new) and [PRs](https://github.com/sasakiyori/sqltext/pulls) are welcome!
This project is just starting, lack of massy documentations, method completions, query language extensions and test case coverages. Thanks in advance to all contributors of this repository :heart:
## License
[MIT License](LICENSE)