-
Notifications
You must be signed in to change notification settings - Fork 4
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
chore: using mysql2 as library for serverless-mysql #374
base: master
Are you sure you want to change the base?
Conversation
@@ -383,7 +383,7 @@ export const initWalletTxHistory = async (mysql: ServerlessMysql, walletId: stri | |||
const results: DbSelectResult = await mysql.query( | |||
`SELECT \`tx_id\`, | |||
\`token_id\`, | |||
SUM(\`balance\`) AS balance, | |||
CAST(SUM(\`balance\`) AS INTEGER) AS balance, |
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.
mysql2
is returning SUM
, MIN
and MAX
as strings, so we can either cast it on mysql itself or on javascript, with parseInt
, I prefer doing it directly in mysql
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.
Casting to integer is fine but the SUM
returns a DECIMAL
(which the client converts to a string) because of a posible overflow and precision issues. Maybe we should check no cast has this problem, like a sum of output values that can go over the mysql native integer highest number.
cf8543e
to
84d84e6
Compare
@@ -6,7 +6,7 @@ | |||
"packages": { | |||
"": { | |||
"name": "hathor-wallet-service", | |||
"version": "1.23.0-beta", | |||
"version": "1.23.1-beta", |
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 last bump didn't update this, totally unrelated to the PR
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.
There are some warnings like "Argument 'mysql' should be typed" which can be fixed if we use the mysql2 types
@@ -383,7 +383,7 @@ export const initWalletTxHistory = async (mysql: ServerlessMysql, walletId: stri | |||
const results: DbSelectResult = await mysql.query( | |||
`SELECT \`tx_id\`, | |||
\`token_id\`, | |||
SUM(\`balance\`) AS balance, | |||
CAST(SUM(\`balance\`) AS INTEGER) AS balance, |
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.
Casting to integer is fine but the SUM
returns a DECIMAL
(which the client converts to a string) because of a posible overflow and precision issues. Maybe we should check no cast has this problem, like a sum of output values that can go over the mysql native integer highest number.
Motivation
The last update of the
mysql
library we were using was in Jan 23, 2020Acceptance Criteria
mysql2
as the library for serverless-mysql (mysql is the default)Security Checklist