use crate::{
ast::CreateSchemaStmt,
binder::{BindError, Binder, bound::BoundCreateSchemaStmt},
common::symbol::Symbol,
};
impl<'c> Binder<'c> {
pub fn bind_create_schema(
&self,
db: Symbol,
stmt: CreateSchemaStmt,
) -> Result<BoundCreateSchemaStmt, BindError> {
if !self.catalog.database_exists(db) {
return Err(BindError::DatabaseNotFound(db));
}
if let Some(auth) = stmt.authorization {
if !self.catalog.role_exists(auth) {
return Err(BindError::RoleNotFound(auth));
}
}
let name = match stmt.name {
Some(n) => n,
None => stmt.authorization.unwrap_or(self.session_user),
};
if !stmt.if_not_exists && self.catalog.schema_exists(db, name) {
return Err(BindError::SchemaAlreadyExists(name));
}
Ok(BoundCreateSchemaStmt {
name: Some(name),
authorization: stmt.authorization,
if_not_exists: stmt.if_not_exists,
})
}
}