-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The main trick is to specify the override on NewQuerierConfig and not on ConnInfo.RegisterDataType. We can't easily get the data types for pgxpool.Pool because we need to get a real *Conn which then fetches a connection from the pool. Partially resolves #39.
- Loading branch information
Showing
9 changed files
with
504 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package numeric_external | ||
|
||
import ( | ||
"github.com/jschaf/pggen" | ||
"github.com/jschaf/pggen/internal/pgtest" | ||
"github.com/stretchr/testify/assert" | ||
"io/ioutil" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestGenerate_Go_Example_Numeric_External(t *testing.T) { | ||
conn, cleanupFunc := pgtest.NewPostgresSchema(t, []string{"schema.sql"}) | ||
defer cleanupFunc() | ||
|
||
tmpDir := t.TempDir() | ||
err := pggen.Generate( | ||
pggen.GenerateOptions{ | ||
ConnString: conn.Config().ConnString(), | ||
QueryFiles: []string{"query.sql"}, | ||
OutputDir: tmpDir, | ||
GoPackage: "numeric_external", | ||
Language: pggen.LangGo, | ||
TypeOverrides: map[string]string{ | ||
"int4": "int", | ||
"int8": "int", | ||
"text": "string", | ||
"numeric": "github.com/shopspring/decimal.Decimal", | ||
}, | ||
}) | ||
if err != nil { | ||
t.Fatalf("Generate(): %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 := ioutil.ReadFile(wantQueriesFile) | ||
if err != nil { | ||
t.Fatalf("read wanted query.go.sql: %s", err) | ||
} | ||
gotQueries, err := ioutil.ReadFile(gotQueriesFile) | ||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- name: InsertNumeric :exec | ||
INSERT INTO numeric_external (num, num_arr) | ||
VALUES (pggen.arg('num'), pggen.arg('num_arr')); | ||
|
||
-- name: FindNumerics :many | ||
SELECT num, num_arr | ||
FROM numeric_external; |
Oops, something went wrong.