Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andreabadesso
Copy link
Collaborator

Motivation

The last update of the mysql library we were using was in Jan 23, 2020

Acceptance Criteria

  • We should use mysql2 as the library for serverless-mysql (mysql is the default)
  • We should remove the mysql dependency

Security Checklist

  • Make sure you do not include new dependencies in the project unless strictly necessary and do not include dev-dependencies as production ones. More dependencies increase the possibility of one of them being hijacked and affecting us.

@@ -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,
Copy link
Collaborator Author

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

Copy link
Member

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.

@@ -6,7 +6,7 @@
"packages": {
"": {
"name": "hathor-wallet-service",
"version": "1.23.0-beta",
"version": "1.23.1-beta",
Copy link
Collaborator Author

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

Copy link
Member

@r4mmer r4mmer left a 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,
Copy link
Member

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.

@luislhl luislhl changed the base branch from dev to master April 21, 2023 12:41
@tuliomir tuliomir removed their request for review July 7, 2023 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants