jschaf / pggen

Generate type-safe Go for any Postgres query. If Postgres can run the query, pggen can generate code for it.
MIT License
282 stars 26 forks source link

cannot unmarshal number into Go value of type map[string]interface {} #54

Closed bera-josh-jewell closed 2 years ago

bera-josh-jewell commented 2 years ago

I am just trying to get through a basic tutorial. I installed through go install: go install github.com/jschaf/pggen/cmd/pggen@latest

Then tried to run the following command against my postgres database: pggen gen go \ --schema-glob author/schema.sql \ --query-glob author/query.sql

it creates the author schema in the database correctly, but I get the following error while trying to generate code for query.sql: ERROR: parse template query file "C:\\code\\api-brand-allocation\\author\\query.sql": infer typed named query FindAuthorByID: infer output types for query: infer output type nullability: explain prepared query: can't scan into dest[0]: json: cannot unmarshal number into Go value of type map[string]interface {} I pulled my query.sql and schema.sql from the following location: https://github.com/jschaf/pggen/tree/main/example/author

Can't figure out what I missed, hopefully something simple. Thanks!

jschaf commented 2 years ago

I just verified that installing via go install and running the author example works on main:

go install github.com/jschaf/pggen/cmd/pggen@latest
cd pggen/example
~/go/bin/pggen gen go --schema-glob author/schema.sql --query-glob author/query.sql

Does running the example from the repo work? My guess is that either schema file or query file has changed. The author example doesn't use json so that's odd. Can you verify the content hasn't changed?

bera-josh-jewell commented 2 years ago

thanks so much for getting back to me. I just pulled the repo and then tried again. I am getting the same error. It is really odd it's complaining about json. Is that how it serializes the data?

Here is my error image

Could this have anything to do with me running on windows?

jschaf commented 2 years ago

I’d suspect the database setup before blaming Windows. Pggen mostly just connects to Postgres

You’ll need Docker to run pggen without a Postgres connection. If the Docker approach works it’s probably the DB setup.

bera-josh-jewell commented 2 years ago

Just wanted to report back that using the docker image for postgres seemed to do the trick. Any guesses on what could be causing an issue with our existing database server?

jschaf commented 2 years ago

Any guesses on what could be causing an issue with our existing database server?

What's the output if you run the pggen queries manually, replacing the pggen.arg with a value? It might also help to add some data to the table to see the shape of data.

jschaf commented 2 years ago

Going to close as issue was resolved.