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

Function pg_query

aiscript-vm/src/stdlib/db/pg.rs:331–355  ·  view source on GitHub ↗

Native function implementations

(state: &mut State<'gc>, args: Vec<Value<'gc>>)

Source from the content-addressed store, hash-verified

329
330// Native function implementations
331fn pg_query<'gc>(state: &mut State<'gc>, args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> {
332 if args.is_empty() {
333 return Err(VmError::RuntimeError(
334 "query() requires at least a SQL query string.".into(),
335 ));
336 }
337
338 let sql = args[0].as_string()?;
339 let ctx = state.get_context();
340 let conn = state.pg_connection.as_ref().unwrap();
341 // Execute query in runtime
342 let rows = execute_query(
343 conn,
344 sql.to_str().unwrap(),
345 args.into_iter().skip(1).collect(),
346 )?;
347
348 // Convert rows to array of objects
349 let mut results = Vec::new();
350 for row in rows {
351 results.push(row_to_object(ctx, &row));
352 }
353
354 Ok(Value::array(state, results))
355}
356
357fn pg_query_as<'gc>(state: &mut State<'gc>, args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> {
358 if args.len() < 2 {

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected