CreateSchema.cpp 764 B

12345678910111213141516171819202122232425262728
  1. /*
  2. * Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibSQL/AST/AST.h>
  7. #include <LibSQL/Database.h>
  8. #include <LibSQL/Meta.h>
  9. namespace SQL::AST {
  10. RefPtr<SQLResult> CreateSchema::execute(ExecutionContext& context) const
  11. {
  12. auto schema_def = context.database->get_schema(m_schema_name);
  13. if (schema_def) {
  14. if (m_is_error_if_schema_exists) {
  15. return SQLResult::construct(SQLCommand::Create, SQLErrorCode::SchemaExists, m_schema_name);
  16. }
  17. return SQLResult::construct(SQLCommand::Create);
  18. }
  19. schema_def = SchemaDef::construct(m_schema_name);
  20. context.database->add_schema(*schema_def);
  21. return SQLResult::construct(SQLCommand::Create, 0, 1);
  22. }
  23. }