Implement SQL query debugging in response output
This commit is contained in:
parent
92e24e2201
commit
ff5a5fd346
3 changed files with 23 additions and 0 deletions
|
@ -109,6 +109,7 @@ impl<'a> Executor<'a> {
|
|||
|
||||
pub fn buf_cancel(&self, v: Response) -> Response {
|
||||
Response {
|
||||
sql: v.sql,
|
||||
time: v.time,
|
||||
status: Status::Err,
|
||||
detail: Some(format!("Transaction cancelled")),
|
||||
|
@ -119,6 +120,7 @@ impl<'a> Executor<'a> {
|
|||
pub fn buf_commit(&self, v: Response) -> Response {
|
||||
match &self.err {
|
||||
Some(_) => Response {
|
||||
sql: v.sql,
|
||||
time: v.time,
|
||||
status: Status::Err,
|
||||
detail: match v.status {
|
||||
|
@ -157,6 +159,7 @@ impl<'a> Executor<'a> {
|
|||
"EVENT_QUERIES" => opt = opt.events(stm.what),
|
||||
"TABLE_QUERIES" => opt = opt.tables(stm.what),
|
||||
"IMPORT" => opt = opt.import(stm.what),
|
||||
"DEBUG" => opt = opt.debug(stm.what),
|
||||
_ => break,
|
||||
}
|
||||
continue;
|
||||
|
@ -249,6 +252,10 @@ impl<'a> Executor<'a> {
|
|||
// Produce the response
|
||||
let res = match res {
|
||||
Ok(v) => Response {
|
||||
sql: match opt.debug {
|
||||
true => Some(format!("{}", stm)),
|
||||
false => None,
|
||||
},
|
||||
time: format!("{:?}", dur),
|
||||
status: Status::Ok,
|
||||
detail: None,
|
||||
|
@ -257,6 +264,10 @@ impl<'a> Executor<'a> {
|
|||
Err(e) => {
|
||||
// Produce the response
|
||||
let res = Response {
|
||||
sql: match opt.debug {
|
||||
true => Some(format!("{}", stm)),
|
||||
false => None,
|
||||
},
|
||||
time: format!("{:?}", dur),
|
||||
status: Status::Err,
|
||||
detail: Some(format!("{}", e)),
|
||||
|
|
|
@ -14,6 +14,7 @@ use crate::sql::version::Version;
|
|||
pub struct Options<'a> {
|
||||
pub auth: &'a Auth,
|
||||
pub dive: usize, // How many subqueries have we gone into?
|
||||
pub debug: bool, // Should we debug query response SQL?
|
||||
pub force: bool, // Should we force tables/events to re-run?
|
||||
pub fields: bool, // Should we process field queries?
|
||||
pub events: bool, // Should we process event queries?
|
||||
|
@ -34,6 +35,7 @@ impl<'a> Options<'a> {
|
|||
Options {
|
||||
auth,
|
||||
dive: 0,
|
||||
debug: false,
|
||||
force: false,
|
||||
fields: true,
|
||||
events: true,
|
||||
|
@ -57,6 +59,14 @@ impl<'a> Options<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
// Create a new Options object for a subquery
|
||||
pub fn debug(&self, v: bool) -> Options<'a> {
|
||||
Options {
|
||||
debug: v,
|
||||
..*self
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new Options object for a subquery
|
||||
pub fn force(&self, v: bool) -> Options<'a> {
|
||||
Options {
|
||||
|
|
|
@ -13,6 +13,8 @@ pub struct Responses(pub Vec<Response>);
|
|||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Response {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub sql: Option<String>,
|
||||
pub time: String,
|
||||
pub status: Status,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
|
Loading…
Reference in a new issue