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

Error when deriving QueryableByName: 'expected 1 type argument' #1368

Closed
agersant opened this Issue Dec 11, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@agersant

agersant commented Dec 11, 2017

Setup

Versions

  • Rust: Stable
  • Diesel: 0.99.0
  • Database: SQLite
  • Operating System: Windows

Feature Flags

  • diesel: sqlite
  • diesel_codegen: sqlite

Problem Description

While updating code from https://github.com/agersant/polaris to a newer diesel version and removing deprecated constructs, the suggested steps lead to an unhelpful compilation error.

The offending piece of code is:

let query = sql::<songs::SqlType>(r#"
	SELECT s.id, s.path, s.parent, s.track_number, s.disc_number, s.title, s.artist, s.album_artist, s.year, s.album, s.artwork
	FROM playlist_songs ps
	LEFT JOIN songs s ON ps.path = s.path
	WHERE ps.playlist = ?
	ORDER BY ps.ordering
"#);
let query = query.clone().bind::<Integer, _>(playlist.id);

Where songs is a SQL table:

#[derive(Debug, Queryable, Serialize)]
pub struct Song {
	#[serde(skip_serializing)]
	id: i32,
	pub path: String,
	#[serde(skip_serializing)]
	pub parent: String,
	pub track_number: Option<i32>,
	pub disc_number: Option<i32>,
	pub title: Option<String>,
	pub artist: Option<String>,
	pub album_artist: Option<String>,
	pub year: Option<i32>,
	pub album: Option<String>,
	pub artwork: Option<String>,
	pub duration: Option<i32>,
}

Compiling this code with diesel 0.99.0 works but yields the following warning: warning: use of deprecated item: use sql_query if you need bind parameters.

I updated the code following the warning's recommendation:

let query = diesel::sql_query(r#"
	(unchanged)
"#);
let query = query.clone().bind::<Integer, _>(playlist.id);
songs = query.get_results(connection.deref())?;

I got a (reasonable) error out of it: the trait diesel::query_source::QueryableByNamediesel::sqlite::Sqliteis not implemented forindex::Song``. Let's add the corresponding derive and table_name marker:

#[derive(Debug, Queryable, QueryableByName, Serialize)]
#[table_name = "songs"]
pub struct Song {
(unchanged)
}

This now fails to compile with an unhelpful error:

#[derive(Debug, Queryable, QueryableByName, Serialize)]
                           ^^^^^^^^^^^^^^^ expected 1 type argument

Steps to reproduce

Download the attached crate
diesel_qbn.zip
and execute cargo check.

Checklist

  • I have already looked over the issue tracker for similar issues.
@sgrif

This comment has been minimized.

Member

sgrif commented Dec 12, 2017

Thank you for providing code to reproduce the issue. I am looking at it now.

@sgrif

This comment has been minimized.

Member

sgrif commented Dec 12, 2017

After pulling the generated code with cargo expand, and then compiling that to see what line is causing the issue, it appears this is caused because you have shadowed Result with your own type. You can work around this issue by replacing use errors::* with something that doesn't import Result, and changing the code which used that type to use errors::Result instead.

@sgrif sgrif closed this Dec 12, 2017

@agersant

This comment has been minimized.

agersant commented Dec 13, 2017

Thank you very much for taking the time to investigate! Sorry it was a false alarm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment