-
Notifications
You must be signed in to change notification settings - Fork 14
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
Change use crate::diesel::*;
import to be more specific and not require crate::
#94
Comments
i guess that is true, but currently it is somewhat expected you do a |
Good catch @jjangga0214! @hasezoey is right, we often include |
Re-opening the issue because of #116, this will need a better solution than just replacing the wildcard import (with some more specific import or a alias) |
i am thinking of fixing this, but there are 2 ways: 1: with a alias (if yes, what alias) use diesel as D;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, D::Queryable, D::Selectable, D::QueryableByName)]
#[D::diesel(table_name=todos, primary_key(id))]
pub struct Todos {
pub id: i32,
pub unsigned: u32,
pub unsigned_nullable: Option<u32>,
pub text: String,
pub completed: bool,
pub type_: String,
pub created_at: chrono::DateTime<chrono::Utc>,
pub updated_at: chrono::DateTime<chrono::Utc>,
} or 2: directly: #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName)]
#[diesel::diesel(table_name=todos, primary_key(id))]
pub struct Todos {
pub id: i32,
pub unsigned: u32,
pub unsigned_nullable: Option<u32>,
pub text: String,
pub completed: bool,
pub type_: String,
pub created_at: chrono::DateTime<chrono::Utc>,
pub updated_at: chrono::DateTime<chrono::Utc>,
} which would be better? (using direct imports like i personally think using @Wulf what do you think would be better? |
IMHO, the latter is better :) |
hey @hasezoey thanks for investigating and thinking of solutions. Again, sorry for the late reply, I've been in the middle of a move! Let's go with |
created #122 which changes most things to use the PS: also changed the issue title to better reflect what this is about |
use crate::diesel::*;
vs use diesel::*;
use crate::diesel::*;
import to be more specific and not require crate::
@hasezoey the changes in #114 result in compile time warning Update: removing this makes the I suggest a fix something like this diff --git a/src/code.rs b/src/code.rs
index 3ae6224..113bdea 100644
--- a/src/code.rs
+++ b/src/code.rs
@@ -731,7 +731,11 @@ fn build_imports(table: &ParsedTableMacro, config: &GenerationConfig) -> String
// Note: i guess this could also just be a string that is appended to, or a vec of "Cow", but i personally think this is the most use-able
// because you dont have to think of any context style (like forgetting to put "\n" before / after something)
let mut imports_vec = Vec::with_capacity(10);
- imports_vec.push("use crate::diesel::*;".into());
+ imports_vec.extend([
+ "#[allow(unused)]".into(),
+ "use diesel::prelude::*;".into(),
+ "".into(),
+ ]);
let table_options = config.table(&table.name.to_string());
imports_vec.extend(table.foreign_keys.iter().map(|fk| { |
The diesel::prelude members should always be non-conflicting with diesel code and hence are safe to import globally. Based on the options used when generating the may or may not be used by the resulting file and hence the import is allowed to be unused. Related: Wulf#94
@longsleep known issue, i just ignored it for now to actually get to removing the line completely and use traits with absolute paths, but i wanted #114 merged first to make it easier to find the issues and test the methods actually compile. |
this is a quick fix, and the import should be removed in the future altogether re Wulf#94
this is a quick fix, and the import should be removed in the future altogether re Wulf#94
dsync/test/simple_table/models/todos/generated.rs
Line 3 in 007ace8
dsync generates
use crate::diesel::*;
.But I think it actually should be
use diesel::*;
.diesel
is an external crate, which is not declared from the root of a user's project.The text was updated successfully, but these errors were encountered: