Skip to content

Commit

Permalink
wip sql: clean up schema [rebase before Local engine cleanup]
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgrinaker committed Jun 18, 2024
1 parent a856b1d commit 0378d12
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 206 deletions.
2 changes: 2 additions & 0 deletions src/sql/engine/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ impl<E: storage::Engine> super::Transaction for Transaction<E> {
}

fn delete(&self, table: &str, ids: &[Value]) -> Result<()> {
// Check for foreign key referenes.

// TODO: try to be more clever than simply iterating over each ID.
for id in ids {
let table = self.must_get_table(table)?;
Expand Down
48 changes: 23 additions & 25 deletions src/sql/plan/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,30 @@ impl<'a, C: Catalog> Planner<'a, C> {
ast::Statement::Explain(_) => panic!("unexpected explain statement"),

// DDL statements (schema changes).
ast::Statement::CreateTable { name, columns } => Plan::CreateTable {
schema: Table::new(
name,
columns
.into_iter()
.map(|c| {
let nullable = c.nullable.unwrap_or(!c.primary_key);
let default = match c.default {
Some(expr) => Some(self.evaluate_constant(expr)?),
None if nullable => Some(Value::Null),
None => None,
};
Ok(Column {
name: c.name,
datatype: c.datatype,
primary_key: c.primary_key,
nullable,
default,
index: c.index && !c.primary_key,
unique: c.unique || c.primary_key,
references: c.references,
})
ast::Statement::CreateTable { name, columns } => {
let columns = columns
.into_iter()
.map(|c| {
let nullable = c.nullable.unwrap_or(!c.primary_key);
let default = match c.default {
Some(expr) => Some(self.evaluate_constant(expr)?),
None if nullable => Some(Value::Null),
None => None,
};
Ok(Column {
name: c.name,
datatype: c.datatype,
primary_key: c.primary_key,
nullable,
default,
index: c.index && !c.primary_key,
unique: c.unique || c.primary_key,
references: c.references,
})
.collect::<Result<_>>()?,
)?,
},
})
.collect::<Result<_>>()?;
Plan::CreateTable { schema: Table { name, columns } }
}

ast::Statement::DropTable { name, if_exists } => {
Plan::DropTable { table: name, if_exists }
Expand Down
Loading

0 comments on commit 0378d12

Please sign in to comment.