Comments (9)
@go-jet thank you for making this change. We now use the decimal
branch as our officially supported jet version. It would be great if you merge that branch into develop
and eventually do an official release. We decided to use string
in our models instead of a third party decimal library. We do the appropriate conversion elsewhere as needed.
FYI we use a bash script wrapper around the jet
code generator to replace the types in the models when they are generated. I documented what we do in this gist:
https://gist.github.com/mlaflamm/5093c5877b401f608a1a737fab7b662c
This might be of interest for other jet users.
from jet.
@crazydadz Agreed, make sense.
@mlaflamm Rebased.
from jet.
I've created a new PR that add a test to write a decimal into the database. #62
from jet.
Lossless decimal scan is now included in the latests v2.5.0 release.
from jet.
It is not possible to customize generated model at the moment. This feature will be added later.
But it is possible to create custom model file, and even to combine custom with generated model files.
Also as a go struct field it is possible to use any type that implements Scanner
interface.
Assuming table name is my_table
, column is money
and that you want to retrieve sql numeric type to go integer type, something like this should be possible:
type MoneyType int64 // or some other type
func (e *MoneyType) Scan(value interface{}) error {
... add implementation
}
type MyTable struct {
model.MyTable
Money MoneyType
}
Now it is possible to use MyTable
in any place where model.MyTable
is used before.
from jet.
We ran into a similar issue. Unfortunately even with your suggestion to use a customised model, the value is converted to a sql.NullFloat64
in qrm/utill.go before being passed to the custom type Scan
.
To work correctly, the value must be converted to a lossless decimal type, like ericlagergren/decimal. Using sql.NullString
instead of sql.NullFloat64
would likely work too. I am sure this could be implemented in a way that doesn't break projects that use the generated models with float64
.
from jet.
Yes, you right, exact decimal types(decimal
and numeric
) should have been first converted to string.
I've made a quick fix(decimals branch) which enables scan into custom lossless decimal types using customized model types.(sample usage)
Note that scan from decimal
and numeric
into float64 is disabled on this branch.
from jet.
Would it be possible to base your branch from develop
? We would like to try it but we have a strong dependency on #51.
from jet.
I've done a PR (#61) based on your decimal branch that is backward compatible with existing generated models that uses the float64
type. All the postgres
tests are passing. This may breaks custom models that defined their own decimal type but paradoxically this may be a good thing if anyone cares about decimal precision.
from jet.
Related Issues (20)
- Alias is broken or I'm doing something wrong HOT 7
- Multiple dynamic WHERE statements HOT 1
- Small typo in wiki HOT 1
- Postgis geography type shows as `postgres.ColumnString` HOT 3
- More convenient way to implement raw/custom operators HOT 5
- Support `WHERE "column" = ANY($1)` HOT 7
- Should return value with return type HOT 1
- Support `WHERE()` on `INSERT ON CONFLICT DO UPDATE` HOT 2
- Support for SQLite FTS5? HOT 2
- Missing struct fields in SELECT due to Postgres truncation of identifiers HOT 4
- Unsupported sql column for the array in postgres HOT 2
- Incorrect Docs: Generator Customization references invalid interfaces HOT 5
- `Generate` function signature doesn't match documentation HOT 1
- Is there a way to make generic db functions for all models/tables? HOT 1
- Sqlite GENERATE columns, but being used in INSERT HOT 4
- Support for keyword arguments to functions HOT 3
- Support for filtered aggregations HOT 1
- Improving Document about SELECT clause. HOT 3
- ProjectionList{ColumnList{...}}.As("some_alias") results in no columns being rendered in the SQL HOT 2
- Ability to add db tags to use pgx struct scanning HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jet.