Skip to content

Commit 682180d

Browse files
authored
Add after_connected hook (#558)
1 parent fb9faa3 commit 682180d

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

pgdog/src/frontend/client/query_engine/hooks/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22
#![allow(unused_variables, dead_code)]
33
use super::*;
44

5+
#[derive(Debug)]
56
pub struct QueryEngineHooks;
67

8+
impl Default for QueryEngineHooks {
9+
fn default() -> Self {
10+
Self::new()
11+
}
12+
}
13+
714
impl QueryEngineHooks {
815
pub(super) fn new() -> Self {
916
Self {}
@@ -16,6 +23,14 @@ impl QueryEngineHooks {
1623
Ok(())
1724
}
1825

26+
pub(super) fn after_connected(
27+
&mut self,
28+
context: &mut QueryEngineContext<'_>,
29+
backend: &Connection,
30+
) -> Result<(), Error> {
31+
Ok(())
32+
}
33+
1934
pub(super) fn after_execution(
2035
&mut self,
2136
context: &mut QueryEngineContext<'_>,

pgdog/src/frontend/client/query_engine/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub struct QueryEngine {
5353
two_pc: TwoPc,
5454
notify_buffer: NotifyBuffer,
5555
pending_explain: Option<ExplainResponseState>,
56+
hooks: QueryEngineHooks,
5657
}
5758

5859
impl QueryEngine {
@@ -72,6 +73,7 @@ impl QueryEngine {
7273
backend,
7374
client_id: comms.client_id(),
7475
comms: comms.clone(),
76+
hooks: QueryEngineHooks::new(),
7577
#[cfg(test)]
7678
test_mode: true,
7779
#[cfg(not(test))]
@@ -125,8 +127,7 @@ impl QueryEngine {
125127
return Ok(());
126128
}
127129

128-
let mut hooks = QueryEngineHooks::new();
129-
hooks.before_execution(context)?;
130+
self.hooks.before_execution(context)?;
130131

131132
// Queue up request to mirrors, if any.
132133
// Do this before sending query to actual server
@@ -223,7 +224,7 @@ impl QueryEngine {
223224
command => self.unknown_command(context, command.clone()).await?,
224225
}
225226

226-
hooks.after_execution(context)?;
227+
self.hooks.after_execution(context)?;
227228

228229
if context.in_error() {
229230
self.backend.mirror_clear();

pgdog/src/frontend/client/query_engine/query.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ impl QueryEngine {
6868
}
6969
}
7070

71+
self.hooks.after_connected(context, &self.backend)?;
72+
7173
self.backend
7274
.handle_client_request(context.client_request, &mut self.router, self.streaming)
7375
.await?;

0 commit comments

Comments
 (0)