diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9fb09af..a2bb265 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,9 @@ jobs: # - macOS-latest # - windows-latest go: - - "1.19.1" + - "1.19.10" + - "1.20.5" + - "1.21.0-rc.2" services: postgres: image: postgres:12 @@ -31,31 +33,23 @@ jobs: run: | psql -U postgres -h localhost -d postgres -c 'CREATE USER dgw_test;' psql -U postgres -h localhost -d postgres -c 'CREATE DATABASE dgw_test OWNER dgw_test;' + - name: Checkout code + uses: actions/checkout/@v3 - name: Install Go - uses: actions/setup-go/@v2 + uses: actions/setup-go/@v4 with: go-version: ${{ matrix.go }} - - - name: Checkout code - uses: actions/checkout/@v3 - + - name: Download Go modules + shell: bash + if: ${{ steps.setup-go.outputs.cache-hit != 'true' }} + run: go mod download - name: Lint uses: golangci/golangci-lint-action@v3 - - name: Run test run: go test -v + check-test-gen: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: - - ubuntu-latest - # Container operations, such as postgres, are only supported on Linux runners - # - macOS-latest - # - windows-latest - go: - - "1.19.1" + runs-on: ubuntu-latest services: postgres: image: postgres:12 @@ -70,17 +64,21 @@ jobs: run: | psql -U postgres -h localhost -d postgres -c 'CREATE USER dgw_test;' psql -U postgres -h localhost -d postgres -c 'CREATE DATABASE dgw_test OWNER dgw_test;' - - name: Install Go - uses: actions/setup-go/@v2 - with: - go-version: ${{ matrix.go }} - + psql -U postgres -h localhost -d dgw_test -f ./test.sql - name: Checkout code uses: actions/checkout/@v3 - - - name: Lint - uses: golangci/golangci-lint-action@v3 - + - name: Install Go + uses: actions/setup-go/@v4 + with: + go-version: "1.20.5" + - name: Download Go modules + shell: bash + if: ${{ steps.setup-go.outputs.cache-hit != 'true' }} + run: go mod download + - name: Install deps + run: | + go install golang.org/x/tools/cmd/goimports@latest + go install - name: Generate run: go generate -v ./example - name: Check diff diff --git a/example/customstruct.go b/example/customstruct.go index 4131393..8681055 100644 --- a/example/customstruct.go +++ b/example/customstruct.go @@ -133,36 +133,6 @@ func GetT4TableByPk(db Queryer, pk0 int, pk1 int) (*T4, error) { return &r, nil } -// T5Table represents public.t5 -type T5Table struct { - ID int64 // id - Select int // select - From string // from -} - -// Create inserts the T5 to the database. -func (r *T5Table) Create(db Queryer) error { - err := db.QueryRow( - `INSERT INTO t5 (select, from) VALUES ($1, $2) RETURNING id`, - &r.Select, &r.From).Scan(&r.ID) - if err != nil { - return err - } - return nil -} - -// GetT5TableByPk select the T5 from the database. -func GetT5TableByPk(db Queryer, pk0 int64) (*T5, error) { - var r T5 - err := db.QueryRow( - `SELECT id, select, from FROM t5 WHERE id = $1`, - pk0).Scan(&r.ID, &r.Select, &r.From) - if err != nil { - return nil, err - } - return &r, nil -} - // Queryer database/sql compatible query interface type Queryer interface { Exec(string, ...interface{}) (sql.Result, error) diff --git a/example/defaultstruct.go b/example/defaultstruct.go index 3eed177..79ea032 100644 --- a/example/defaultstruct.go +++ b/example/defaultstruct.go @@ -174,43 +174,3 @@ func GetT4ByPkContext(ctx context.Context, db Queryer, pk0 int, pk1 int) (*T4, e } return &r, nil } - -// T5 represents public.t5 -type T5 struct { - ID int64 // id - Select int // select - From string // from -} - -// Create inserts the T5 to the database. -func (r *T5) Create(db Queryer) error { - return r.CreateContext(context.Background(), db) -} - -// GetT5ByPk select the T5 from the database. -func GetT5ByPk(db Queryer, pk0 int64) (*T5, error) { - return GetT5ByPkContext(context.Background(), db, pk0) -} - -// CreateContext inserts the T5 to the database. -func (r *T5) CreateContext(ctx context.Context, db Queryer) error { - err := db.QueryRowContext(ctx, - `INSERT INTO t5 (select, from) VALUES ($1, $2) RETURNING id`, - &r.Select, &r.From).Scan(&r.ID) - if err != nil { - return errors.Wrap(err, "failed to insert t5") - } - return nil -} - -// GetT5ByPkContext select the T5 from the database. -func GetT5ByPkContext(ctx context.Context, db Queryer, pk0 int64) (*T5, error) { - var r T5 - err := db.QueryRowContext(ctx, - `SELECT id, select, from FROM t5 WHERE id = $1`, - pk0).Scan(&r.ID, &r.Select, &r.From) - if err != nil { - return nil, errors.Wrap(err, "failed to select t5") - } - return &r, nil -}