A safe, extensible ORM and Query Builder for Rust – For feature requests and longer questions also see https://discourse.diesel.rs
@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`
Queryable<diesel::sql_types::Numeric, Pg>
is not implemented for BigDecimal
#![allow(unused)]
#![allow(clippy::all)]
use super::schema::employee;
use chrono::NaiveDateTime;
use bigdecimal::BigDecimal;
#[derive(Queryable, Debug, Identifiable)]
#[table_name = "employee"]
#[primary_key(employee_id)]
pub struct Employee {
pub employee_id: i32,
pub name: Option<String>,
pub age: Option<i32>,
pub address: Option<String>,
pub email: Option<String>,
pub dept_id: i32,
pub salary: Option<BigDecimal>,
pub created_on: Option<NaiveDateTime>,
pub created_by: Option<String>,
pub modified_on: Option<NaiveDateTime>,
pub modified_by: Option<String>,
pub is_active: Option<bool>,
}
let employees: Vec<Employee> = employee
.load::<Employee>(&connection)
.expect("Error loading employee");
for emp in employees {
println!("{}", emp.name.unwrap_or_default());
}
the trait `Queryable<diesel::sql_types::Numeric, Pg>` is not implemented for `BigDecimal`
[dependencies]
diesel = { version = "1.4.5", features = ["postgres","chrono"] }
dotenv = "0.15.0"
chrono = { version = "0.4.19" , features = ["serde"] }
bigdecimal = { version = "0.2.0" , features = ["serde"] }
diesel = { version = "1.4.5", features = ["postgres","chrono","numeric"] }