Skip to main content

surrealdb_expr/expr/statements/
create.rs

1use surrealdb_types::{SqlFormat, ToSql};
2
3use crate::expr::{Data, Expr, Literal, Output};
4
5#[derive(Clone, Debug, Eq, PartialEq, Hash)]
6pub struct CreateStatement {
7	// A keyword modifier indicating if we are expecting a single result or several
8	pub only: bool,
9	// Where we are creating (i.e. table, or record ID)
10	pub what: Vec<Expr>,
11	// The data associated with the record being created
12	pub data: Option<Data>,
13	//  What the result of the statement should resemble (i.e. Diff or no result etc).
14	pub output: Option<Output>,
15	// The timeout for the statement
16	pub timeout: Expr,
17}
18
19impl Default for CreateStatement {
20	fn default() -> Self {
21		Self {
22			only: Default::default(),
23			what: Default::default(),
24			data: Default::default(),
25			output: Default::default(),
26			timeout: Expr::Literal(Literal::None),
27		}
28	}
29}
30
31impl ToSql for CreateStatement {
32	fn fmt_sql(&self, f: &mut String, fmt: SqlFormat) {
33		let stmt: crate::sql::statements::create::CreateStatement = self.clone().into();
34		stmt.fmt_sql(f, fmt);
35	}
36}