https://github.com/imantung/sqlstr
String manipulation/helper for SQL Query
https://github.com/imantung/sqlstr
sql-cleaner sql-obsecurer sql-parser sql-table sqlquery string-manipulation
Last synced: 4 months ago
JSON representation
String manipulation/helper for SQL Query
- Host: GitHub
- URL: https://github.com/imantung/sqlstr
- Owner: imantung
- License: mit
- Created: 2019-05-21T17:24:58.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-01-01T12:28:56.000Z (almost 4 years ago)
- Last Synced: 2024-06-19T05:59:45.299Z (over 1 year ago)
- Topics: sql-cleaner, sql-obsecurer, sql-parser, sql-table, sqlquery, string-manipulation
- Language: Go
- Size: 6.84 KB
- Stars: 8
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# SQLSTR
String manipulation/helper for SQL Query.
## Examples
### Clean Query from double white space, comment, etc.
```go
cleaned := sqlstr.Clean(`
SELECT *
FROM table -- some table comment
WHERE column1 = 'meh' /* request from tyrion*/`)
fmt.Println(cleaned)
// Output:
// SELECT * FROM table WHERE column1 = 'meh'
```
### Obscure value
```go
obsecured := sqlstr.Obscure(`SELECT * FROM table WHERE column1 = 'text' AND column2 = 1234 AND column3 = TRUE and column4 = 3.14`)
fmt.Println(obsecured)
// Output:
// SELECT * FROM table WHERE column1 = ? AND column2 = ? AND column3 = ? and column4 = ?
```
### Get Table Names
```go
queryString := sqlstr.NewQueryString(`SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;`)
tableNames := queryString.TableNames()
fmt.Println(tableNames)
// Output:
// [table1 table2]
```
## Author
iman.tung@gmail.com