3 releases
0.1.2 | Jul 9, 2019 |
---|---|
0.1.1 | Jul 9, 2019 |
0.1.0 | Jul 9, 2019 |
#2280 in Database interfaces
3KB
About
This is just a quick macro to minimize the amount of maps you do with rust-mysql-simple (shoutout to an amazing library)
from this:
let result = connection.prep_exec(
"SELECT id, email, password FROM users WHERE email = :email",
mysql::params! {
"email" => username
}
).map(|result| {
result
.map(|x| x.unwrap())
.map(|row| {
let (id, email, password) = mysql::from_row(row);
User {
id,
email,
password
}
})
.collect()
});
to this:
let result = mysql_macros::mysql_query!(connection,
"SELECT id, email, password FROM users WHERE email = :email",
mysql::params!(
"email" => username
),
|(id, email, password)| {
User {
id,
email,
password
}
}
);