2021-03-29 15:43:37 +00:00
|
|
|
use crate::dbs::Executor;
|
2022-01-13 17:36:41 +00:00
|
|
|
use crate::dbs::Options;
|
2021-03-31 12:10:13 +00:00
|
|
|
use crate::dbs::Runtime;
|
2021-03-29 15:43:37 +00:00
|
|
|
use crate::err::Error;
|
2020-06-29 15:36:01 +00:00
|
|
|
use crate::sql::comment::shouldbespace;
|
|
|
|
use crate::sql::cond::{cond, Cond};
|
2022-01-16 20:31:50 +00:00
|
|
|
use crate::sql::error::IResult;
|
2020-06-29 15:36:01 +00:00
|
|
|
use crate::sql::fetch::{fetch, Fetchs};
|
|
|
|
use crate::sql::field::{fields, Fields};
|
2022-01-13 17:36:41 +00:00
|
|
|
use crate::sql::value::Value;
|
|
|
|
use crate::sql::value::{whats, Values};
|
2020-06-29 15:36:01 +00:00
|
|
|
use nom::bytes::complete::tag_no_case;
|
|
|
|
use nom::combinator::opt;
|
|
|
|
use nom::sequence::preceded;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use std::fmt;
|
|
|
|
|
2021-03-29 15:43:37 +00:00
|
|
|
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
|
2020-06-29 15:36:01 +00:00
|
|
|
pub struct LiveStatement {
|
|
|
|
pub expr: Fields,
|
2022-01-13 17:36:41 +00:00
|
|
|
pub what: Values,
|
2020-06-29 15:36:01 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub cond: Option<Cond>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub fetch: Option<Fetchs>,
|
|
|
|
}
|
|
|
|
|
2022-01-14 08:12:56 +00:00
|
|
|
impl LiveStatement {
|
|
|
|
pub async fn compute(
|
|
|
|
&self,
|
|
|
|
_ctx: &Runtime,
|
|
|
|
_opt: &Options<'_>,
|
|
|
|
_exe: &mut Executor,
|
|
|
|
_doc: Option<&Value>,
|
|
|
|
) -> Result<Value, Error> {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 15:36:01 +00:00
|
|
|
impl fmt::Display for LiveStatement {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "LIVE SELECT {} FROM {}", self.expr, self.what)?;
|
|
|
|
if let Some(ref v) = self.cond {
|
|
|
|
write!(f, " {}", v)?
|
|
|
|
}
|
|
|
|
if let Some(ref v) = self.fetch {
|
|
|
|
write!(f, " {}", v)?
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn live(i: &str) -> IResult<&str, LiveStatement> {
|
|
|
|
let (i, _) = tag_no_case("LIVE SELECT")(i)?;
|
|
|
|
let (i, _) = shouldbespace(i)?;
|
|
|
|
let (i, expr) = fields(i)?;
|
|
|
|
let (i, _) = shouldbespace(i)?;
|
|
|
|
let (i, _) = tag_no_case("FROM")(i)?;
|
|
|
|
let (i, _) = shouldbespace(i)?;
|
|
|
|
let (i, what) = whats(i)?;
|
|
|
|
let (i, cond) = opt(preceded(shouldbespace, cond))(i)?;
|
|
|
|
let (i, fetch) = opt(preceded(shouldbespace, fetch))(i)?;
|
|
|
|
Ok((
|
|
|
|
i,
|
|
|
|
LiveStatement {
|
|
|
|
expr,
|
|
|
|
what,
|
|
|
|
cond,
|
|
|
|
fetch,
|
|
|
|
},
|
|
|
|
))
|
|
|
|
}
|