As far as I have been able to determine, Diesel does not have any capability to perform queries where the 'shape' of the returned rows is not known at compile time. This is one of its strengths (at least for some use cases) because used properly, it will validate interaction with the database at compile time.
However this makes it difficult to use for dynamically generated SQL.
If your queries always generate the same number and types of columns then you can write something like this:
// Define a type to represent the rows returned by your query
#[derive(QueryableByName)]
struct StringColumn {
#[sql_type = "Text"]
username: String
}
// Then you can execute your query, telling Rust that you expect
// to get the rows back as the above type
let users:Vec<StringColumn> = diesel::sql_query("SELECT username FROM users").load(&conn)?;
If you are purely using dynamically generated SQL, you might be better off using the mysql crate directly.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…