Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mysql Decimal Data Type Support #121

Closed
cyrainfish opened this issue Mar 28, 2017 · 2 comments
Closed

Mysql Decimal Data Type Support #121

cyrainfish opened this issue Mar 28, 2017 · 2 comments

Comments

@cyrainfish
Copy link

It's really useful for me to generate ORM from Mysql, but I just find "Decimal Data Type" is regarded as string/null.String. Is there any special reason for this? If no, I'm hoping to convert it to float64/null.Float64 like below:

  •           case "double", "double precision", "real":
    
  •           case "double", "double precision", "real", "decimal":
    

File : github.com/vattle/sqlboiler/bdb/drivers/mysql.go

Thanks!
Yu

@nullbio
Copy link
Member

nullbio commented Mar 28, 2017

This was done because float64 can have precision errors when dealing with decimal values, which is particularly dangerous for financial code. You will need to do the conversions yourself for this, as there is no adequate storage in the stdlib to safely represent the decimal values yet, as far as I am aware.

Here were some declined proposals:

golang/go#12332
golang/go#12127

Here are some libraries that seem to be popular for conversions:

https://github.com/shopspring/decimal
https://github.com/ericlagergren/decimal

If precision is not important to you then you can just use strconv.ParseFloat().

@nullbio nullbio closed this as completed Mar 28, 2017
@aarondl
Copy link
Member

aarondl commented Mar 28, 2017

Keep in mind that we've talked about a custom driver that would allow you to select your own data types here: https://github.com/vattle/sqlboiler/pull/102
We'll get to it but eventually but it's not on any immediate roadmaps as we're busy on other things atm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants