1#include "duckdb/main/database.hpp"
2
3#include "duckdb/catalog/catalog.hpp"
4#include "duckdb/common/file_system.hpp"
5#include "duckdb/main/connection_manager.hpp"
6#include "duckdb/storage/storage_manager.hpp"
7#include "duckdb/transaction/transaction_manager.hpp"
8
9using namespace duckdb;
10using namespace std;
11
12DBConfig::~DBConfig() {
13}
14
15DuckDB::DuckDB(const char *path, DBConfig *config) {
16 if (config) {
17 // user-supplied configuration
18 Configure(*config);
19 } else {
20 // default configuration
21 DBConfig config;
22 Configure(config);
23 }
24 if (temporary_directory.empty() && path) {
25 // no directory specified: use default temp path
26 temporary_directory = string(path) + ".tmp";
27
28 // special treatment for in-memory mode
29 if (strcmp(path, ":memory:") == 0) {
30 temporary_directory = ".tmp";
31 }
32 }
33 if (config && !config->use_temporary_directory) {
34 // temporary directories explicitly disabled
35 temporary_directory = string();
36 }
37
38 storage = make_unique<StorageManager>(*this, path ? string(path) : string(), access_mode == AccessMode::READ_ONLY);
39 catalog = make_unique<Catalog>(*storage);
40 transaction_manager = make_unique<TransactionManager>(*storage);
41 connection_manager = make_unique<ConnectionManager>();
42 // initialize the database
43 storage->Initialize();
44}
45
46DuckDB::DuckDB(const string &path, DBConfig *config) : DuckDB(path.c_str(), config) {
47}
48
49DuckDB::~DuckDB() {
50}
51
52void DuckDB::Configure(DBConfig &config) {
53 if (config.access_mode != AccessMode::UNDEFINED) {
54 access_mode = config.access_mode;
55 } else {
56 access_mode = AccessMode::READ_WRITE;
57 }
58 if (config.file_system) {
59 file_system = move(config.file_system);
60 } else {
61 file_system = make_unique<FileSystem>();
62 }
63 checkpoint_only = config.checkpoint_only;
64 checkpoint_wal_size = config.checkpoint_wal_size;
65 use_direct_io = config.use_direct_io;
66 maximum_memory = config.maximum_memory;
67 temporary_directory = config.temporary_directory;
68 collation = config.collation;
69}
70