more on usage
This commit is contained in:
parent
af90b9c9c6
commit
87ba808c2a
@ -24,11 +24,34 @@ Basic functionality
|
|||||||
|
|
||||||
import pathlib
|
import pathlib
|
||||||
from ptvp35 import DbFactory, KVJson
|
from ptvp35 import DbFactory, KVJson
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
async with DbFactory(pathlib.Path('example.db', kvfactory=KVJson())) as connection:
|
async with DbFactory(pathlib.Path('example.db', kvfactory=KVJson())) as connection:
|
||||||
await _main(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
|
.. autoclass:: ptvp35.DbConnection
|
||||||
|
|
||||||
.. automethod:: get
|
.. automethod:: get
|
||||||
|
@ -524,7 +524,7 @@ note: unstable signature."""
|
|||||||
def submit_transaction(self, delta: dict, future: asyncio.Future | None, /) -> None:
|
def submit_transaction(self, delta: dict, future: asyncio.Future | None, /) -> None:
|
||||||
"""not implemented.
|
"""not implemented.
|
||||||
low-level API.
|
low-level API.
|
||||||
note: unstable signature."""
|
note: unstable (undefined) signature."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
async def commit(self, /) -> None:
|
async def commit(self, /) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user