I have a database field that is set to decimal, while in my Go project I am having problem choosing which datatype can be used. each time I send a create reuquest to my code, I get a "cannot marshal 'decimal' into #golang datatype#
this is my database schema
CREATE TABLE transaction(
organization_id timeuuid,
month text,
employee_id timeuuid,
id timeuuid,
employee_name text,
amount decimal,
deductions int,
date_approved date,
PRIMARY KEY ((organization_id, month), id)
)
my golang models looks like this
type WageGarnishment struct {
ID gocql.UUID `json:"id"`
organizationID gocql.UUID `json:"organization_id"`
Month string `json:"month"`
Amount Float64 `json:"amount"`
Deductions uint `json:"deductions"`
EffectiveDate time.Time `json:"effective_date"`
DateApproved time.Time `json:"date_approved"`
EmployeeSummary
}
no matter the datatype in my Amount Field I keep getting this Error:
Error #01: can not marshal float64 into decimal
Thanks for your Help in Advance
If you look into documentation for Gocql package, then you will see that the decimal
is mapped to the Go's infDec
data type (see its doc) so you need to use it instead of Float64
.