use super::{binding, run_drop_inner, RelationRemovalContext};
use uqa_sql::{
ast::{DropKind, DropStmt},
SQLError,
};
pub fn drop_table(context: &RelationRemovalContext<'_>, name: &str) -> Result<bool, SQLError> {
drop_relation(context, name, DropKind::Table)
}
pub fn drop_foreign_table(
context: &RelationRemovalContext<'_>,
name: &str,
) -> Result<bool, SQLError> {
drop_relation(context, name, DropKind::ForeignTable)
}
pub fn drop_sequence(context: &RelationRemovalContext<'_>, name: &str) -> Result<bool, SQLError> {
drop_relation(context, name, DropKind::Sequence)
}
fn drop_relation(
context: &RelationRemovalContext<'_>,
name: &str,
kind: DropKind,
) -> Result<bool, SQLError> {
let statement = DropStmt {
kind,
names: vec![name.to_string()],
if_exists: true,
cascade: false,
};
let names = binding::bind_drop_targets(context, &statement, &mut |_| {})?;
if names.is_empty() {
return Ok(false);
}
run_drop_inner(context, DropStmt { names, ..statement })?;
Ok(true)
}