-
Notifications
You must be signed in to change notification settings - Fork 10
feat: support decimal #58
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
dc15bfb
c186a73
6c3459f
f486bab
100bba6
5a3e29b
b2e697e
a1c3981
d2b6670
a7f4c07
b6e5de3
f3222af
8405773
8e4947f
0f8349b
4746449
e777a3b
36d7070
2d84a90
a2c068d
6677246
7ebdb94
e8d4fa1
04d4bdc
d7e05d5
cf9cfb7
f3762c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -573,6 +573,47 @@ func (b *buffer) Float64Column(name string, val float64) *buffer { | |
| return b | ||
| } | ||
|
|
||
| func (b *buffer) DecimalColumn(name string, val any) *buffer { | ||
|
||
| if !b.prepareForField() { | ||
| return b | ||
| } | ||
| b.lastErr = b.writeColumnName(name) | ||
| if b.lastErr != nil { | ||
| return b | ||
| } | ||
| b.WriteByte('=') | ||
| if str, ok := val.(string); ok { | ||
| if err := validateDecimalText(str); err != nil { | ||
| b.lastErr = err | ||
| return b | ||
| } | ||
| b.WriteString(str) | ||
| b.WriteByte('d') | ||
| b.hasFields = true | ||
| return b | ||
| } | ||
|
|
||
| dec, err := normalizeDecimalValue(val) | ||
| if err != nil { | ||
| b.lastErr = err | ||
| return b | ||
| } | ||
| scale, payload, err := dec.toBinary() | ||
| if err != nil { | ||
| b.lastErr = err | ||
| return b | ||
| } | ||
| b.WriteByte('=') | ||
| b.WriteByte(decimalBinaryTypeCode) | ||
| b.WriteByte(scale) | ||
| b.WriteByte(byte(len(payload))) | ||
| if len(payload) > 0 { | ||
| b.Write(payload) | ||
| } | ||
| b.hasFields = true | ||
| return b | ||
| } | ||
|
|
||
| func (b *buffer) Float64ColumnBinary(name string, val float64) *buffer { | ||
| if !b.prepareForField() { | ||
| return b | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we want to support this 3rd-party library? I've checked it and the last release was 1.5 years ago while there are 100+ open GH issues, some of which look like straightforward bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be the only popular decimal integration in the golang ecosystem.
Having initial support for it makes it easier for customers to connect to QDB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The library is not maintained and it also mentions alternatives, some of which are actively maintained and more performant:
https://github.com/cockroachdb/apd
https://github.com/alpacahq/alpacadecimal
https://github.com/govalues/decimal
https://github.com/greatcloak/decimal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of these libraries are near as popular as shopspring, and most of them aren't more actively maintained too