MCPcopy Create free account
hub / github.com/NyxCode/ormx / query_users

Function query_users

example-postgres/src/query2.rs:5–29  ·  view source on GitHub ↗
(
    db: &PgPool,
    filter: Option<&str>,
    limit: Option<usize>,
)

Source from the content-addressed store, hash-verified

3use crate::User;
4
5pub(crate) async fn query_users(
6 db: &PgPool,
7 filter: Option<&str>,
8 limit: Option<usize>,
9) -> anyhow::Result<Vec<User>> {
10 let result = ormx::conditional_query_as!(
11 User,
12 r#"SELECT
13 id AS user_id, first_name, last_name, email, disabled,
14 role AS "role: _", "group" AS "group: _", type as "ty: _", last_login"#
15 "FROM users"
16 Some(f) = filter => {
17 "WHERE first_name LIKE" ?(f)
18 "OR last_name LIKE" ?(f)
19 }
20 "ORDER BY first_name DESC"
21 Some(l) = limit => {
22 "LIMIT" ?(l as i64)
23 }
24 )
25 .fetch_all(db)
26 .await?;
27
28 Ok(result)
29}

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected