pub fn sql(query: &str) -> Vec<Map<String, Value>>Expand description
Rows returned by query, run on the test database (Rails’ ActiveRecord::Base.connection.select_all).
It opens miniflare’s SQLite file of the test database in TEST_STATE
directly (WAL mode: the running server sees the writes at once), in a
few milliseconds, so a check can be polled. Several statements may be
separated by ;; the rows of the last one are returned. Values are SQL
literals: build them with quote. When the state holds no single D1
file (several databases), it runs the app’s wrangler (d1 execute DB --local) instead, about a second per call.
§Panics
When wrangler fails (the message has its output), e.g. on a SQL error.
§Examples
use ocre::testing::{quote, sql};
let rows = sql(&format!("SELECT id FROM posts WHERE title = {}", quote("Hello")));
assert_eq!(rows.len(), 1);