-
Notifications
You must be signed in to change notification settings - Fork 552
/
schema.rs
39 lines (33 loc) · 880 Bytes
/
schema.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::error::Result;
use crate::sql::engine::Transaction;
use crate::sql::types::schema::Table;
/// A CREATE TABLE executor
pub struct CreateTable {
table: Table,
}
impl CreateTable {
pub fn new(table: Table) -> Self {
Self { table }
}
pub fn execute(self, txn: &mut impl Transaction) -> Result<()> {
txn.create_table(self.table)
}
}
/// A DROP TABLE executor
pub struct DropTable {
table: String,
if_exists: bool,
}
impl DropTable {
pub fn new(table: String, if_exists: bool) -> Self {
Self { table, if_exists }
}
pub fn execute(self, txn: &mut impl Transaction) -> Result<bool> {
// TODO the planner should deal with this.
if self.if_exists && txn.get_table(&self.table)?.is_none() {
return Ok(false);
}
txn.drop_table(&self.table)?;
Ok(true)
}
}