Function ::exo::db::exec_sql

Overview
async fn exec_sql(value) -> Result

Execute a sql-query against the database. Only Select statements are supported.

Use the SqlQuery for dynamic values:

Select all user records with the ident of 'admin'.

let ident = exo::Ident::new("admin");
let query = exo::SqlQuery::new().model("user").check("ident", "==", ident);
let records = exo::db::exec_sql(query).await?;
assert!(records[0].ident == exo::Ident::new("admin"));

Select limited records example:

Select a full record with the first * operator. The second * operator selects over all records types. Limit to 5 records with the limit operator.

let records = exo::db::exec_sql("SELECT * FROM * LIMIT 5;").await?;
assert_eq!(records.len(), 5);
assert!(records[0] is exo::Record);

Select record typ with offset example:

Select only right records. Limit to 5 records with the limit operator.

let records = exo::db::exec_sql("SELECT * FROM user LIMIT 5;").await?;
assert!(records[0] is exo::Record);

Select columns from user example:

let entries = exo::db::exec_sql("SELECT uuid, name FROM user;").await?;
assert!(entries[0]["name"] is exo::Language);
assert!(entries[0]["uuid"] is exo::Reference);

Count amount of records example:

let entries = exo::db::exec_sql("SELECT count(uuid) FROM role;").await?;
assert_eq!(entries[0]["count"], 2);