(
state: &mut State<'gc>,
_args: Vec<Value<'gc>>,
)
| 416 | } |
| 417 | |
| 418 | pub(super) fn begin_transaction<'gc>( |
| 419 | state: &mut State<'gc>, |
| 420 | _args: Vec<Value<'gc>>, |
| 421 | ) -> Result<Value<'gc>, VmError> { |
| 422 | // Check if there's already an active transaction |
| 423 | let has_active = ACTIVE_TRANSACTION.with(|tx| tx.borrow().is_some()); |
| 424 | if has_active { |
| 425 | return Err(VmError::RuntimeError("Transaction already active".into())); |
| 426 | } |
| 427 | |
| 428 | let ctx = state.get_context(); |
| 429 | let conn = state.pg_connection.as_ref().unwrap(); |
| 430 | let tx = Handle::current() |
| 431 | .block_on(async move { conn.begin().await }) |
| 432 | .map_err(|e| VmError::RuntimeError(format!("Failed to begin transaction: {}", e)))?; |
| 433 | |
| 434 | // Store transaction in thread local |
| 435 | ACTIVE_TRANSACTION.with(|cell| { |
| 436 | *cell.borrow_mut() = Some(tx); |
| 437 | }); |
| 438 | |
| 439 | // Create and return new instance |
| 440 | let instance = Instance::new(create_transaction_class(ctx)); |
| 441 | Ok(Value::Instance(Gc::new(&ctx, RefLock::new(instance)))) |
| 442 | } |
| 443 | |
| 444 | fn query<'gc>(state: &mut State<'gc>, args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> { |
| 445 | if args.is_empty() { |
nothing calls this directly
no test coverage detected