Comments (8)
Are you use
ung the table from the other module? I don't see it in your code. Can you post the full code?
from diesel.
That's the full code. I thought that derive
ing Queriable
will be enough.
Using table!
macro does not make it compile though.
#![feature(custom_derive)]
#[macro_use]
extern crate diesel;
use diesel::*;
table! {
users {
id -> Serial,
name -> VarChar,
favorite_color -> Nullable<VarChar>,
}
}
#[derive(Queriable, Debug)]
pub struct User {
id: i32,
name: String,
favorite_color: Option<String>,
}
fn main() {
let connection = Connection::establish(env!("DATABASE_URL"))
.unwrap();
let users: Vec<User> = users::table.load(&connection)
.unwrap().collect();
println!("Here are all the users in our database: {:?}", users);
}
src/main.rs:27:19: 27:28 error: the trait `diesel::query_source::Queriable<(diesel::types::Integer, diesel::types::VarChar, diesel::types::Nullable<diesel::types::VarChar>)>` is not implemented for the type `User` [E0277]
src/main.rs:27 .unwrap().collect();
^~~~~~~~~
src/main.rs:27:19: 27:28 help: run `rustc --explain E0277` to see a detailed explanation
src/main.rs:26:41: 26:58 error: the trait `diesel::query_source::Queriable<(diesel::types::Integer, diesel::types::VarChar, diesel::types::Nullable<diesel::types::VarChar>)>` is not implemented for the type `User` [E0277]
src/main.rs:26 let users: Vec<User> = users::table.load(&connection)
^~~~~~~~~~~~~~~~~
src/main.rs:26:41: 26:58 help: run `rustc --explain E0277` to see a detailed explanation
error: aborting due to 2 previous errors
Could not compile `try_diesel`.
from diesel.
Deriving should be enough. Have you followed the instructions at https://github.com/sgrif/diesel/blob/master/diesel_codegen/README.md#using-on-nightly? This looks like you're probably just missing the default-features = false, features = ["nightly"]
on codegen
from diesel.
If I don't use table!
- where should I get the users
module?
Naa, it didn't work out :(
[dependencies]
diesel = "*"
diesel_codegen = { version = "^0.1.0", default-features = false, features = ["nightly"] }
#![feature(custom_derive, custom_attribute, plugin)]
#![plugin(diesel_codegen)]
#[macro_use]
extern crate diesel;
extern crate diesel_codegen;
use diesel::*;
Compiling aster v0.8.0
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:950:35: 950:52 error: use of undeclared type name `ast::ImplItemKind` [E0412]
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:950 pub fn build_item(self, node: ast::ImplItemKind) -> F::Result {
^~~~~~~~~~~~~~~~~
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:950:35: 950:52 help: run `rustc --explain E0412` to see a detailed explanation
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:979:20: 979:44 error: failed to resolve. Could not find `ImplItemKind` in `syntax::ast` [E0433]
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:979 let node = ast::ImplItemKind::Const(const_.ty, const_.expr.expect("an expr is required for a const impl item"));
^~~~~~~~~~~~~~~~~~~~~~~~
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:979:20: 979:44 help: run `rustc --explain E0433` to see a detailed explanation
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:979:20: 979:44 error: unresolved name `ast::ImplItemKind::Const` [E0425]
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:979 let node = ast::ImplItemKind::Const(const_.ty, const_.expr.expect("an expr is required for a const impl item"));
^~~~~~~~~~~~~~~~~~~~~~~~
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:979:20: 979:44 help: run `rustc --explain E0425` to see a detailed explanation
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:990:20: 990:45 error: failed to resolve. Could not find `ImplItemKind` in `syntax::ast` [E0433]
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:990 let node = ast::ImplItemKind::Method(method.sig, method.block.expect("a block is required for a method impl item"));
^~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:990:20: 990:45 help: run `rustc --explain E0433` to see a detailed explanation
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:990:20: 990:45 error: unresolved name `ast::ImplItemKind::Method` [E0425]
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:990 let node = ast::ImplItemKind::Method(method.sig, method.block.expect("a block is required for a method impl item"));
^~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:990:20: 990:45 help: run `rustc --explain E0425` to see a detailed explanation
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1001:20: 1001:43 error: failed to resolve. Could not find `ImplItemKind` in `syntax::ast` [E0433]
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1001 let node = ast::ImplItemKind::Type(ty);
^~~~~~~~~~~~~~~~~~~~~~~
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1001:20: 1001:43 help: run `rustc --explain E0433` to see a detailed explanation
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1001:20: 1001:43 error: unresolved name `ast::ImplItemKind::Type` [E0425]
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1001 let node = ast::ImplItemKind::Type(ty);
^~~~~~~~~~~~~~~~~~~~~~~
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1001:20: 1001:43 help: run `rustc --explain E0425` to see a detailed explanation
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1012:20: 1012:44 error: failed to resolve. Could not find `ImplItemKind` in `syntax::ast` [E0433]
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1012 let node = ast::ImplItemKind::Macro(mac);
^~~~~~~~~~~~~~~~~~~~~~~~
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1012:20: 1012:44 help: run `rustc --explain E0433` to see a detailed explanation
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1012:20: 1012:44 error: unresolved name `ast::ImplItemKind::Macro` [E0425]
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1012 let node = ast::ImplItemKind::Macro(mac);
^~~~~~~~~~~~~~~~~~~~~~~~
/home/user/.cargo/registry/src/github.com-0a35038f75765ae4/aster-0.8.0/src/item.rs:1012:20: 1012:44 help: run `rustc --explain E0425` to see a detailed explanation
error: aborting due to 9 previous errors
Could not compile `aster`.
And I make it diesel_codegen = "*"
src/main.rs:29:19: 29:28 error: the trait `diesel::query_source::Queriable<(diesel::types::Integer, diesel::types::VarChar, diesel::types::Nullable<diesel::types::VarChar>)>` is not implemented for the type `User` [E0277]
src/main.rs:29 .unwrap().collect();
^~~~~~~~~
src/main.rs:29:19: 29:28 help: run `rustc --explain E0277` to see a detailed explanation
src/main.rs:28:41: 28:58 error: the trait `diesel::query_source::Queriable<(diesel::types::Integer, diesel::types::VarChar, diesel::types::Nullable<diesel::types::VarChar>)>` is not implemented for the type `User` [E0277]
src/main.rs:28 let users: Vec<User> = users::table.load(&connection)
^~~~~~~~~~~~~~~~~
src/main.rs:28:41: 28:58 help: run `rustc --explain E0277` to see a detailed explanation
error: aborting due to 2 previous errors
Could not compile `try_diesel`.
from diesel.
I should probably make it more clear in the README, table!
must be called, we don't derive it for you. As for the first set of errors, try updating to the latest nightly, or use Syntex + stable
from diesel.
Got latest nightly. It works! Sorry, I should've done this before.
How about making #[derive(Queriable)]
smart enough to produce appropriate table!
call? Does it seem to be possible?
from diesel.
The problem is that the type of your struct can very much not be one-to-one with the types of the table. I am planning on eventually adding load_table_from_schema!(table_name)
and load_schema!
, which will use a database connection at compile time to get this information from the database.
from diesel.
How about marking fields like this?
#[derive(Queriable, Debug)]
pub struct User {
#[column_type = Serial]
id: i32,
#[column_type = VarChar]
name: String,
}
UPD: this particular issue is closed. Let's make another one for automatic generation of table!
call?
from diesel.
Related Issues (20)
- Documentation: Improve documentation for upsert `.filter_target()` HOT 2
- splitting into multiple schema.rs HOT 1
- Interaction between `#[derive(AsChangeset)]` and macro in type position HOT 2
- SQLite + PRAGMA foreign_keys = ON => missing error HOT 9
- `.distinct_on` is limited to maximum three `.order_by`s HOT 2
- Runtime Error for count() with order_by clause combined HOT 5
- fix: `sql_query` error "`Untyped: CompatibleType<std::string::String, Pg>` is not satisfied" HOT 1
- Impossible to combine into_boxed and group_by
- Impossible to combine into_boxed and group_by
- Failed to save array of enums HOT 3
- Nullable<diesel::sqlite::sql_types::Timestamptz> throws trait not implement errors
- Segmentation Fault in R2D2 postgres (interrupted by signal 11: SIGSEGV) HOT 10
- `joinable!` is not generated for two foreign keys referencing the same table HOT 1
- Diesel-cli Can't connect to local MySQL server through socket '/tmp/mysql.sock' HOT 1
- Deserialization layer seems too permissive with regards to checking the actual types received HOT 1
- Can't use `into_boxed` after union HOT 1
- table have more than one primary_key can not use on_conflict(diesel::dsl::DuplicatedKeys) HOT 7
- No intellisense when using query dsl HOT 6
- `overflow evaluating the requirement` when writing generic diesel code HOT 1
- Pagination guide doesn't work on entity represented by joined tables HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from diesel.