Skip to content

Commit

Permalink
chore: fix server.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
KKould committed Dec 20, 2024
1 parent 0e44dbf commit 6255acb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 14 additions & 12 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,21 @@ impl SimpleQueryHandler for SessionBackend {
_ => {
let mut guard = self.tx.lock();

let iter = if let Some(transaction) = guard.as_mut() {
unsafe { transaction.as_mut().run(query) }.map(Box::new)
as Result<Box<dyn ResultIter>, _>
} else {
self.inner.run(query).map(Box::new)
}
.map_err(|e| PgWireError::ApiError(Box::new(e)))?;

let mut tuples = Vec::new();
for tuple in iter {
tuples.push(tuple.map_err(|e| PgWireError::ApiError(Box::new(e)))?);
}
Ok(vec![Response::Query(encode_tuples(iter.schema(), tuples)?)])
let response = if let Some(transaction) = guard.as_mut() {
let mut iter = unsafe { transaction.as_mut().run(query) }.map_err(|e| PgWireError::ApiError(Box::new(e)))?;
for tuple in iter.by_ref() {
tuples.push(tuple.map_err(|e| PgWireError::ApiError(Box::new(e)))?);
}
encode_tuples(iter.schema(), tuples)?
} else {
let mut iter = self.inner.run(query).map_err(|e| PgWireError::ApiError(Box::new(e)))?;
for tuple in iter.by_ref() {
tuples.push(tuple.map_err(|e| PgWireError::ApiError(Box::new(e)))?);
}
encode_tuples(iter.schema(), tuples)?
};
Ok(vec![Response::Query(response)])
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ impl<S: Storage> Database<S> {
}
}

pub trait ResultIter: Iterator<Item = Result<Tuple, DatabaseError>> + Sized {
pub trait ResultIter: Iterator<Item = Result<Tuple, DatabaseError>> {
fn schema(&self) -> &SchemaRef;

fn done(self) -> Result<(), DatabaseError>;
Expand Down

0 comments on commit 6255acb

Please sign in to comment.