Repository navigation
Generate exact Decimal128 and Money fields - #81
Merged
Merged
Conversation
A generated decimal field was a Float64 column over DECIMAL(10,2), which
could not be read back on PostgreSQL (ColumnTypeMismatchError) or on
SQLite for whole values. decimal now generates an exact Grant::Decimal128
column and the new money type a Grant::Money column.
- price:decimal -> column price : Grant::Decimal128?, precision: 18, scale: 4;
'price:decimal{38,10}' sets precision (1..38) and scale (0..precision).
- total:money -> column total : Grant::Money?, precision: 18, scale: 4 plus a
total_currency column; total:money{USD} or 'total:money{18,2,USD}' fixes the
currency (currency: "USD") with no companion column.
- Migrations match Grant's storage: pg NUMERIC(p,s), mysql DECIMAL(p,s),
sqlite INTEGER up to 18 digits and TEXT from 19 to 38; currency VARCHAR(3)
(TEXT on sqlite).
- Schemas take amounts as String and check them with a method validator
(422 for text that is not an exact decimal or ISO 4217 code). Scaffolds
read the posted form text, since Amber's form parser reads numbers as
Float64; APIs read the JSON string.
- Forms use a number input stepped to the scale plus a currency input;
generated specs use exact strings such as "19.99" and check the round trip.
- Help text and documentation list the new syntax.
crimson-knight
marked this pull request as ready for review
November 27, 2026 17:57
This was referenced Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relay G5 (zero-native-library), amber_cli item. Draft, do not merge yet: it generates code against Grant's
Grant::Decimal128/Grant::Moneycolumns, which are being built in parallel in crimson-knight/grant (g5/decimal128-money-columns). The relay merges after an end-to-end app test against both.What changes
A generated
decimalfield used to beFloat64overDECIMAL(10,2)and could not be read back on PostgreSQL (ColumnTypeMismatchError) or on SQLite for whole values.price:decimalcolumn price : Grant::Decimal128?, precision: 18, scale: 4NUMERIC(18,4)DECIMAL(18,4)INTEGER'price:decimal{38,10}'..., precision: 38, scale: 10NUMERIC(38,10)DECIMAL(38,10)TEXTtotal:moneycolumn total : Grant::Money?, precision: 18, scale: 4total_currency VARCHAR(3)VARCHAR(3)TEXTtotal:money{USD}/'total:money{18,2,USD}'..., currency: "USD"Precision 1..38, scale 0..precision; out-of-range options stop the generator with a message. Braces with a comma must be quoted (the shell expands them); an expanded
price:decimal38gets a hint saying so.Stringand a method validator answers 422 for text that is not an exact decimal or an ISO 4217 code.19.99into Float64, which keeps only about 15 digits); API controllers read the JSON string.stepfrom the scale, plus a currency input for money."19.99") and a round-trip check.Verification
crystal-alpha spec: 856 examples, 4 failures, 5 errors. All 9 are amber-lsp binary/stdlib lookup specs that fail identically on unmodifiedmainlocally (no built amber-lsp binary).amber newapp withscaffold Product price:decimal total:money name:stringandapi Invoice 'amount:decimal{38,10}:required' 'fee:money{EUR}' 'total:money{18,2}:required', built against Amber 2.0.0-beta.16 and a snapshot of the in-progress Grant branch: type-checks, and its 19 generated specs pass on SQLite. Scratch specs also showed 18 digits through the HTML form, 38 digits through the JSON API, and 422 forprice=abc.