diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2019-04-08 15:55:14 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2019-04-08 15:55:14 +0200 |
commit | ad0e585abed7a189b6117e9187c9afff809d1414 (patch) | |
tree | d1e80624e0f87882e90c0fe87a99a817e7edc61d /src/models/room.rs | |
parent | 5ab5f490bc7199709fbc03d51bf6131e92269fdc (diff) | |
download | ramaskrik-social-ad0e585abed7a189b6117e9187c9afff809d1414.tar.gz ramaskrik-social-ad0e585abed7a189b6117e9187c9afff809d1414.tar.bz2 ramaskrik-social-ad0e585abed7a189b6117e9187c9afff809d1414.zip |
Move functions to query/modify db to connection object.
Makes tha API a bit nicer by asking the database rather than
passing the database on to each model. Reserve models for
method/functions that work on the model structs themselves.
Diffstat (limited to 'src/models/room.rs')
-rw-r--r-- | src/models/room.rs | 18 |
1 files changed, 1 insertions, 17 deletions
diff --git a/src/models/room.rs b/src/models/room.rs index 6360c88..d475901 100644 --- a/src/models/room.rs +++ b/src/models/room.rs @@ -16,11 +16,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -use crate::{ - db::Connection, - schema::rooms, -}; -use diesel::prelude::*; +use crate::schema::rooms; use serde_derive::{Deserialize, Serialize}; #[derive(Deserialize, Identifiable, PartialEq, Serialize, Queryable)] @@ -28,15 +24,3 @@ pub struct Room { pub id: i32, pub name: String, } - -pub fn get_all(db: &Connection) -> QueryResult<Vec<Room>> { - use crate::schema::rooms::dsl::*; - rooms.load::<Room>(&**db) -} - -pub fn by_name(rname: &str, db: &Connection) -> QueryResult<Room> { - use crate::schema::rooms::dsl::*; - rooms - .filter(name.eq(&rname)) - .get_result::<Room>(&**db) -} |