-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
Allow passing a connection from publish to executeSql #200
Conversation
Adds the option to pass a connection from publish to executeSql. This allows creating transactions that encompass inserting jobs.
@@ -1,6 +1,6 @@ | |||
declare namespace PgBoss { | |||
interface Db { | |||
executeSql(text: string, values: any[]): Promise<{ rows: any[]; rowCount: number }>; | |||
executeSql(text: string, values: any[], options?: ExecutionOptions): Promise<{ rows: any[]; rowCount: number }>; |
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.
Maybe this ?
can be removed. It looks like options
will always be defined based on how its called.
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's a few places where executeSql is called without any values too: https://github.com/timgit/pg-boss/blob/master/src/contractor.js#L26
I'm not super familiar with typescript, is that valid?
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.
My bad! I assumed executeSql
was only called there
@timgit What do you think about this patch? |
A couple things I'd like to see in this PR.
|
Playing catchup on a few things and might not have time to get at this for a few days. Looking at it with fresh eyes, 100% agree the interface is kind of weird.
Are you saying instead of this:
We instead pass in a db object? like this?
It's a bit more work, but would make it obvious that Or, could even do something like this:
Personally I prefer the last form, as it gets straight to the point. |
Yes, this form aligns with the constructor option, which makes it a bit more clear of what the intention is. await boss.publish({ name: 'passConnection', options: { db: wrapper } }) I agree it's a bit more setup for the caller, but this should make the internals a bit more ignorant of what's going on. The goal would be to simply swap out the normal db service with an override if it's passed in. This should make |
Sad that this has never made it into some release. Inserting directly into the job table to use transactions feels a bit error-prone to me, especially when things change under the hood. |
Adds the option to pass a connection from publish to executeSql.
This allows creating transactions that encompass inserting jobs.
The test seems a bit messy, open to suggestions.
Fixes #199