sql/query/
create_schema.rs1use crate::{Dialect, ToSql};
2use crate::util::SqlExtension;
3
4#[derive(Debug)]
5pub struct CreateSchema {
6 pub name: String,
7 pub if_not_exists: bool,
8}
9
10impl CreateSchema {
11 pub fn new(name: &str) -> Self {
12 CreateSchema {
13 name: name.to_string(),
14 if_not_exists: false,
15 }
16 }
17
18 pub fn if_not_exists(mut self) -> Self {
19 self.if_not_exists = true;
20 self
21 }
22}
23
24impl ToSql for CreateSchema {
25 fn write_sql(&self, buf: &mut String, _: Dialect) {
26 buf.push_str("CREATE SCHEMA ");
27 if self.if_not_exists {
28 buf.push_str(" IF NOT EXISTS ");
29 }
30 buf.push_quoted(&self.name);
31 }
32}