volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.66k stars 539 forks source link

Type match should happen as part of column translation #473

Open autarch opened 5 years ago

autarch commented 5 years ago

If you're having a generation problem please answer these questions before submitting your issue. Thanks!

What version of SQLBoiler are you using (sqlboiler --version)?

SQLBoiler v3.2.0

If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)

sqlboiler -c ./sqlboiler.toml psql

If this happened at runtime what code produced the issue? (if not applicable leave blank)

What is the output of the command above with the -d flag added to it? (Provided you are comfortable sharing this, it contains a blueprint of your schema)

Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)

This can be replicated with basically any non-enum custom type in Pg. The type in this case looks like this:

CREATE DOMAIN non_empty_citext AS CITEXT CHECK ( value != '' );

Further information. What did you do, what did you expect?

When I create the models for our schema I get this warning: warning: incompatible data type detected: non_empty_citext

I had tried to get rid of the warning by defining a type conversion in the config file, but that doesn't help, because those mappings are not looked at until after the code that issues the warning.

This isn't a big deal, since ultimately it defaults to using a string in this case, which is the right type, but it'd be nice if we could stop the warnings by defining the right type mapping in our config. The way the code is designed makes this impossible right now.

I think the easiest way to do this would be to pass the mappings into the driver (as JSON for the binary drivers) and have them use them, rather than running the driver's Assemble and then applying the mappings.

aarondl commented 5 years ago

This is doable. So long as the implementation of processTypeReplacements stays in the drivers package somewhere where all drivers can share it.