(
state: &mut State<'gc>,
_args: Vec<Value<'gc>>,
)
| 266 | } |
| 267 | |
| 268 | pub(super) fn begin_transaction<'gc>( |
| 269 | state: &mut State<'gc>, |
| 270 | _args: Vec<Value<'gc>>, |
| 271 | ) -> Result<Value<'gc>, VmError> { |
| 272 | let has_active = ACTIVE_TRANSACTION.with(|tx| tx.borrow().is_some()); |
| 273 | if has_active { |
| 274 | return Err(VmError::RuntimeError("Transaction already active".into())); |
| 275 | } |
| 276 | |
| 277 | let ctx = state.get_context(); |
| 278 | let conn = state.sqlite_connection.as_ref().unwrap(); |
| 279 | let tx = Handle::current() |
| 280 | .block_on(async move { conn.begin().await }) |
| 281 | .map_err(|e| VmError::RuntimeError(format!("Failed to begin transaction: {}", e)))?; |
| 282 | |
| 283 | ACTIVE_TRANSACTION.with(|cell| { |
| 284 | *cell.borrow_mut() = Some(tx); |
| 285 | }); |
| 286 | |
| 287 | let instance = Instance::new(create_transaction_class(ctx)); |
| 288 | Ok(Value::Instance(Gc::new(&ctx, RefLock::new(instance)))) |
| 289 | } |
| 290 | |
| 291 | fn query<'gc>(state: &mut State<'gc>, args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> { |
| 292 | if args.is_empty() { |
nothing calls this directly
no test coverage detected