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

Function query

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

Source from the content-addressed store, hash-verified

289 }
290
291 fn query<'gc>(state: &mut State<'gc>, args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> {
292 if args.is_empty() {
293 return Err(VmError::RuntimeError(
294 "query() requires a SQL query string.".into(),
295 ));
296 }
297
298 let query = args[0].as_string()?;
299 let ctx = state.get_context();
300
301 let result = ACTIVE_TRANSACTION.with(|cell| {
302 if let Some(tx) = (*cell.borrow_mut()).as_mut() {
303 let rows = execute_query(
304 &mut **tx,
305 query.to_str().unwrap(),
306 args.into_iter().skip(1).collect(),
307 );
308 Some(rows)
309 } else {
310 None
311 }
312 });
313
314 match result {
315 Some(Ok(rows)) => {
316 let mut results = Vec::new();
317 for row in rows {
318 results.push(row_to_object(ctx, &row));
319 }
320 Ok(Value::array(&ctx, results))
321 }
322 Some(Err(e)) => Err(VmError::RuntimeError(format!("Database error: {e}"))),
323 None => Err(VmError::RuntimeError("No active transaction".into())),
324 }
325 }
326
327 fn query_as<'gc>(state: &mut State<'gc>, args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> {
328 if args.len() < 2 {

Callers 1

execute_queryFunction · 0.70

Calls 9

RuntimeErrorClass · 0.85
as_stringMethod · 0.80
get_contextMethod · 0.80
as_mutMethod · 0.80
to_strMethod · 0.80
pushMethod · 0.80
execute_queryFunction · 0.70
row_to_objectFunction · 0.70
borrow_mutMethod · 0.45

Tested by

no test coverage detected