CreateSchema.cpp 634 B

12345678910111213141516171819202122232425
  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. ResultOr<ResultSet> CreateSchema::execute(ExecutionContext& context) const
  11. {
  12. auto schema_def = SchemaDef::construct(m_schema_name);
  13. if (auto result = context.database->add_schema(*schema_def); result.is_error()) {
  14. if (result.error().error() != SQLErrorCode::SchemaExists || m_is_error_if_schema_exists)
  15. return result.release_error();
  16. }
  17. return ResultSet { SQLCommand::Create };
  18. }
  19. }