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

Expose executor via InternalExecutorBundle on Client #494

Closed
wants to merge 4 commits into from

Conversation

bgentry
Copy link
Contributor

@bgentry bgentry commented Aug 2, 2024

This adds an InternalExecutorBundle() method to Client which returns a new driver.InternalExecutorBundle[TTx] interface type. The interface exposes the driver's internal executors via Executor() and ExecutorTx(tx) methods. This can enable external modules to run queries against River's underlying drivers, including arbitrary SQL.

Compatibility interfaces for ExecResult, Rows, and Row are able to paper over the basic differences between database/sql and pgx in order to expose just enough functionality for basic arbitrary SQL queries.

For now, this allows us to run simple SQL queries against River's drivers from external libraries. In the future, it could be a path toward extracting most of the duplicate queries in drivers into a shared query module that isn't driver-specific. Drivers would become a simpler interface focused on Exec/Query/QueryRow and row scanning details, rather than each needing to implement every query under the sun.

A final commit ef5dff2 demonstrates a possible extension of this pattern to expand the driver interface so that it can abstract all details of deserializing river_job rows, allowing driver-specific details like []byte vs string for json to be tucked away in a single implementation, even if external packages are able to run arbitrary queries for jobs. This commit can be omitted from merge but I wanted to at least illustrate the potential here.

@bgentry bgentry requested a review from brandur August 2, 2024 14:10
@bgentry bgentry force-pushed the bg-expose-executor branch 2 times, most recently from 84f18b8 to abebce8 Compare August 2, 2024 14:37
This adds an `InternalExecutorBundle()` method to `Client` which returns
a new `driver.InternalExecutorBundle[TTx]` interface type. The interface
exposes the driver's internal executors via `Executor()` and
`ExecutorTx(tx)` methods. This can enable external modules to run
queries against River's underlying drivers, including arbitrary SQL.

Compatibility interfaces for `ExecResult`, `Rows`, and `Row` are able to
paper over the basic differences between `database/sql` and `pgx` in
order to expose just enough functionality for basic arbitrary SQL
queries.
@bgentry bgentry mentioned this pull request Aug 3, 2024
@bgentry bgentry closed this Aug 3, 2024
@bgentry bgentry deleted the bg-expose-executor branch August 3, 2024 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant