1 | //===----------------------------------------------------------------------===// |
2 | // DuckDB |
3 | // |
4 | // duckdb/main/database.hpp |
5 | // |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #pragma once |
10 | |
11 | #include "duckdb/common/common.hpp" |
12 | #include "duckdb/common/file_system.hpp" |
13 | #include "duckdb/main/extension.hpp" |
14 | |
15 | namespace duckdb { |
16 | class StorageManager; |
17 | class Catalog; |
18 | class TransactionManager; |
19 | class ConnectionManager; |
20 | class FileSystem; |
21 | |
22 | enum class AccessMode : uint8_t { UNDEFINED = 0, AUTOMATIC = 1, READ_ONLY = 2, READ_WRITE = 3 }; |
23 | |
24 | // this is optional and only used in tests at the moment |
25 | struct DBConfig { |
26 | friend class DuckDB; |
27 | friend class StorageManager; |
28 | |
29 | public: |
30 | ~DBConfig(); |
31 | |
32 | //! Access mode of the database (AUTOMATIC, READ_ONLY or READ_WRITE) |
33 | AccessMode access_mode = AccessMode::AUTOMATIC; |
34 | // Checkpoint when WAL reaches this size |
35 | idx_t checkpoint_wal_size = 1 << 20; |
36 | //! Whether or not to use Direct IO, bypassing operating system buffers |
37 | bool use_direct_io = false; |
38 | //! The FileSystem to use, can be overwritten to allow for injecting custom file systems for testing purposes (e.g. |
39 | //! RamFS or something similar) |
40 | unique_ptr<FileSystem> file_system; |
41 | //! The maximum memory used by the database system (in bytes). Default: Infinite |
42 | idx_t maximum_memory = (idx_t)-1; |
43 | //! Whether or not to create and use a temporary directory to store intermediates that do not fit in memory |
44 | bool use_temporary_directory = true; |
45 | //! Directory to store temporary structures that do not fit in memory |
46 | string temporary_directory; |
47 | //! The collation type of the database |
48 | string collation = string(); |
49 | |
50 | private: |
51 | // FIXME: don't set this as a user: used internally (only for now) |
52 | bool checkpoint_only = false; |
53 | }; |
54 | |
55 | //! The database object. This object holds the catalog and all the |
56 | //! database-specific meta information. |
57 | class Connection; |
58 | class DuckDB { |
59 | public: |
60 | DuckDB(const char *path = nullptr, DBConfig *config = nullptr); |
61 | DuckDB(const string &path, DBConfig *config = nullptr); |
62 | |
63 | ~DuckDB(); |
64 | |
65 | unique_ptr<FileSystem> file_system; |
66 | unique_ptr<StorageManager> storage; |
67 | unique_ptr<Catalog> catalog; |
68 | unique_ptr<TransactionManager> transaction_manager; |
69 | unique_ptr<ConnectionManager> connection_manager; |
70 | |
71 | AccessMode access_mode; |
72 | bool use_direct_io; |
73 | bool checkpoint_only; |
74 | idx_t checkpoint_wal_size; |
75 | idx_t maximum_memory; |
76 | string temporary_directory; |
77 | string collation; |
78 | |
79 | public: |
80 | template <class T> void LoadExtension() { |
81 | T extension; |
82 | extension.Load(*this); |
83 | } |
84 | |
85 | private: |
86 | void Configure(DBConfig &config); |
87 | }; |
88 | |
89 | } // namespace duckdb |
90 | |