33#include < pybind11/stl/filesystem.h>
44#include < pybind11/typing.h>
55
6- // #include <filesystem>
7- // #include <optional>
8- // #include <string>
6+ #include < filesystem>
7+ #include < optional>
8+ #include < string>
99#include < string_view>
10- // #include <variant>
11- //
12- // #include <rocksdb/cache.h>
13- // #include <rocksdb/db.h>
14- // //#include <rocksdb/decompress_allocator.h>
15- // #include <rocksdb/env.h>
16- // #include <rocksdb/filter_policy.h>
17- // #include <rocksdb/options.h>
18- // #include <rocksdb/write_batch.h>
1910
2011#include < amulet/pybind11_extensions/compatibility.hpp>
2112#include < amulet/pybind11_extensions/iterator.hpp>
2213
23- // #include <amulet/rocksdb.hpp>
2414#include < amulet/rocksdb/compact_range_options.hpp>
2515#include < amulet/rocksdb/db.hpp>
2616#include < amulet/rocksdb/options.hpp>
@@ -70,7 +60,6 @@ namespace detail {
7060
7161namespace {
7262
73-
7463// class RocksDBKeysIterator {
7564// private:
7665// std::unique_ptr<Amulet::RocksDBIterator> iterator_ptr;
@@ -370,19 +359,17 @@ void init_module(py::module m)
370359 " :raises: RocksDBException if an error occured." ));
371360 RocksDB.def (
372361 py::init ([](
373- std::filesystem::path path,
374- Amulet::RocksDB::Options& options,
375- Amulet::RocksDB::ReadOptions& read_options,
376- Amulet::RocksDB::WriteOptions& write_options,
377- Amulet::RocksDB::CompactRangeOptions& compact_range_options
378- ) {
362+ std::filesystem::path path,
363+ Amulet::RocksDB::Options& options,
364+ Amulet::RocksDB::ReadOptions& read_options,
365+ Amulet::RocksDB::WriteOptions& write_options,
366+ Amulet::RocksDB::CompactRangeOptions& compact_range_options) {
379367 return std::make_unique<Amulet::RocksDB::RocksDB>(
380368 std::move (path),
381369 std::move (options),
382370 std::move (read_options),
383371 std::move (write_options),
384- std::move (compact_range_options)
385- );
372+ std::move (compact_range_options));
386373 }),
387374 py::arg (" path" ),
388375 py::arg (" options" ),
@@ -412,9 +399,23 @@ void init_module(py::module m)
412399
413400 RocksDB.def (
414401 " compact_range" ,
415- &Amulet::RocksDB::RocksDB::compact_range,
416- py::doc (" Remove deleted entries from the database to reduce its size." ),
417- py::call_guard<py::gil_scoped_release>());
402+ [](Amulet::RocksDB::RocksDB& self, std::optional<py::bytes> begin, std::optional<py::bytes> end) {
403+ std::optional<std::string_view> begin_view;
404+ std::optional<std::string_view> end_view;
405+ if (begin) {
406+ begin_view = begin;
407+ }
408+ if (end) {
409+ end_view = end;
410+ }
411+ {
412+ py::gil_scoped_release gil;
413+ self.compact_range (begin_view, end_view);
414+ }
415+ },
416+ py::arg (" begin" ),
417+ py::arg (" end" ),
418+ py::doc (" Remove deleted entries from the database to reduce its size." ));
418419
419420 RocksDB.def (
420421 " compact" ,
@@ -440,7 +441,8 @@ void init_module(py::module m)
440441 " __setitem__" ,
441442 put,
442443 py::arg (" key" ),
443- py::arg (" value" ));
444+ py::arg (" value" ),
445+ py::doc (" db[b\" key\" ] = b\" value\" " ));
444446
445447 // RocksDB.def(
446448 // "put_batch",
@@ -491,7 +493,11 @@ void init_module(py::module m)
491493 " :return: The data stored behind the given key.\n "
492494 " :raises: KeyError if the requested key is not present.\n "
493495 " :raises: RocksDBException on other error." ));
494- RocksDB.def (" __getitem__" , get, py::arg (" key" ));
496+ RocksDB.def (
497+ " __getitem__" ,
498+ get,
499+ py::arg (" key" ),
500+ py::doc (" db[b\" key\" ]" ));
495501
496502 auto del = [](Amulet::RocksDB::RocksDB& self, py::bytes key) {
497503 std::string_view key_view = key;
@@ -507,13 +513,12 @@ void init_module(py::module m)
507513 py::doc (
508514 " Delete a key from the database.\n "
509515 " \n "
510- " :param key: The key to delete from the database." ),
511- py::call_guard<py::gil_scoped_release>());
516+ " :param key: The key to delete from the database." ));
512517 RocksDB.def (
513518 " __delitem__" ,
514519 del,
515520 py::arg (" key" ),
516- py::call_guard<py::gil_scoped_release>( ));
521+ py::doc ( " del db[b \" key \" ] " ));
517522
518523 // RocksDB.def(
519524 // "create_iterator",
0 commit comments