MCPcopy Create free account
hub / github.com/aiscriptdev/aiscript / pg_query_as

Function pg_query_as

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

Source from the content-addressed store, hash-verified

355}
356
357fn pg_query_as<'gc>(state: &mut State<'gc>, args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> {
358 if args.len() < 2 {
359 return Err(VmError::RuntimeError(
360 "query_as() requires a class and SQL query string.".into(),
361 ));
362 }
363
364 // First argument should be a class
365 let class = match args[0] {
366 Value::Class(class) => class,
367 _ => {
368 return Err(VmError::RuntimeError(
369 "First argument to query_as() must be a class.".into(),
370 ));
371 }
372 };
373
374 let sql = args[1].as_string()?;
375 let ctx = state.get_context();
376 let conn = state.pg_connection.as_ref().unwrap();
377
378 execute_typed_query(
379 ctx,
380 conn,
381 class,
382 sql.to_str().unwrap(),
383 args.into_iter().skip(2).collect(),
384 )
385}
386
387mod transaction {
388 use super::*;

Callers

nothing calls this directly

Calls 7

RuntimeErrorClass · 0.85
lenMethod · 0.80
as_stringMethod · 0.80
get_contextMethod · 0.80
to_strMethod · 0.80
execute_typed_queryFunction · 0.70
as_refMethod · 0.45

Tested by

no test coverage detected