From 87ba808c2af1be87f4fbb9d9b3b97ba748cb9fae Mon Sep 17 00:00:00 2001 From: timofey Date: Sun, 20 Nov 2022 22:54:57 +0000 Subject: [PATCH] more on usage --- docs/source/usage.rst | 25 ++++++++++++++++++++++++- ptvp35/__init__.py | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 242bfa4..8aeee1e 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -24,11 +24,34 @@ Basic functionality import pathlib from ptvp35 import DbFactory, KVJson - + async def main(): async with DbFactory(pathlib.Path('example.db', kvfactory=KVJson())) as connection: await _main(connection) +Different ways to get/set a value: + +.. code-block:: python3 + + from ptvp35 import DbConnection + + async def _main(connection: DbConnection): + value0 = connection.get('increment-0', 0) + await connection.set('increment-0', value0 + 1) + + value1 = connection.get('increment-1', 0) + connection.set_nowait('increment-1', value1 + 1) + await connection.commit() + + async with connection.transaction() as transaction: + value2 = transaction.get('increment-2', 0) + transaction.set_nowait('increment-2', value2 + 1) + + async with connection.transaction() as transaction: + value3 = transaction.get('increment-3', 0) + transaction.set_nowait('increment-3', value3 + 1) + await transaction.commit() + .. autoclass:: ptvp35.DbConnection .. automethod:: get diff --git a/ptvp35/__init__.py b/ptvp35/__init__.py index cdae838..b1c7702 100644 --- a/ptvp35/__init__.py +++ b/ptvp35/__init__.py @@ -524,7 +524,7 @@ note: unstable signature.""" def submit_transaction(self, delta: dict, future: asyncio.Future | None, /) -> None: """not implemented. low-level API. -note: unstable signature.""" +note: unstable (undefined) signature.""" raise NotImplementedError async def commit(self, /) -> None: