A safe, extensible ORM and Query Builder for Rust – For feature requests and longer questions also see https://github.com/diesel-rs/diesel/discussions/categories/q-a
#[macro_use]
extern crate diesel;
table! {
examples (id) {
id -> Int4,
bytes -> Bytea,
}
}
// Compiles
#[derive(Queryable)]
struct Example {
id: i32,
bytes: [u8; 8],
}
// Doesn't compile
#[derive(Insertable)]
#[table_name = "examples"]
struct NewExample {
bytes: [u8; 8],
}
for now, my code looks like:
table
.filter(available.eq(query.available()))
.limit(query.limit())
.offset(query.offset());
diesel is AWESOME~~~
@tzsword I have actually been looking into this issue last week. The issue is that diesel uses some derive macros inside it non proc macros which is why re-exporting doesn't work. I am planning to solve it soon.
Awesomeeeeeeeeeeeeee this is very cool, can I help? I'm a rookie~~
$crate::query_builder::QueryId
by adding the derived code locally
Diesel doesn't currently provide a way to explicitly assign a field to its default value, though it may be provided in the future.
I have been meaning to ask about this. I find that I need to specify DEFAULT
in INSERT
. I looked at the docs and it looks like it is not supported and this is the closest info I could find. Can you please confirm?
CREATE TABLE users (
id SERIAL,
name VARCHAR(255),
email VARCHAR(255) DEFAULT NULL
);
INSERT INTO users (name, email) VALUES ('John', 'john@gmail.com'), ('Sean', DEFAULT);
That way the following will work.
diesel::insert_into(users).values(&(name.eq("Sean"), email.default)).execute(&conn);
will work. Notice the email.default
let mut posts_query = schema::posts::table.into_boxed::<Pg>();
if let Some(foo_id) = foo.id {
posts_query = posts.filter(id.eq(foo_id));
}
if let Some(foo_title) = foo.title {
posts_query = posts.filter(title.eq(foo_title));
}
if let Some(foo_name) = foo.name {
posts_query = posts.filter(name.eq(foo_name));
}
--> src/main.rs:54:21
|
54 | posts_query = posts.filter(name.eq(foo_name));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `diesel::query_builder::BoxedSelectStatement`, found struct `diesel::query_builder::SelectStatement`