CreateSchema.cpp 733 B

1234567891011121314151617181920212223242526272829
  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 = TRY(context.database->get_schema(m_schema_name));
  13. if (schema_def) {
  14. if (m_is_error_if_schema_exists)
  15. return Result { SQLCommand::Create, SQLErrorCode::SchemaExists, m_schema_name };
  16. return ResultSet { SQLCommand::Create };
  17. }
  18. schema_def = SchemaDef::construct(m_schema_name);
  19. TRY(context.database->add_schema(*schema_def));
  20. return ResultSet { SQLCommand::Create };
  21. }
  22. }