Skip to content

Commit

Permalink
Refactor CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Nymphium committed Jul 6, 2023
1 parent 96bf7a0 commit 2a64367
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 97 deletions.
52 changes: 25 additions & 27 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 }}

- 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: |
psql -U postgres -h localhost -d dgw_test -f ./test.sql
go install golang.org/x/tools/cmd/goimports@latest
go install
- name: Generate
run: go generate -v ./example
- name: Check diff
Expand Down
30 changes: 0 additions & 30 deletions example/customstruct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 0 additions & 40 deletions example/defaultstruct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 2a64367

Please sign in to comment.