summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibSQL/AST/CreateSchema.cpp
blob: a41cc3a269b9344600acd82e80424e176de35872 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
 * 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 {

ResultOr<ResultSet> CreateSchema::execute(ExecutionContext& context) const
{
    auto schema_def = TRY(context.database->get_schema(m_schema_name));

    if (schema_def) {
        if (m_is_error_if_schema_exists)
            return Result { SQLCommand::Create, SQLErrorCode::SchemaExists, m_schema_name };
        return ResultSet { SQLCommand::Create };
    }

    schema_def = SchemaDef::construct(m_schema_name);
    TRY(context.database->add_schema(*schema_def));

    return ResultSet { SQLCommand::Create };
}

}