diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..69e59d7 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,39 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go +name: go +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] +jobs: + test: + runs-on: ubuntu-latest + # Service containers to run with `container-job` + services: + # Label used to access the service container + postgres: + # Docker Hub image + image: postgres + # Provide the password for postgres + env: + POSTGRES_PASSWORD: postgres + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + # Maps tcp port 5432 on service container to the host + - 5432:5432 + steps: + - uses: actions/checkout@v4 + - name: Setup + uses: actions/setup-go@v4 + with: + go-version: '1.21' + - name: Test + run: go test -race -count=2 -coverprofile=cover.out -mod=readonly ./... + env: + PQT_POSTGRES_ADDRESS: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 37429fb..0000000 --- a/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -dist: trusty -language: go -go: - - 1.9.x -addons: - postgresql: '9.5' - apt: - sources: - - sourceline: 'ppa:masterminds/glide' - packages: - - glide -before_install: - - psql -c 'create database travis_ci_test;' -U postgres - - mkdir -p $GOPATH/bin -install: - - go get github.com/aryann/difflib - - go get github.com/huandu/xstrings - - go get . - - go get ./pqtgo - - go get ./pqtsql - - cd ./example/ && glide install - - cd ../ -script: - - ./test.sh -env: - global: - - PQT_POSTGRES_ADDRESS=postgres://postgres:@localhost/travis_ci_test?sslmode=disable -after_success: - - bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/Makefile b/Makefile index 4f320d8..4071c35 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ gen: echo 'package model' > ./example/app/internal/model/schema.pqt.go cd example && go install ./generator - cd example && go generate ./app/internal/model + cd example/app/internal/model && go generate run: cd example && go run app/main.go diff --git a/README.md b/README.md index 3bfaf64..17ed49c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# pqt [![GoDoc](https://godoc.org/github.com/piotrkowalczuk/pqt?status.svg)](http://godoc.org/github.com/piotrkowalczuk/pqt) [![Build Status](https://travis-ci.org/piotrkowalczuk/pqt.svg?branch=master)](https://travis-ci.org/piotrkowalczuk/pqt) [![codecov.io](https://codecov.io/github/piotrkowalczuk/pqt/coverage.svg?branch=master)](https://codecov.io/github/piotrkowalczuk/pqt?branch=master) +# pqt [![GoDoc](https://godoc.org/github.com/piotrkowalczuk/pqt?status.svg)](http://godoc.org/github.com/piotrkowalczuk/pqt) ![go workflow](https://github.com/piotrkowalczuk/pqt/actions/workflows/go.yml/badge.svg?branch=piotrkowalczuk/gh-action) This package is a toolbox for Postgres driven applications. It provides multiple tools to help to work with Postgres efficiently. @@ -49,4 +49,4 @@ $ make run ## Contribution -TODO \ No newline at end of file +TODO diff --git a/example/app/go.mod b/example/app/go.mod new file mode 100644 index 0000000..5f1b38e --- /dev/null +++ b/example/app/go.mod @@ -0,0 +1,5 @@ +module github.com/piotrkowalczuk/pqt/example/app + +go 1.21.4 + +require github.com/lib/pq v1.10.9 diff --git a/example/app/go.sum b/example/app/go.sum new file mode 100644 index 0000000..aeddeae --- /dev/null +++ b/example/app/go.sum @@ -0,0 +1,2 @@ +github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= +github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= diff --git a/example/app/internal/model/schema.pqt.go b/example/app/internal/model/schema.pqt.go index 64a02b9..6b47133 100644 --- a/example/app/internal/model/schema.pqt.go +++ b/example/app/internal/model/schema.pqt.go @@ -48,7 +48,7 @@ func RunInTransaction(ctx context.Context, db *sql.DB, f func(tx *sql.Tx) error, } return tx.Commit() - }(); err == RetryTransaction { + }(); errors.Is(err, RetryTransaction) { continue } return err @@ -10725,7 +10725,7 @@ func (c *Composer) Args() []interface{} { return c.args } -/// SQL ... +// SQL ... const SQL = ` -- sql schema beginning -- do not modify, generated by pqt diff --git a/example/app/main.go b/example/app/main.go index 10875ab..428e7fd 100644 --- a/example/app/main.go +++ b/example/app/main.go @@ -176,7 +176,7 @@ func main() { count, err = repo.news.Count(ctx, &model.NewsCountExpr{}) if err != nil { - if err != context.DeadlineExceeded { + if !errors.Is(err, context.DeadlineExceeded) { log.Fatal(err) } log.Fatal("as expected, news count failed due to deadline") diff --git a/example/generator/main.go b/example/generator/main.go index 7d55478..4e1013e 100644 --- a/example/generator/main.go +++ b/example/generator/main.go @@ -53,7 +53,7 @@ func main() { if err != nil { log.Fatal(err) } - fmt.Fprint(file, "/// SQL ...\n") + fmt.Fprint(file, "// SQL ...\n") fmt.Fprint(file, "const SQL = `\n") if err := sqlGen.GenerateTo(sch, file); err != nil { diff --git a/example/glide.lock b/example/glide.lock deleted file mode 100644 index 742e224..0000000 --- a/example/glide.lock +++ /dev/null @@ -1,8 +0,0 @@ -hash: cd25a00643f01beeef3595661d9019dc6eb3369d1dfb45eaf0a9eaa2339d8be7 -updated: 2017-05-22T13:48:43.084454114+02:00 -imports: -- name: github.com/lib/pq - version: 4a82388ebc5138c8289fe9bc602cb0b3e32cd617 - subpackages: - - oid -testImports: [] diff --git a/example/glide.yaml b/example/glide.yaml deleted file mode 100644 index 8cbd1ee..0000000 --- a/example/glide.yaml +++ /dev/null @@ -1,6 +0,0 @@ -package: github.com/piotrkowalczuk/pqt/example -ignore: -- github.com/piotrkowalczuk/pqt -import: -- package: github.com/lib/pq - version: 4a82388ebc5138c8289fe9bc602cb0b3e32cd617 diff --git a/example/model.test b/example/model.test deleted file mode 100755 index 107cd81..0000000 Binary files a/example/model.test and /dev/null differ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a0e11c9 --- /dev/null +++ b/go.mod @@ -0,0 +1,9 @@ +module github.com/piotrkowalczuk/pqt + +go 1.21.4 + +require ( + github.com/aryann/difflib v0.0.0-20210328193216-ff5ff6dc229b + github.com/huandu/xstrings v1.4.0 + github.com/lib/pq v1.10.9 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7c63ffd --- /dev/null +++ b/go.sum @@ -0,0 +1,6 @@ +github.com/aryann/difflib v0.0.0-20210328193216-ff5ff6dc229b h1:uUXgbcPDK3KpW29o4iy7GtuappbWT0l5NaMo9H9pJDw= +github.com/aryann/difflib v0.0.0-20210328193216-ff5ff6dc229b/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A= +github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU= +github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= +github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= diff --git a/internal/gogen/gen_general.go b/internal/gogen/gen_general.go index aaca62e..d3ca8b3 100644 --- a/internal/gogen/gen_general.go +++ b/internal/gogen/gen_general.go @@ -567,7 +567,7 @@ func (g *Generator) Interfaces() { } func (g *Generator) Statics() { - g.Print(` + code := ` const ( JoinInner = iota JoinLeft @@ -1013,7 +1013,9 @@ func (c *Composer) Add(arg interface{}) { // Args returns all arguments stored as a slice. func (c *Composer) Args() []interface{} { return c.args -}`) +}` + + g.Print(code) } func (g *Generator) PluginsStatics(s *pqt.Schema) { diff --git a/internal/gogen/gen_helpers.go b/internal/gogen/gen_helpers.go index 6366127..13be42a 100644 --- a/internal/gogen/gen_helpers.go +++ b/internal/gogen/gen_helpers.go @@ -36,7 +36,7 @@ func RunInTransaction(ctx context.Context, db *sql.DB, f func(tx *sql.Tx) error, } return tx.Commit() - }(); err == RetryTransaction { + }(); errors.Is(err, RetryTransaction) { continue } return err diff --git a/pqtgo/pqtgogen/generator_test.go b/pqtgo/pqtgogen/generator_test.go index 87cba6a..056e28b 100644 --- a/pqtgo/pqtgogen/generator_test.go +++ b/pqtgo/pqtgogen/generator_test.go @@ -114,7 +114,7 @@ func RunInTransaction(ctx context.Context, db *sql.DB, f func(tx *sql.Tx) error, } return tx.Commit() - }(); err == RetryTransaction { + }(); errors.Is(err, RetryTransaction) { continue } return err diff --git a/test.sh b/test.sh deleted file mode 100755 index 71a4903..0000000 --- a/test.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash - -rm coverage.txt -set -e -echo "mode: atomic" > coverage.txt - -for d in $(go list ./... | grep -v /vendor); do - go test -coverprofile=profile.out -covermode=atomic $d - if [ -f profile.out ]; then - tail -n +2 profile.out >> coverage.txt - rm profile.out - fi -done - -go tool cover -func=coverage.txt | tail -n 1 \ No newline at end of file