|
| 1 | +from objectbox.c import * |
| 2 | +from objectbox.model import Model |
| 3 | + |
| 4 | + |
| 5 | +class StoreOptions: |
| 6 | + """ A RAII wrapper to the C API for setting the store options. """ |
| 7 | + |
| 8 | + _c_handle: Optional[int] |
| 9 | + |
| 10 | + def __init__(self): |
| 11 | + self._c_handle = obx_opt() |
| 12 | + |
| 13 | + def _free(self): |
| 14 | + if self._c_handle is not None: |
| 15 | + obx_opt_free(self._c_handle) |
| 16 | + self._c_handle = None |
| 17 | + |
| 18 | + def directory(self, path: str): |
| 19 | + obx_opt_directory(self._c_handle, c_str(path)) |
| 20 | + return self |
| 21 | + |
| 22 | + def max_db_size_in_kb(self, size_in_kb: int): |
| 23 | + obx_opt_max_db_size_in_kb(self._c_handle, size_in_kb) |
| 24 | + return self |
| 25 | + |
| 26 | + def max_data_size_in_kb(self, size_in_kb: int): |
| 27 | + obx_opt_max_data_size_in_kb(self._c_handle, size_in_kb) |
| 28 | + return self |
| 29 | + |
| 30 | + def file_mode(self, file_mode: int): |
| 31 | + obx_opt_file_mode(self._c_handle, file_mode) |
| 32 | + return self |
| 33 | + |
| 34 | + def max_readers(self, max_readers: int): |
| 35 | + obx_opt_max_readers(self._c_handle, max_readers) |
| 36 | + return self |
| 37 | + |
| 38 | + def no_reader_thread_locals(self, flag: bool): |
| 39 | + obx_opt_max_readers(self._c_handle, flag) |
| 40 | + return self |
| 41 | + |
| 42 | + def model(self, model: Model): |
| 43 | + obx_opt_model(self._c_handle, model._c_model) |
| 44 | + return self |
| 45 | + |
| 46 | + def model_bytes(self, bytes_: bytes): |
| 47 | + obx_opt_model_bytes(self._c_handle, len(bytes_)) |
| 48 | + return self |
| 49 | + |
| 50 | + def model_bytes_direct(self, bytes_: bytes): |
| 51 | + obx_opt_model_bytes_direct(self._c_handle, len(bytes_)) |
| 52 | + return self |
| 53 | + |
| 54 | + def validate_on_open_pages(self, page_limit: int, flags: int): |
| 55 | + raise NotImplementedError # TODO |
| 56 | + |
| 57 | + def validate_on_open_kv(self, flags: OBXValidateOnOpenKvFlags): |
| 58 | + raise NotImplementedError # TODO |
| 59 | + |
| 60 | + def put_padding_mode(self, mode: OBXPutPaddingMode): |
| 61 | + obx_opt_put_padding_mode(self._c_handle, mode) |
| 62 | + return self |
| 63 | + |
| 64 | + def read_schema(self, value: bool): |
| 65 | + obx_opt_read_schema(self._c_handle, value) |
| 66 | + return self |
| 67 | + |
| 68 | + def use_previous_commit(self, value: bool): |
| 69 | + obx_opt_use_previous_commit(self._c_handle, value) |
| 70 | + return self |
| 71 | + |
| 72 | + def read_only(self, value: bool): |
| 73 | + obx_opt_read_only(self._c_handle, value) |
| 74 | + return self |
| 75 | + |
| 76 | + def debug_flags(self, flags: OBXDebugFlags): |
| 77 | + obx_opt_debug_flags(self._c_handle, flags) |
| 78 | + return self |
| 79 | + |
| 80 | + def add_debug_flags(self, flags: OBXDebugFlags): |
| 81 | + obx_opt_add_debug_flags(self._c_handle, flags) |
| 82 | + return self |
| 83 | + |
| 84 | + def async_max_queue_length(self, value: int): |
| 85 | + obx_opt_async_max_queue_length(self._c_handle, value) |
| 86 | + return self |
| 87 | + |
| 88 | + def async_throttle_at_queue_length(self, value: int): |
| 89 | + obx_opt_async_throttle_at_queue_length(self._c_handle, value) |
| 90 | + return self |
| 91 | + |
| 92 | + def async_throttle_micros(self, value: int): |
| 93 | + obx_opt_async_throttle_micros(self._c_handle, value) |
| 94 | + return self |
| 95 | + |
| 96 | + def async_max_in_tx_duration(self, micros: int): |
| 97 | + obx_opt_async_max_in_tx_duration(self._c_handle, micros) |
| 98 | + return self |
| 99 | + |
| 100 | + def async_max_in_tx_operations(self, value: int): |
| 101 | + obx_opt_async_max_in_tx_operations(self._c_handle, value) |
| 102 | + return self |
| 103 | + |
| 104 | + def async_pre_txn_delay(self, delay_micros: int): |
| 105 | + obx_opt_async_pre_txn_delay(self._c_handle, delay_micros) |
| 106 | + return self |
| 107 | + |
| 108 | + def async_pre_txn_delay4(self, delay_micros: int, delay2_micros: int, min_queue_length_for_delay2: int): |
| 109 | + obx_opt_async_pre_txn_delay4(self._c_handle, delay_micros, delay2_micros, min_queue_length_for_delay2) |
| 110 | + return self |
| 111 | + |
| 112 | + def async_post_txn_delay(self, delay_micros: int): |
| 113 | + obx_opt_async_post_txn_delay(self._c_handle, delay_micros) |
| 114 | + return self |
| 115 | + |
| 116 | + def async_post_txn_delay5(self, delay_micros: int, delay2_micros: int, min_queue_length_for_delay2: int, |
| 117 | + subtract_processing_time: bool): |
| 118 | + obx_opt_async_post_txn_delay5(self._c_handle, delay_micros, delay2_micros, min_queue_length_for_delay2, |
| 119 | + subtract_processing_time) |
| 120 | + return self |
| 121 | + |
| 122 | + def async_minor_refill_threshold(self, queue_length: int): |
| 123 | + obx_opt_async_minor_refill_threshold(self._c_handle, queue_length) |
| 124 | + return self |
| 125 | + |
| 126 | + def async_minor_refill_max_count(self, value: int): |
| 127 | + obx_opt_async_minor_refill_max_count(self._c_handle, value) |
| 128 | + return self |
| 129 | + |
| 130 | + def async_max_tx_pool_size(self, value: int): |
| 131 | + obx_opt_async_max_tx_pool_size(self._c_handle, value) |
| 132 | + return self |
| 133 | + |
| 134 | + def async_object_bytes_max_cache_size(self, value: int): |
| 135 | + obx_opt_async_object_bytes_max_cache_size(self._c_handle, value) |
| 136 | + return self |
| 137 | + |
| 138 | + def async_object_bytes_max_size_to_cache(self, value: int): |
| 139 | + obx_opt_async_object_bytes_max_size_to_cache(self._c_handle, value) |
| 140 | + return self |
| 141 | + |
| 142 | + # TODO def log_callback(self): |
| 143 | + |
| 144 | + def backup_restore(self, backup_file: str, flags: OBXBackupRestoreFlags): |
| 145 | + raise NotImplementedError # TODO |
| 146 | + |
| 147 | + def get_directory(self) -> str: |
| 148 | + dir_bytes = obx_opt_get_directory(self._c_handle) |
| 149 | + return dir_bytes.decode('utf-8') |
| 150 | + |
| 151 | + def get_max_db_size_in_kb(self) -> int: |
| 152 | + return obx_opt_get_max_db_size_in_kb(self._c_handle) |
| 153 | + |
| 154 | + def get_max_data_size_in_kb(self) -> int: |
| 155 | + return obx_opt_get_max_data_size_in_kb(self._c_handle) |
| 156 | + |
| 157 | + def get_debug_flags(self) -> OBXDebugFlags: |
| 158 | + return obx_opt_get_debug_flags(self._c_handle) |
0 commit comments