MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / begin_transaction

Function begin_transaction

aiscript-vm/src/stdlib/db/sqlite.rs:268–289  ·  view source on GitHub ↗
(
        state: &mut State<'gc>,
        _args: Vec<Value<'gc>>,
    )

Source from the content-addressed store, hash-verified

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() {

Callers

nothing calls this directly

Calls 7

RuntimeErrorClass · 0.85
InstanceClass · 0.85
get_contextMethod · 0.80
create_transaction_classFunction · 0.70
borrowMethod · 0.45
as_refMethod · 0.45
borrow_mutMethod · 0.45

Tested by

no test coverage detected