rippled
Loading...
Searching...
No Matches
RelationalDatabase.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2020 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/main/Application.h>
21#include <xrpld/app/rdb/RelationalDatabase.h>
22#include <xrpld/core/ConfigSections.h>
23
24namespace ripple {
25
27getSQLiteDatabase(Application& app, Config const& config, JobQueue& jobQueue);
28
31 Application& app,
32 Config const& config,
33 JobQueue& jobQueue)
34{
35 bool use_sqlite = false;
36
37 Section const& rdb_section{config.section(SECTION_RELATIONAL_DB)};
38 if (!rdb_section.empty())
39 {
40 if (boost::iequals(get(rdb_section, "backend"), "sqlite"))
41 {
42 use_sqlite = true;
43 }
44 else
45 {
46 Throw<std::runtime_error>(
47 "Invalid rdb_section backend value: " +
48 get(rdb_section, "backend"));
49 }
50 }
51 else
52 {
53 use_sqlite = true;
54 }
55
56 if (use_sqlite)
57 {
58 return getSQLiteDatabase(app, config, jobQueue);
59 }
60
62}
63
64} // namespace ripple
Section & section(std::string const &name)
Returns the section with the given name.
A pool of threads to perform work.
Definition JobQueue.h:58
static std::unique_ptr< RelationalDatabase > init(Application &app, Config const &config, JobQueue &jobQueue)
init Creates and returns an appropriate RelationalDatabase instance based on configuration.
Holds a collection of configuration values.
Definition BasicConfig.h:45
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
std::unique_ptr< RelationalDatabase > getSQLiteDatabase(Application &app, Config const &config, JobQueue &jobQueue)
T get(Section const &section, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.