Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jonfriesen/pglint
A simple PostgreSQL lint library written in Go that wraps ecpg
https://github.com/jonfriesen/pglint
postgres postgresql
Last synced: 24 days ago
JSON representation
A simple PostgreSQL lint library written in Go that wraps ecpg
- Host: GitHub
- URL: https://github.com/jonfriesen/pglint
- Owner: jonfriesen
- License: mit
- Created: 2019-02-05T18:26:58.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-13T00:07:13.000Z (over 3 years ago)
- Last Synced: 2024-06-20T00:27:03.885Z (5 months ago)
- Topics: postgres, postgresql
- Language: Go
- Size: 11.7 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pglint
This library is used to validate PostgreSQL statements and running them against the ecpg library to determine if they are valid.![Build Status](https://github.com/jonfriesen/pglint/workflows/build/badge.svg)
## requirements
- Go v1.11+
- [ecpg library](https://manpages.debian.org/experimental/libecpg-dev/ecpg.1.en.html)
```
// Ubuntu
sudo apt install libecpg-dev
// RedHat & CentOS
sudo yum install postgresql-devel
// Arch Linux
sudo pacman -S postgresql-libs
```## usage
The generaly rule of thumb is no repsonse is good news.
### Library
Consume the library by creating a ECPG object.
```go
config := ecpg.Config{
AddSemiColon: *addSemicolons,
TrimWhiteSpace: *trimWhitespace,
QuestionMarks: *allowQuestionMarks,
}linter, err := ecpg.NewECPG(&config)
if err != nil {
log.Fatalf("Error: %v", err)
}
```### CLI usage
`pglint-cli [options] `
```
Usage of pglint-cli:
-addSemicolons
Automatically add semicolons to queries if not already present (will fail without a semicolon) (default true)
-questionmarks
Determines whether or not the to fill question mark placeholders with sample data for linting (default true)
-trim
Trim whitespace at head and tail of query (default true)
```Eg. `pglint-cli -trim=false -questionmarks=false 'SELECT * FROM myTable;'`
### Docker
`docker run jonfriesen/pglint 'SELECT DATABASE_NAME FROM M_DATABASES;'`
#### Build yourself
Build: `docker build -t pglint .`
Run: `docker run pglint 'SELECT DATABASE_NAME FROM M_DATABASES;'`