Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/wheels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
CIBW_BUILD_FRONTEND: build # pip backend doesn't seem including our dynamic libraries
CIBW_BUILD: ${{ matrix.config.cibw }}
CIBW_ENVIRONMENT: MACOSX_DEPLOYMENT_TARGET=13.0 SYSTEM_VERSION_COMPAT=0 # Shitty arm macOS
CIBW_BEFORE_BUILD_LINUX: yum install wget -y && git fetch --tags && wget -c https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-linux.zip && unzip ninja-linux.zip -d /usr/local/bin && chmod +x /usr/local/bin/ninja
CIBW_BEFORE_BUILD_LINUX: pip install ninja && git fetch --tags
CIBW_BEFORE_BUILD_WINDOWS: choco install ninja git && cd libmdbx && git fetch --tags
CIBW_BEFORE_BUILD_MACOS: brew install ninja git && cd libmdbx && git fetch --tags
CIBW_TEST_REQUIRES: pytest
Expand Down Expand Up @@ -136,7 +136,7 @@ jobs:
CIBW_BUILD_FRONTEND: build # pip backend doesn't seem including our dynamic libraries
CIBW_BUILD: ${{ matrix.config.cibw }}
CIBW_ENVIRONMENT: MACOSX_DEPLOYMENT_TARGET=13.0 SYSTEM_VERSION_COMPAT=0 # Shitty arm macOS
CIBW_BEFORE_BUILD_LINUX: cd libmdbx && git fetch --tags && wget -c https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-linux.zip && unzip ninja-linux.zip -d /usr/local/bin && chmod +x /usr/local/bin/ninja
CIBW_BEFORE_BUILD_LINUX: pip install ninja && git fetch --tags
CIBW_BEFORE_BUILD_WINDOWS: choco install ninja cmake git && cd libmdbx && git fetch --tags
CIBW_BEFORE_BUILD_MACOS: brew install ninja git && cd libmdbx && git fetch --tags
CIBW_TEST_REQUIRES: pytest
Expand All @@ -158,7 +158,7 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: "recursive"

- name: Build SDist
run: |
sudo apt update && sudo apt install ninja-build git build-essential -y
Expand Down Expand Up @@ -190,4 +190,4 @@ jobs:
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
password: ${{ secrets.PYPI_TOKEN }}
27 changes: 27 additions & 0 deletions mdbx/mdbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2624,6 +2624,25 @@ def delete(self, txn: TXN, key: bytes, value: bytes = None):
if ret != MDBXError.MDBX_SUCCESS.value:
raise make_exception(ret)

def get_sequence(self, txn: TXN, increment: int = 0) -> int:
"""
Wrapper around mdbx_dbi_sequence.

:param txn: Transaction handle
:param dbi: Database handle
:param increment: Value to increase the sequence by (0 for read-only transactions)
:return: Previous sequence value
:raises MDBXErrorExc: on failure
"""
result = ctypes.c_uint64(0)
ret = _lib.mdbx_dbi_sequence(txn._txn, self._dbi, ctypes.byref(result), ctypes.c_uint64(increment))
if ret == MDBXError.MDBX_SUCCESS.value:
return result.value
elif ret == MDBXError.MDBX_RESULT_TRUE.value:
raise OverflowError("Sequence increment resulted in overflow")
else:
raise make_exception(ret)


class Cursor():
"""
Expand Down Expand Up @@ -3346,3 +3365,11 @@ def make_exception(errno: int):
_lib.mdbx_txn_straggler.argtypes = [
ctypes.POINTER(MDBXTXN), ctypes.POINTER(ctypes.c_int)]
_lib.mdbx_txn_straggler.restype = ctypes.c_int

_lib.mdbx_dbi_sequence.argtypes = [
ctypes.POINTER(MDBXTXN),
MDBXDBI,
ctypes.POINTER(ctypes.c_uint64),
ctypes.c_uint64,
]
_lib.mdbx_dbi_sequence.restype = ctypes.c_int
28 changes: 27 additions & 1 deletion tests/test_iters.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,33 @@ def test_iters_dup(self):
vals = [(k, v) for k, v in cur.iter_dupsort()]
expected = [ (x, dup) for x, dups in expected for dup in dups]
self.assertEqual(vals, expected)


def test_sequence(self) -> None:
with Env(self._folder_path.absolute().as_posix()) as env:
with env.ro_transaction() as txn:
with txn.open_map() as dbi:
self.assertEqual(dbi.get_sequence(txn, 0), 0)

with env.rw_transaction() as txn:
with txn.open_map() as dbi:
self.assertEqual(dbi.get_sequence(txn, 1), 0)
self.assertEqual(dbi.get_sequence(txn, 1), 1)
txn.abort()

with env.ro_transaction() as txn:
with txn.open_map() as dbi:
self.assertEqual(dbi.get_sequence(txn, 0), 0)

with env.rw_transaction() as txn:
with txn.open_map() as dbi:
self.assertEqual(dbi.get_sequence(txn, 1), 0)
self.assertEqual(dbi.get_sequence(txn, 1), 1)
txn.commit()

with env.ro_transaction() as txn:
with txn.open_map() as dbi:
self.assertEqual(dbi.get_sequence(txn, 0), 2)

def tearDown(self):
del self._folder
shutil.rmtree(self._folder_path, ignore_errors=True)
Expand Down
Loading