SELECT * FROM table WHERE date = ? ORDER BY id
#[derive(Queryable, AsChangeset, Serialize, Deserialize, Debug, Clone)]
#[table_name = "table"]
pub struct Data {
pub id: i32,
pub title: String,
pub date: String,
pub link: String,
pub writer: String,
}
use crate::db::models::Model;
use crate::db::schema::table;
use crate::db::schema::table::dsl::*;
// SELECT * FROM table WHERE date = ? ORDER BY id
pub fn get_notices(conn: &MysqlConnection, _date: String) -> QueryResult<Vec<Model>> {
table
.filter(date.eq(_date))
.order(table::id.desc()) // if ambiguous
.load::<Model>(&*conn)
}
SELECT * FROM table limit 5
#[derive(Queryable, AsChangeset, Serialize, Deserialize, Debug, Clone)]
#[table_name = "table"]
pub struct Data {
pub id: i32,
pub title: String,
pub date: String,
pub link: String,
pub writer: String,
}
use crate::db::models::Model;
use crate::db::schema::table;
use crate::db::schema::table::dsl::*;
// SELECT * FROM table LIMIT 5
pub fn get_notices(conn: &MysqlConnection) -> QueryResult<Vec<Model>> {
table
.limit(5)
.load::<Model>(&*conn)
}