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-09 15:57:57 -05:00
|
|
|
Result CreateSchema::execute(ExecutionContext& context) const
|
2021-06-27 21:32:22 -04:00
|
|
|
{
|
2022-02-09 15:57:57 -05:00
|
|
|
auto schema_def = TRY(context.database->get_schema(m_schema_name));
|
|
|
|
|
2021-06-27 21:32:22 -04:00
|
|
|
if (schema_def) {
|
2022-02-09 15:57:57 -05:00
|
|
|
if (m_is_error_if_schema_exists)
|
|
|
|
return { SQLCommand::Create, SQLErrorCode::SchemaExists, m_schema_name };
|
|
|
|
return { SQLCommand::Create };
|
2021-06-27 21:32:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
schema_def = SchemaDef::construct(m_schema_name);
|
2022-02-09 15:57:57 -05:00
|
|
|
TRY(context.database->add_schema(*schema_def));
|
|
|
|
|
|
|
|
return { SQLCommand::Create, 0, 1 };
|
2021-06-27 21:32:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|