@@ -34,17 +34,17 @@ def __init__(
3434 self ,
3535 database_path : str | Path | None = None ,
3636 * ,
37- buffer_pool_size : int = 0 ,
38- max_num_threads : int = 0 ,
39- compression : bool = True ,
37+ buffer_pool_size : int | None = None ,
38+ max_num_threads : int | None = None ,
39+ compression : bool | None = None ,
4040 lazy_init : bool = False ,
41- read_only : bool = False ,
41+ read_only : bool | None = None ,
4242 max_db_size : int | None = None ,
43- auto_checkpoint : bool = True ,
44- checkpoint_threshold : int = - 1 ,
45- throw_on_wal_replay_failure : bool = True ,
46- enable_checksums : bool = True ,
47- enable_multi_writes : bool = False ,
43+ auto_checkpoint : bool | None = None ,
44+ checkpoint_threshold : int | None = None ,
45+ throw_on_wal_replay_failure : bool | None = None ,
46+ enable_checksums : bool | None = None ,
47+ enable_multi_writes : bool | None = None ,
4848 backend : str = "auto" ,
4949 ):
5050 """
@@ -54,54 +54,60 @@ def __init__(
5454 The path to database files. If the path is not specified, or empty, or equal to `:memory:`, the database
5555 will be created in memory.
5656
57- buffer_pool_size : int
58- The maximum size of buffer pool in bytes. Defaults to ~80% of system memory.
57+ buffer_pool_size : int, optional
58+ The maximum size of buffer pool in bytes. If None (default), the
59+ engine default (~80% of system memory) is used.
5960
60- max_num_threads : int
61- The maximum number of threads to use for executing queries.
61+ max_num_threads : int, optional
62+ The maximum number of threads to use for executing queries. If None
63+ (default), the engine default is used.
6264
63- compression : bool
64- Enable database compression.
65+ compression : bool, optional
66+ Enable database compression. If None (default), the engine default
67+ is used.
6568
6669 lazy_init : bool
6770 If True, the database will not be initialized until the first query.
6871 This is useful when the database is not used in the main thread or
6972 when the main process is forked.
7073 Default to False.
7174
72- read_only : bool
75+ read_only : bool, optional
7376 If true, the database is opened read-only. No write transactions is
7477 allowed on the `Database` object. Multiple read-only `Database`
7578 objects can be created with the same database path. However, there
7679 cannot be multiple `Database` objects created with the same
7780 database path.
78- Default to False .
81+ If None (default), the engine default is used .
7982
8083 max_db_size : int, optional
8184 The maximum size of the database in bytes. Note that this is introduced
8285 temporarily for now to get around with the default 8TB mmap address
8386 space limit some environment. This will be removed once we implement
8487 a better solution later. If not specified, the backend's default is used.
8588
86- auto_checkpoint: bool
89+ auto_checkpoint: bool, optional
8790 If true, the database will automatically checkpoint when the size of
88- the WAL file exceeds the checkpoint threshold.
91+ the WAL file exceeds the checkpoint threshold. If None (default),
92+ the engine default is used.
8993
90- checkpoint_threshold: int
94+ checkpoint_threshold: int, optional
9195 The threshold of the WAL file size in bytes. When the size of the
9296 WAL file exceeds this threshold, the database will checkpoint if autoCheckpoint is true.
97+ If None (default), the engine default is used.
9398
94- throw_on_wal_replay_failure: bool
99+ throw_on_wal_replay_failure: bool, optional
95100 If true, any WAL replaying failure when loading the database will throw an error.
96101 Otherwise, Lbug will silently ignore the failure and replay up to where the error
97- occured.
102+ occured. If None (default), the engine default is used.
98103
99- enable_checksums: bool
104+ enable_checksums: bool, optional
100105 If true, the database will use checksums to detect corruption in the
101- WAL file.
106+ WAL file. If None (default), the engine default is used.
102107
103- enable_multi_writes: bool
104- If true, multiple concurrent write transactions are allowed. Default to False.
108+ enable_multi_writes: bool, optional
109+ If true, multiple concurrent write transactions are allowed. If None
110+ (default), the engine default is used.
105111
106112 backend : {"auto", "capi", "pybind"}
107113 Backend to use for database/query execution.
@@ -213,6 +219,35 @@ def __getstate__(self) -> dict[str, Any]:
213219 }
214220 return state
215221
222+ def _engine_kwargs (self ) -> dict [str , Any ]:
223+ """Return only the explicitly set engine settings.
224+
225+ Unset (None) settings are omitted so the engine default applies,
226+ instead of this binding pinning its own copy of the default.
227+ """
228+ kwargs : dict [str , Any ] = {}
229+ if self .buffer_pool_size is not None :
230+ kwargs ["buffer_pool_size" ] = self .buffer_pool_size
231+ if self .max_num_threads is not None :
232+ kwargs ["max_num_threads" ] = self .max_num_threads
233+ if self .compression is not None :
234+ kwargs ["compression" ] = self .compression
235+ if self .read_only is not None :
236+ kwargs ["read_only" ] = self .read_only
237+ if self .max_db_size is not None :
238+ kwargs ["max_db_size" ] = self .max_db_size
239+ if self .auto_checkpoint is not None :
240+ kwargs ["auto_checkpoint" ] = self .auto_checkpoint
241+ if self .checkpoint_threshold is not None :
242+ kwargs ["checkpoint_threshold" ] = self .checkpoint_threshold
243+ if self .throw_on_wal_replay_failure is not None :
244+ kwargs ["throw_on_wal_replay_failure" ] = self .throw_on_wal_replay_failure
245+ if self .enable_checksums is not None :
246+ kwargs ["enable_checksums" ] = self .enable_checksums
247+ if self .enable_multi_writes is not None :
248+ kwargs ["enable_multi_writes" ] = self .enable_multi_writes
249+ return kwargs
250+
216251 def init_database (self ) -> None :
217252 """Initialize the database."""
218253 self .check_for_database_close ()
@@ -221,17 +256,7 @@ def init_database(self) -> None:
221256 self ._database = self .init_pybind_database ()
222257 else :
223258 self ._database = get_capi_module ().Database (
224- self .database_path ,
225- self .buffer_pool_size ,
226- self .max_num_threads ,
227- self .compression ,
228- self .read_only ,
229- self .max_db_size ,
230- self .auto_checkpoint ,
231- self .checkpoint_threshold ,
232- self .throw_on_wal_replay_failure ,
233- self .enable_checksums ,
234- self .enable_multi_writes ,
259+ self .database_path , ** self ._engine_kwargs ()
235260 )
236261
237262 def init_pybind_database (self ) -> Any | None :
@@ -241,21 +266,7 @@ def init_pybind_database(self) -> Any | None:
241266 if pybind_module is None :
242267 return None
243268 if self ._pybind_database is None :
244- kwargs = {
245- "database_path" : self .database_path ,
246- "buffer_pool_size" : self .buffer_pool_size ,
247- "max_num_threads" : self .max_num_threads ,
248- "compression" : self .compression ,
249- "read_only" : self .read_only ,
250- "auto_checkpoint" : self .auto_checkpoint ,
251- "checkpoint_threshold" : self .checkpoint_threshold ,
252- "throw_on_wal_replay_failure" : self .throw_on_wal_replay_failure ,
253- "enable_checksums" : self .enable_checksums ,
254- "enable_multi_writes" : self .enable_multi_writes ,
255- }
256-
257- if self .max_db_size is not None :
258- kwargs ["max_db_size" ] = self .max_db_size
269+ kwargs = {"database_path" : self .database_path , ** self ._engine_kwargs ()}
259270
260271 self ._pybind_database = pybind_module .Database (** kwargs )
261272
0 commit comments