diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 15c63f5..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Build - -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - test: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - # Setup Go - - name: Setup Go - uses: actions/setup-go@v2 - with: - go-version: '1.17.0' # The Go version to download (if necessary) and use. - - # Install all the dependencies - - name: Install dependencies - run: | - go version - go get -u golang.org/x/lint/golint - - # Run vet & lint on the code - - name: Run vet & lint - run: | - go vet . - golint . - - # Run testing on the code - - name: Run testing - run: go test -v diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..5bb71a2 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,27 @@ +--- +name: Go +on: + push: + branches: + - main + pull_request: + branches: + - main +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + go: ['1.17.x', '1.18.x', '1.19.x', '1.20.x', '1.21.x', '1.22.x', '1.23.x'] + name: Go ${{ matrix.go }} job + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go }} + + # Run testing on the code + - name: Run testing + run: go test -v ./... \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..407897b --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,30 @@ +--- +name: Lint +on: + push: + branches: + - main + pull_request: + +permissions: + contents: read + +jobs: + lint: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: stable + # Run vet & lint on the code + - name: Run vet & lint + run: | + go mod tidy + go mod verify + go fix ./... + go vet -all ./... + + - name: govulncheck + uses: golang/govulncheck-action@v1 diff --git a/.gitignore b/.gitignore index 722d5e7..0cd6e6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,25 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +vendor/ + +# Go workspace file +go.work +go.work.sum + +# Original .vscode diff --git a/README.md b/README.md index f87dc24..0587d0e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![GoDoc Reference](https://godoc.org/github.com/leporo/sqlf?status.svg)](http://godoc.org/github.com/leporo/sqlf) ![Build Status](https://github.com/leporo/sqlf/actions/workflows/build.yml/badge.svg) [![Go Report Card](https://goreportcard.com/badge/github.com/leporo/sqlf)](https://goreportcard.com/report/github.com/leporo/sqlf) +[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go#sql-query-builders) A fast SQL query builder for Go. diff --git a/example_test.go b/example_test.go index f3af55b..893c009 100644 --- a/example_test.go +++ b/example_test.go @@ -22,8 +22,10 @@ func (db *dummyDB) QueryRowContext(ctx context.Context, query string, args ...in return nil } -var db = new(dummyDB) -var ctx = context.Background() +var ( + db = new(dummyDB) + ctx = context.Background() +) func Example() { var ( @@ -223,7 +225,7 @@ func ExampleStmt_From() { fmt.Println(q.String()) q.Close() // Output: - //SELECT * FROM (SELECT id, section, header, score, row_number() OVER (PARTITION BY section ORDER BY score DESC) AS rating_in_section FROM news ORDER BY section, rating_in_section) counted_news WHERE rating_in_section <= 5 + // SELECT * FROM (SELECT id, section, header, score, row_number() OVER (PARTITION BY section ORDER BY score DESC) AS rating_in_section FROM news ORDER BY section, rating_in_section) counted_news WHERE rating_in_section <= 5 } func ExampleStmt_SubQuery() { diff --git a/pool.go b/pool.go index 8048696..1b0395d 100644 --- a/pool.go +++ b/pool.go @@ -6,9 +6,7 @@ import ( "github.com/valyala/bytebufferpool" ) -var ( - stmtPool = sync.Pool{New: newStmt} -) +var stmtPool = sync.Pool{New: newStmt} func newStmt() interface{} { return &Stmt{