Table request with dynamic parameters

I started learning how to use Diesel to query a database. I have a table that looks something like the structure below (this is just a toy project that will help me understand how diesel works).

#[derive(Queryable, Insertable)]
#[table_name="posts"]
struct Post {
    id: String,
    title: String,
    body: String,
    published: bool
}

Executing queries that are fully defined at compile time is quite simple, for example

posts.select(id, title).order(title.desc());

I don’t understand how to build a query depending on some runtime parameters without returning to SQL. For example, JSONAPI allows you to dynamically select fields and sort them based on query parameters. How can I do this in Diesel?

+4
source share

Source: https://habr.com/ru/post/1671254/


All Articles