Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- impl DbState {
- pub fn new(dbname: &str) -> DbState {
- println!(">>> setup!");
- DbState { conn: SqliteConnection::establish(dbname).unwrap() }
- // TODO: create all the tables
- }
- pub fn create_user(&self, email_fld: &str) -> (User, String) {
- let mut test_user = User::default();
- test_user.username = String::from("john");
- test_user.email = String::from(email_fld);
- test_user.password = String::from("7654321");
- diesel::insert_into(users)
- .values((
- username.eq(&test_user.username),
- password.eq(&test_user.password),
- email.eq(&test_user.email),
- )).execute(&self.conn)
- .expect("Test user could not be created.");
- // FIXME: boo cloning boo
- (test_user.clone(), test_user.password)
- }
- pub fn clean_db(&self) {
- println!(">>> dropping!");
- diesel::delete(users).execute(&self.conn)
- .expect("Cannot delete users");
- }
- }
- impl Drop for DbState {
- fn drop(&mut self) {
- self.clean_db();
- }
- }
- fn main() {
- let state = DbState::new();
- let (test_user, _) = state.create_user("hey@domain.con");
- println!("test user with id: {}", test_user.id);
- }
Add Comment
Please, Sign In to add comment