more on usage
This commit is contained in:
parent
af90b9c9c6
commit
87ba808c2a
@ -29,6 +29,29 @@ Basic functionality
|
||||
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
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user