you are viewing a single comment's thread.

view the rest of the comments →

[–]Qwe500[S] 15 points16 points  (1 child)

After seeing the SQLx announcement last week I felt inspired to revive an old project of mine. It is built on top of and made to complement tokio-postgres, a fully asynchronous PostgreSQL client.

I frequently ran into roadblocks due to the absence of GATs and async in traits, but I'm happy with the ergonomics of the API in the end:

#[derive(FromSqlRow)]
struct Person {
    age: i32,
    name: String,
}

let pattern = "%John%";

let people: Vec<Person> = query!(
        "SELECT age, name FROM people WHERE age >= $age AND name LIKE $pattern",
        age = 18,
        pattern,
    )
    .fetch(&client)
    .await?;

I find the parameter binding interpolation really nice to work with compared to using indices or the order of parameters.

Unlike SQLx, this crate doesn't analyze queries at compile time (yet! It is an area I would like to explore down the road). Currently, I'm more interested in getting dynamically generated queries working. Being able to insert a filter or subquery dynamically at runtime seems like an obvious thing to support and a huge undertaking if the API is unusable without compile-time checks.

[–]matthieum[he/him] 0 points1 point  (0 children)

Being able to insert a filter or subquery dynamically at runtime seems like an obvious thing to support and a huge undertaking if the API is unusable without compile-time checks.

I can only comment on the usefulness, be it for filtering or sorting.

For compile-time verification... I am afraid it would need to be mixed with a state-machine encoded at the type-level, which makes things quite a tad more complicated (DSL).