Closed osawyerr closed 1 year ago
hi @osawyerr , there are public getters for these fields, you can access with .row_schema()
Yes I saw those. But they return & and its not clear how to convert a &BoxStream
to a BoxStream
for the data_rows, for example.
I tried using as_ref()
but then you cant call next()
on what that returns:
let mut data_rows = results.data_rows().as_ref();
while let Some(row) = data_rows.next().await {
...
226 | while let Some(row) = data_rows.next().await {
| ^^^^^^^^^ ---- required by a bound introduced by this call
| |
| the trait `Unpin` is not implemented for `dyn Stream<Item = Result<pgwire::messages::data::DataRow, PgWireError>> + std::marker::Send`
This doesn't work either:
let mut data_rows = results.data_rows();
while let Some(row) = data_rows.next().await {
...
228 | while let Some(row) = data_rows.next().await {
| ^^^^^^^^^^^^^^^^ `data_rows` is a `&` reference, so the data it refers to cannot be borrowed as mutable
I see. I'm on vocation today and will look into this issue tonight. Perhaps we can add owned version of getters for both fields.
By the way, I just exposed send_query_response
in 0.13.1
I'm not sure if it's what you need.
Yes thats working well thanks. You might consider making the other helper methods public as well to make defining a ExtendedQueryHandler
easier - send_execution_response
, send_describe_response
, etc
Also I have a question, how can we force the ExtendedQueryHandler
to always be called? I have defined it and added it to process_socket
but the SimpleQueryHandler
is being called when I send a query select * from my_table
. Is there a way to disable this?
Just for some background, the reason I'm doing this is I want to call a method foo()
before the do_query()
method is executed (it can't be called in the body of do_query()
). Thats why I am writing an ExtendedQueryHandler
so that I can call foo()
in on_execute
. For further context,foo()
returns an object that needs to be alive when do_query()
completes. But because do_query()
streams, foo()
cannot be called in do_query()
. It needs to be called before do_query()
I'm not sure if using an ExtendedQueryHandler
is the best way to achieve this.
Also I have a question, how can we force the ExtendedQueryHandler to always be called? I have defined it and added it to process_socket but the SimpleQueryHandler is being called when I send a query select * from my_table. Is there a way to disable this?
It depends on what type of subquery the client uses. For example, psql
always uses simple
subprotocol and sends query in plain text, thus SimpleQueryHandler
are used to respond it. Clients like JDBC use extended
subprotocol by default so ExtendedQueryHandler
are called.
I assume you are using foo()
to setup some resource to support do_query()
. Is it possible to call foo()
upon the initialization of SimpleQueryHandler
and ExtendedQueryHandler
. Both handlers can be implemented on same object. And they are initialized for each client connection.
Ah that makes sense. I'm using psql for my tests.
I assume you are using foo() to setup some resource to support do_query(). Is it possible to call foo() upon the initialization of SimpleQueryHandler and ExtendedQueryHandler. Both handlers can be implemented on same object. And they are initialized for each client connection.
Yes its setting up a resource required for do_query()
. Hmmm, I did consider setting the resource up when SimpleQueryHandler
and ExtendedQueryHandler
are initialised as you mentioned. However, those are initialised each time a client connects for the lifetime of the connection. But the requirement is that the resource needs to be initialised on a per query basis.
OK. Then I think you will need to override on_query
from SimpleQueryHandler
and on_execute
from ExtendedQueryHandler
for your case.
Hi there. I'm trying to override
ExtendedQueryHandler::on_execute()
I'm basing my implementation on something similar to the default implementation. However I don't have access toQueryResponse::data_rows
andQueryResponse::row_schema
because they arepub(crate)
.Was this intentional? If so, how can we get access to data_rows so we can iterate through it?