-
Notifications
You must be signed in to change notification settings - Fork 395
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
Refactor database utils into a class #1689
base: staging
Are you sure you want to change the base?
Conversation
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.
Couple things:
I've noticed the schema env var was not documented in https://github.com/ethereum/sourcify/pull/1652/files Please add documentation for that including the env var and that it defaults to public.
I see we are no longer passing this.schema
but we still pass the client
in the Database functions. Can't we also remove that? node-postgres
says: "In fact, pool.query delegates directly to client.query internally": https://node-postgres.com/features/queries unless we are using a transaction: https://node-postgres.com/apis/pool#poolquery Maybe we can move the client acquisition and handling all inside the Database
and remove this from the DatabaseService
s.
As a side note, turns out we could pass this.schema
in the SQL query with pg-format
: https://node-postgres.com/features/queries#parameterized-query The docs say it can be vulnerable for injection. In our case it should be fine because this.schema
is not a user input, right? So we don't need to change that part of the code now.
Can you also check the "Prepared statements" docs if this is something we can take advantage of? https://node-postgres.com/features/queries#prepared-statements
Right
That's exactly why we are using it... "Maybe we can move the client acquisition and handling all inside the Database and remove this from the DatabaseServices." we can do this.
Yes, everything is passed via arguments except this.schema, I don't think we should care about this.schema being vulnerable because it's not passed by the users
Good idea |
Actually regarding this it's not that straightforward because multiple transactions can be initialized from a Pool. We cannot remove the let client: PoolClient;
try {
client = await this.database.beginTransaction();
onchainCreationCodeInsertResult = await this.database.insertCode(
client,
databaseColumns.onchainCreationCode,
);
} catch(e) {
await this.database.rollbackTransaction(client!);
} finally {
this.database.releaseClient(client!)
} Personally I don't think this is much better than before... @kuzdogan wdyt? |
Ok yes, I see. Moving the client acquisition inside |
@kuzdogan I added |
See #1653