Native function implementations
(state: &mut State<'gc>, args: Vec<Value<'gc>>)
| 329 | |
| 330 | // Native function implementations |
| 331 | fn 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 | |
| 357 | fn pg_query_as<'gc>(state: &mut State<'gc>, args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> { |
| 358 | if args.len() < 2 { |
nothing calls this directly
no test coverage detected