rippled
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 <ripple/app/main/Application.h>
21 #include <ripple/app/rdb/RelationalDatabase.h>
22 #include <ripple/core/ConfigSections.h>
23 #include <ripple/nodestore/DatabaseShard.h>
24 
25 namespace ripple {
26 
28 getSQLiteDatabase(Application& app, Config const& config, JobQueue& jobQueue);
29 
31 getPostgresDatabase(Application& app, Config const& config, JobQueue& jobQueue);
32 
35  Application& app,
36  Config const& config,
37  JobQueue& jobQueue)
38 {
39  bool use_sqlite = false;
40  bool use_postgres = false;
41 
42  if (config.reporting())
43  {
44  use_postgres = true;
45  }
46  else
47  {
48  const Section& rdb_section{config.section(SECTION_RELATIONAL_DB)};
49  if (!rdb_section.empty())
50  {
51  if (boost::iequals(get(rdb_section, "backend"), "sqlite"))
52  {
53  use_sqlite = true;
54  }
55  else
56  {
57  Throw<std::runtime_error>(
58  "Invalid rdb_section backend value: " +
59  get(rdb_section, "backend"));
60  }
61  }
62  else
63  {
64  use_sqlite = true;
65  }
66  }
67 
68  if (use_sqlite)
69  {
70  return getSQLiteDatabase(app, config, jobQueue);
71  }
72  else if (use_postgres)
73  {
74  return getPostgresDatabase(app, config, jobQueue);
75  }
76 
78 }
79 
80 } // namespace ripple
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:42
ripple::RelationalDatabase::init
static std::unique_ptr< RelationalDatabase > init(Application &app, Config const &config, JobQueue &jobQueue)
init Creates and returns an appropriate RelationalDatabase instance based on configuration.
Definition: RelationalDatabase.cpp:34
ripple::Application
Definition: Application.h:115
ripple::Config::reporting
bool reporting() const
Definition: Config.h:337
ripple::Config
Definition: Config.h:89
ripple::getPostgresDatabase
std::unique_ptr< RelationalDatabase > getPostgresDatabase(Application &app, Config const &config, JobQueue &jobQueue)
Definition: PostgresDatabase.cpp:1052
ripple::JobQueue
A pool of threads to perform work.
Definition: JobQueue.h:55
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
std::unique_ptr
STL class.
ripple::get
T & get(EitherAmount &amt)
Definition: AmountSpec.h:118
ripple::getSQLiteDatabase
std::unique_ptr< RelationalDatabase > getSQLiteDatabase(Application &app, Config const &config, JobQueue &jobQueue)
Definition: SQLiteDatabase.cpp:1736
ripple::BasicConfig::section
Section & section(std::string const &name)
Returns the section with the given name.
Definition: BasicConfig.cpp:127