Skip to content

Commit 05292da

Browse files
committed
Added some information to the README
1 parent af0ef31 commit 05292da

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

README.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ async def main() -> None:
117117
)
118118

119119
await transaction.begin()
120-
res: list[dict[str, Any]] = await transaction.execute(
120+
await transaction.execute(
121121
"INSERT INTO users VALUES ($1)",
122122
["Some data"],
123123
)
@@ -130,6 +130,65 @@ async def main() -> None:
130130
# rust does it instead.
131131
```
132132

133+
### Transactions can be roll backed
134+
You must understand that rollback can be executed only once per transaction.
135+
After it's execution transaction state changes to `done`.
136+
If you want to use `ROLLBACK TO SAVEPOINT`, see below.
137+
```python
138+
from typing import Any
139+
import asyncio
140+
141+
from rust_psql_driver import PSQLPool, IsolationLevel
142+
143+
144+
db_pool = PSQLPool()
145+
146+
async def main() -> None:
147+
await db_pool.startup()
148+
149+
transaction = await db_pool.transaction(
150+
isolation_level=IsolationLevel.Serializable,
151+
)
152+
153+
await transaction.begin()
154+
await transaction.execute(
155+
"INSERT INTO users VALUES ($1)",
156+
["Some data"],
157+
)
158+
await transaction.rollback()
159+
```
160+
161+
### Transaction ROLLBACK TO SAVEPOINT
162+
You can rollback your transaction to the specified savepoint, but before it you must create it.
163+
164+
```python
165+
from typing import Any
166+
import asyncio
167+
168+
from rust_psql_driver import PSQLPool, IsolationLevel
169+
170+
171+
db_pool = PSQLPool()
172+
173+
async def main() -> None:
174+
await db_pool.startup()
175+
176+
transaction = await db_pool.transaction(
177+
isolation_level=IsolationLevel.Serializable,
178+
)
179+
180+
await transaction.begin()
181+
# Create new savepoint
182+
await transaction.savepoint("test_savepoint")
183+
184+
await transaction.execute(
185+
"INSERT INTO users VALUES ($1)",
186+
["Some data"],
187+
)
188+
# Rollback to specified SAVEPOINT.
189+
await transaction.rollback_to("test_savepoint")
190+
```
191+
133192
## Extra Types
134193
Sometimes it's impossible to identify which type user tries to pass as a argument. But Rust is a strongly typed programming language so we have to help.
135194

0 commit comments

Comments
 (0)