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

feat(js-connectors): DX, enable hooks for connect() and disconnect() #4177

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

jkomyno
Copy link
Contributor

@jkomyno jkomyno commented Aug 29, 2023

This PR ensures that:

  • QueryEngine::connect() calls the connect() method on the given JS Connector
  • QueryEngine::disconnect() calls the disconnect() method on the given JS Connector

This PR is based on #4174.

@jkomyno jkomyno changed the base branch from main to feat/node-drivers-dx August 29, 2023 13:14
@codspeed-hq
Copy link

codspeed-hq bot commented Aug 29, 2023

CodSpeed Performance Report

Merging #4177 will not alter performance

Comparing feat/node-drivers-dx-connect-disconnect (b2517dd) with feat/node-drivers-dx (e7b2fc5)

Summary

✅ 11 untouched benchmarks

Comment on lines 115 to 118
async disconnect() {
debug('[js::disconnect]')
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One would be inclined to run await this.pool.end() upon disconnection, releasing the connection pool resources.
This operation can only be done once per pool, or it would trigger an error. However, one can freely alternate await prisma.$connect() with await prisma.$disconnect(), so we can't release the pool on disconnect().

Would the Node.js process remain hanging due to pending database connections? No, they would be automatically released a few milliseconds after the last query execution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For that and previous comment, I think semantically correct (as in, "does what the method name suggests" thing would be creating pool in connect each time it's called and then completely destroy it in disconnect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or are we just adding stubs for methods and will do actual implementation later?

Comment on lines +111 to +113
async connect() {
debug('[js::connect]')
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One would be inclined to add await this.pool.connect(), but that wouldn't refresh the pool connections.
Rather, it would select one to use that as a "transactional client".

@@ -99,6 +99,17 @@ pub trait Queryable: Send + Sync {
fn requires_isolation_first(&self) -> bool;
}

#[async_trait]
pub trait Connectable: Queryable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this trait be moved to js-connectors instead? I don't think quaint's connecteors implement that, JsConnector is the only one that needs it.

@@ -128,3 +139,5 @@ macro_rules! impl_default_TransactionCapable {
}

pub(crate) use impl_default_TransactionCapable;

pub trait JsConnectorLike: TransactionCapable + Connectable {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here, this looks out of place in quaint to me.

Base automatically changed from feat/node-drivers-dx to main September 5, 2023 15:36
@janpio janpio added the topic: driver adapters formerly phase 1 label Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: driver adapters formerly phase 1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants