Skip to content

Instantly share code, notes, and snippets.

@rippinrobr
Last active June 6, 2018 22:32
Show Gist options
  • Save rippinrobr/5047511276e8e1ce5e2b58ebd119b833 to your computer and use it in GitHub Desktop.
Save rippinrobr/5047511276e8e1ce5e2b58ebd119b833 to your computer and use it in GitHub Desktop.
The code for the retrieving a particular conspiracy
/// The DbExecutor is contains the database connection which will be used by all of the
/// message handlers
pub struct DbExecutor(pub SqliteConnection);
impl Actor for DbExecutor {
type Context = SyncContext<Self>;
}
/// Sent to the DbExecutor to fetch the conspiracy with the given page_id
pub struct GetConspiracy {
pub page_id: String
}
/// Sets up the Result that is returned by the GetConspiracy handler
/// which is either the Conspiracy model or an error message
impl Message for GetConspiracy {
type Result = Result<Conspiracy, String>;
}
impl Handler<GetConspiracy> for DbExecutor {
type Result = Result<Conspiracy, String>;
/// The first two parameters are what we care about, the instance of self is where
/// I get the database connection from. The msg paramter contains the page_id that
/// was passed as part of the message and will be used to query the db for the requested
/// conspiracy. It makes a single call and returns the results of the results of the query.
fn handle(&mut self, msg: GetConspiracy, _: &mut Self::Context) -> Self::Result
{
db::get_conspiracy_by_id(&self.0, &msg.page_id)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment