2021-06-27 21:32:22 -04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibSQL/AST/AST.h>
|
|
|
|
#include <LibSQL/Database.h>
|
|
|
|
#include <LibSQL/Meta.h>
|
|
|
|
|
|
|
|
namespace SQL::AST {
|
|
|
|
|
2022-02-10 14:43:00 -05:00
|
|
|
ResultOr<ResultSet> CreateSchema::execute(ExecutionContext& context) const
|
2021-06-27 21:32:22 -04:00
|
|
|
{
|
2022-11-29 08:24:15 -05:00
|
|
|
auto schema_def = SchemaDef::construct(m_schema_name);
|
2022-02-09 15:57:57 -05:00
|
|
|
|
2022-11-29 08:24:15 -05:00
|
|
|
if (auto result = context.database->add_schema(*schema_def); result.is_error()) {
|
|
|
|
if (result.error().error() != SQLErrorCode::SchemaExists || m_is_error_if_schema_exists)
|
|
|
|
return result.release_error();
|
2021-06-27 21:32:22 -04:00
|
|
|
}
|
|
|
|
|
2022-02-10 14:43:00 -05:00
|
|
|
return ResultSet { SQLCommand::Create };
|
2021-06-27 21:32:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|