Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hi diesel mysql unsize issue. #1627

Closed
haruhinoshana opened this issue Apr 9, 2018 · 3 comments
Closed

hi diesel mysql unsize issue. #1627

haruhinoshana opened this issue Apr 9, 2018 · 3 comments

Comments

@haruhinoshana
Copy link

haruhinoshana commented Apr 9, 2018

hi im new in using rust iron and diesel and i'm doing a sample project i got using rust iron with r2d2 diesel cli mysql..... heres the error.

error[E0308]: mismatched types
--> src/dal/models/user.rs:82:23
|
82 | Ok(new_user) => Ok(new_user),
| ^^^^^^^^ expected struct dal::models::user::User, found usize
|
= note: expected type dal::models::user::User
found type usize

error[E0308]: mismatched types
--> src/dal/models/post.rs:36:23
|
36 | Ok(new_post) => Ok(new_post),
| ^^^^^^^^ expected struct dal::models::post::Post, found usize
|
= note: expected type dal::models::post::Post
found type usize

heres the code...

pub fn create(user: &NewUser, connection: &DieselConnection, logger: &Logger) -> Result<User, diesel::result::Error> {
	let statement = diesel::insert(user)
	.into(users::table);

	info!(logger, "Executing Query"; "query" => debug_sql!(statement), "user" => format!("{:?}", user));

	let new_user = statement.execute(&**connection);
	//<User>

	match new_user {
		Ok(new_user) => Ok(new_user),
		Err(error) => {
			warn!(logger, "Error creating user"; o!("error" => format!("{:?}", error)));
			Err(error)
		},
	}
}

help me please im newbie.

@haruhinoshana haruhinoshana changed the title hi hi diesel mysql unsize issue. Apr 9, 2018
@weiznich
Copy link
Member

weiznich commented Apr 9, 2018

execute returns the number of affected rows.
For mysql there is no way that an insertstatment returns the inserted row, this needs a distinct query.

@weiznich weiznich closed this as completed Apr 9, 2018
@haruhinoshana
Copy link
Author

is there a work around to get the last_insert_id or let new_user = statement.get_result::(&**connection); in mysql diesel sir..

@sgrif
Copy link
Member

sgrif commented Apr 9, 2018

See http://docs.diesel.rs/diesel/macro.sql_function.html to use custom SQL functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants