You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
asyncdefmain() -> 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
+
asyncdefmain() -> 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
+
133
192
## Extra Types
134
193
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.
0 commit comments