2023-01-19 09:53:33 +00:00
|
|
|
use crate::sql::fmt::Pretty;
|
2023-11-18 13:56:13 +00:00
|
|
|
use crate::sql::statement::{Statement, Statements};
|
2023-08-18 22:51:56 +00:00
|
|
|
use crate::sql::Value;
|
2022-05-21 00:35:59 +00:00
|
|
|
use derive::Store;
|
2023-08-17 18:03:46 +00:00
|
|
|
use revision::revisioned;
|
2020-06-29 15:36:01 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2023-01-19 09:53:33 +00:00
|
|
|
use std::fmt::Write;
|
2022-10-04 21:51:18 +00:00
|
|
|
use std::fmt::{self, Display, Formatter};
|
2022-05-04 21:34:28 +00:00
|
|
|
use std::ops::Deref;
|
2020-06-29 15:36:01 +00:00
|
|
|
use std::str;
|
|
|
|
|
2023-08-18 22:51:56 +00:00
|
|
|
pub(crate) const TOKEN: &str = "$surrealdb::private::sql::Query";
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Store, Hash)]
|
2023-08-17 18:03:46 +00:00
|
|
|
#[revisioned(revision = 1)]
|
2023-08-18 22:51:56 +00:00
|
|
|
#[serde(rename = "$surrealdb::private::sql::Query")]
|
2022-05-04 21:34:28 +00:00
|
|
|
pub struct Query(pub Statements);
|
2020-06-29 15:36:01 +00:00
|
|
|
|
2022-05-04 21:34:28 +00:00
|
|
|
impl Deref for Query {
|
|
|
|
type Target = Vec<Statement>;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.0 .0
|
2020-06-29 15:36:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-20 12:30:47 +00:00
|
|
|
impl IntoIterator for Query {
|
|
|
|
type Item = Statement;
|
|
|
|
type IntoIter = std::vec::IntoIter<Self::Item>;
|
|
|
|
fn into_iter(self) -> Self::IntoIter {
|
|
|
|
self.0.into_iter()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-18 22:51:56 +00:00
|
|
|
impl From<Query> for Value {
|
|
|
|
fn from(q: Query) -> Self {
|
|
|
|
Value::Query(q)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-04 21:51:18 +00:00
|
|
|
impl Display for Query {
|
|
|
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
2023-01-19 09:53:33 +00:00
|
|
|
write!(Pretty::from(f), "{}", &self.0)
|
2020-06-29 15:36:01 +00:00
|
|
|
}
|
|
|
|
}
|