Skip to content

Commit

Permalink
Fix IntelliJ Go lints
Browse files Browse the repository at this point in the history
  • Loading branch information
jschaf committed Jun 17, 2023
1 parent 95dc264 commit 4272ee3
Show file tree
Hide file tree
Showing 27 changed files with 115 additions and 126 deletions.
12 changes: 6 additions & 6 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ in the following steps.
the `--schema-glob` flag in [cmd/pggen/pggen.go]. Pass the normalized
options to `pggen.Generate` in [generate.go].

1. Start Postgres by either connecting to the database specified in
2. Start Postgres by either connecting to the database specified in
`--postgres-connection` or by starting a new Dockerized Postgres instance.
[internal/pgdocker/pgdocker.go] creates and destroys Docker images for
pggen.

1. Parse each query files into an `*ast.File` containing many
3. Parse each query files into an `*ast.File` containing many
`*ast.SourceQuery` nodes in [internal/parser/interface.go].

1. Infer the Postgres types and nullability for the input parameters and output
4. Infer the Postgres types and nullability for the input parameters and output
columns of an `*ast.SourceQuery` and store the results in
`pginfer.TypedQuery` in [internal/pginfer/pginfer.go].

Expand All @@ -39,13 +39,13 @@ in the following steps.
flow analysis to determine nullability. I've started down that road in
[pgplan.go](./internal/pgplan/pgplan.go).

1. Transform each `*ast.File` into `codegen.QueryFile` in [generate.go]
5. Transform each `*ast.File` into `codegen.QueryFile` in [generate.go]
`parseQueries`.

1. Use a language-specific code generator to transform `codegen.QueryFile`
6. Use a language-specific code generator to transform `codegen.QueryFile`
into a `golang.TemplatedFile` like with [internal/codegen/golang/templater.go].

1. Emit the generated code from `golang.TemplateFile` in
7. Emit the generated code from `golang.TemplateFile` in
[internal/codegen/golang/templated_file.go]

[cmd/pggen/pggen.go]: cmd/pggen/pggen.go
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ Examples embedded in the repo:
which should render as `AuthorIDs`, not `AuthorIds`. For the IDs example,
use `--acronym ids=IDs`.

1. Short form: `--acronym <word>`: replaces `<word>` with uppercase
2. Short form: `--acronym <word>`: replaces `<word>` with uppercase
`<WORD>`. Equivalent to `--acronym <word>=<WORD>`

By default, pggen includes `--acronym id` to render `id` as `ID`.
Expand All @@ -338,7 +338,7 @@ Examples embedded in the repo:
CREATE TYPE device_type AS ENUM ('undefined', 'phone', 'ipad');
```

Generates the following Go code when used in a query:
pggen generates the following Go code when used in a query:

```go
// DeviceType represents the Postgres enum device_type.
Expand Down Expand Up @@ -372,7 +372,7 @@ Examples embedded in the repo:
means the Go type must fulfill at least one of following:

- The Go type is a wrapper around primitive type, like `type AuthorID int`.
pgx will use the decode methods on the underlying primitive type.
pgx will use decode methods on the underlying primitive type.

- The Go type implements both [`pgtype.BinaryDecoder`] and
[`pgtype.TextDecoder`]. pgx will use the correct decoder based on the wire
Expand Down Expand Up @@ -404,7 +404,7 @@ Examples embedded in the repo:
SELECT ROW (15, 'qux')::"user" AS "user";
```

Generates the following Go code:
pggen generates the following Go code:

```go
// User represents the Postgres composite type "user".
Expand Down Expand Up @@ -474,7 +474,7 @@ We'll walk through the generated file `author/query.sql.go`:

- The `Querier` interface defines the interface with methods for each SQL
query. Each SQL query compiles into three methods, one method for to run
query by itself, and two methods to support batching a query with
the query by itself, and two methods to support batching a query with
[`pgx.Batch`].

```go
Expand Down Expand Up @@ -574,9 +574,9 @@ We'll walk through the generated file `author/query.sql.go`:
nullable types for all built-in Postgres types. pggen tries to infer if a
column is nullable or non-nullable. If a column is nullable, pggen uses a
`pgtype` Go type like `pgtype.Text`. If a column is non-nullable, pggen uses
a more ergonomic type like `string`. pggen's nullability inference in
[internal/pginfer/nullability.go] is rudimentary; a proper approach requires
a full explain plan with some control flow analysis.
a more ergonomic type like `string`. pggen's nullability inference
implemented in [internal/pginfer/nullability.go] is rudimentary; a proper
approach requires a full explain-plan with some control flow analysis.

- Lastly, pggen generates the implementation for each query.

Expand Down
12 changes: 6 additions & 6 deletions example/author/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ func TestGenerate_Go_Example_Author(t *testing.T) {
t.Fatalf("Generate() example/author: %s", err)
}

wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile,
wantQueryFile := "query.sql.go"
gotQueryFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueryFile,
"Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueriesFile)
wantQueries, err := os.ReadFile(wantQueryFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := os.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueryFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
assert.Equalf(t, string(wantQueries), string(gotQueries),
"Got file %s; does not match contents of %s",
gotQueriesFile, wantQueriesFile)
gotQueryFile, wantQueryFile)
}
12 changes: 6 additions & 6 deletions example/complex_params/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ func TestGenerate_Go_Example_ComplexParams(t *testing.T) {
t.Fatalf("Generate() example/complex_params: %s", err)
}

wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueriesFile)
wantQueryFile := "query.sql.go"
gotQueryFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueryFile, "Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueryFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := os.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueryFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
assert.Equalf(t, string(wantQueries), string(gotQueries),
"Got file %s; does not match contents of %s",
gotQueriesFile, wantQueriesFile)
gotQueryFile, wantQueryFile)
}
12 changes: 6 additions & 6 deletions example/composite/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ func TestGenerate_Go_Example_Composite(t *testing.T) {
t.Fatalf("Generate(): %s", err)
}

wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile,
wantQueryFile := "query.sql.go"
gotQueryFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueryFile,
"Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueriesFile)
wantQueries, err := os.ReadFile(wantQueryFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := os.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueryFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
assert.Equalf(t, string(wantQueries), string(gotQueries),
"Got file %s; does not match contents of %s",
gotQueriesFile, wantQueriesFile)
gotQueryFile, wantQueryFile)
}
12 changes: 6 additions & 6 deletions example/custom_types/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ func TestGenerate_Go_Example_CustomTypes(t *testing.T) {
t.Fatalf("Generate() example/custom_types: %s", err)
}

wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueriesFile)
wantQueryFile := "query.sql.go"
gotQueryFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueryFile, "Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueryFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := os.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueryFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
assert.Equalf(t, string(wantQueries), string(gotQueries),
"Got file %s; does not match contents of %s",
gotQueriesFile, wantQueriesFile)
gotQueryFile, wantQueryFile)
}
2 changes: 1 addition & 1 deletion example/custom_types/mytype/mytypes.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mytype

// Simple custom type we can use for the Postgres text type.
// String is a simple custom type we can use for the Postgres text type.
type String string
2 changes: 1 addition & 1 deletion example/custom_types/types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package custom_types

// A custom type in the same package as the query file.
// CustomInt is a custom type in the same package as the query file.
type CustomInt int
12 changes: 6 additions & 6 deletions example/device/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ func TestGenerate_Go_Example_Device(t *testing.T) {
t.Fatalf("Generate() example/device: %s", err)
}

wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueriesFile)
wantQueryFile := "query.sql.go"
gotQueryFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueryFile, "Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueryFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := os.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueryFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
assert.Equalf(t, string(wantQueries), string(gotQueries),
"Got file %s; does not match contents of %s",
gotQueriesFile, wantQueriesFile)
gotQueryFile, wantQueryFile)
}
12 changes: 6 additions & 6 deletions example/domain/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ func TestGenerate_Go_Example_Domain(t *testing.T) {
t.Fatalf("Generate() example/domain: %s", err)
}

wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueriesFile)
wantQueryFile := "query.sql.go"
gotQueryFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueryFile, "Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueryFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := os.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueryFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
assert.Equalf(t, string(wantQueries), string(gotQueries),
"Got file %s; does not match contents of %s",
gotQueriesFile, wantQueriesFile)
gotQueryFile, wantQueryFile)
}
12 changes: 6 additions & 6 deletions example/enums/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ func TestGenerate_Go_Example_Enums(t *testing.T) {
t.Fatalf("Generate() example/enums: %s", err)
}

wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueriesFile)
wantQueryFile := "query.sql.go"
gotQueryFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueryFile, "Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueryFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := os.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueryFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
assert.Equalf(t, string(wantQueries), string(gotQueries),
"Got file %s; does not match contents of %s",
gotQueriesFile, wantQueriesFile)
gotQueryFile, wantQueryFile)
}
12 changes: 6 additions & 6 deletions example/function/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ func TestGenerate_Go_Example_Function(t *testing.T) {
t.Fatalf("Generate() example/function: %s", err)
}

wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile,
wantQueryFile := "query.sql.go"
gotQueryFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueryFile,
"Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueriesFile)
wantQueries, err := os.ReadFile(wantQueryFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := os.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueryFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
assert.Equalf(t, string(wantQueries), string(gotQueries),
"Got file %s; does not match contents of %s",
gotQueriesFile, wantQueriesFile)
gotQueryFile, wantQueryFile)
}
12 changes: 6 additions & 6 deletions example/go_pointer_types/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ func TestGenerate_Go_Example_GoPointerTypes(t *testing.T) {
t.Fatalf("Generate() example/go_pointer_types: %s", err)
}

wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueriesFile)
wantQueryFile := "query.sql.go"
gotQueryFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueryFile, "Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueryFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := os.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueryFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
assert.Equalf(t, string(wantQueries), string(gotQueries),
"Got file %s; does not match contents of %s",
gotQueriesFile, wantQueriesFile)
gotQueryFile, wantQueryFile)
}
12 changes: 6 additions & 6 deletions example/ltree/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ func TestGenerate_Go_Example_ltree(t *testing.T) {
t.Fatalf("Generate() example/ltree: %s", err)
}

wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueriesFile)
wantQueryFile := "query.sql.go"
gotQueryFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueryFile, "Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueryFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := os.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueryFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
assert.Equalf(t, string(wantQueries), string(gotQueries),
"Got file %s; does not match contents of %s",
gotQueriesFile, wantQueriesFile)
gotQueryFile, wantQueryFile)
}
12 changes: 6 additions & 6 deletions example/nested/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ func TestGenerate_Go_Example_nested(t *testing.T) {
t.Fatalf("Generate() example/nested: %s", err)
}

wantQueriesFile := "query.sql.go"
gotQueriesFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueriesFile, "Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueriesFile)
wantQueryFile := "query.sql.go"
gotQueryFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueryFile, "Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueryFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := os.ReadFile(gotQueriesFile)
gotQueries, err := os.ReadFile(gotQueryFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
assert.Equalf(t, string(wantQueries), string(gotQueries),
"Got file %s; does not match contents of %s",
gotQueriesFile, wantQueriesFile)
gotQueryFile, wantQueryFile)
}
Loading

0 comments on commit 4272ee3

Please sign in to comment.