Diesel 2.0 update thread. #3144
Replies: 14 comments 51 replies
-
Nice work! I upgraded a (currently private) hobby project of mine and it went smoothly with just a couple of find and replaces except that the new version didn't like me having a column in my database named alias: error[E0308]: mismatched types
--> src/schema.rs:248:1
|
248 | / table! {
249 | | tag_aliases (id) {
250 | | id -> Int4,
251 | | created -> Timestamptz,
... |
257 | | }
258 | | }
| | ^
| | |
| | expected struct `Alias`, found struct `tag_aliases::columns::alias`
| | expected due to this
| | unit struct defined here
| |_`alias` is interpreted as a unit struct, not a new binding
| help: introduce a new binding instead: `other_alias`
|
= note: expected struct `Alias<S>`
found struct `tag_aliases::columns::alias`
= note: this error originates in the macro `$crate::__diesel_table_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0599]: no method named `field` found for struct `tag_aliases::columns::alias` in the current scope
--> src/schema.rs:248:1
|
248 | / table! {
249 | | tag_aliases (id) {
250 | | id -> Int4,
251 | | created -> Timestamptz,
... |
257 | | }
258 | | }
| | ^
| | |
| |_method `field` not found for this
| method not found in `tag_aliases::columns::alias`
|
= note: this error originates in the macro `$crate::__diesel_table_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
Some errors have detailed explanations: E0308, E0599.
For more information about an error, try `rustc --explain E0308`. The error didn't make too much sense to me at first, but I saw aliasing mentioned in the release notes so I tried renaming the column which fixed the issue. I tried using Selectable with the derive, naively trying to use #[derive(Selectable)]
#[diesel(table_name = crate::schema::posts)]
pub struct PostSmall {
pub id: i32,
#[diesel(column_name = "thumbnail_filename")]
pub thumbnail: String,
pub title: String,
#[diesel(column_name = "users::id")]
pub user_id: i32,
#[diesel(column_name = "users::display_name")]
pub username: String,
} but the derive didn't like it. For what it's worth my intent was to replace a macro I wrote that looks like this make_query! {
pub struct PostSmall {
pub id: i32 = posts::id,
pub thumbnail: String = posts::thumbnail_filename,
pub title: String = posts::title,
pub user_id: i32 = users::id,
pub username: String = users::display_name,
}
} I'm happy with my current setup and I even rewrote my macro to create the Selectable impl so it's not a huge deal if the derive is not intended for this kind of usage, this just happened to be the first thing I tried after I got the project to compile with 2.0. |
Beta Was this translation helpful? Give feedback.
-
Thanks @weiznich and the team for the awesome work. I've faced these issues, till now.
I have the latest stable Rust version. |
Beta Was this translation helpful? Give feedback.
-
Thanks @weiznich - the new features are pretty much exactly what I was looking for from using 1.4. I've migrated a bunch of stuff and haven't faced any problems so far. The only thing which was an inconvenience was not being able to use a generic connection with the SaveChangesDSL. Wanted to get your views on that - example here. |
Beta Was this translation helpful? Give feedback.
-
We have a project we are working on and we started it off with Diesel 1.4, but since it's still in development we jumped on the chance to test it and continue the work on 2.0 version. Most of the stuff is already migrated, but now I am facing a blocker to move forward (maybe there is a simple solution). Basically, we have some query builders internally and we used the type DieselBoxedType<'a> = diesel::query_builder::BoxedSelectStatement<
'a,
user_sessions::SqlType,
user_sessions::table,
diesel::pg::Pg,
>; But, but even if it was, I still get an error that seems like this won't be possible to do anymore, this is some example code: impl ExamplePgRepository {
pub fn start_query<'a>(&self) -> DieselBoxedType<'a> {
user_sessions::table.into_boxed()
}
} The error I get:
As I can see, the error could easily be solved with Is this a bug or is it on purpose so I should do it differently? |
Beta Was this translation helpful? Give feedback.
-
Thanks to everyone who contributed to this milestone; it's an impressive piece of work! One point of friction I've had is with types like #[derive(Queryable)]
struct MyTaggedStruct {
// ... other fields ...
tags: Vec<String>,
} In the |
Beta Was this translation helpful? Give feedback.
-
Thank you for all your efforts for bringing this big release! I have successfully migrated my hobby project to use diesel 2.0.0-rc.0 without much trouble, the full code changes are here. Here are some minor problems that I encountered:
-pub trait CindyFilter<Table: Send, DB> {
- fn as_expression(self) -> Option<Box<dyn BoxableExpression<Table, DB, SqlType = Bool> + Send>>;
+pub trait CindyFilter<Table> {
+ fn as_expression(self) -> Option<Box<dyn BoxableExpression<Table, diesel::pg::Pg, SqlType = Bool>>>;
}
|
Beta Was this translation helpful? Give feedback.
-
https://github.com/adwhit/diesel-derive-enum doesn't work anymore, |
Beta Was this translation helpful? Give feedback.
-
I am using both diesel 2.0 and oso in a project, if I define a struct:
get error:
if use |
Beta Was this translation helpful? Give feedback.
-
Hello, thanks for this project! I'm migrating to release 2.0.0 and I'm running into a problem (which is not necessarily diesel related, I realize that) with pagination which is based on the advanced blog example. I refactored to use
The errors occur here https://gist.github.com/rj76/3a0f2635473a54e3f880cd14ea46e84e#file-pagination-rs-L88 I tried modifying the where of impl LoadPaginated on line 78, but it's referencing a private field. Do you have any directions as to what to change to fix the error? Is the change of the lifetimes causing this? |
Beta Was this translation helpful? Give feedback.
-
I am just wondering if it's just me, but since the update to 2.0.0-rc.0 rust analyzer doesn't like the scheme file anymore even though everything works just fine. It is somewhat inconvenient. Do I miss something here? |
Beta Was this translation helpful? Give feedback.
-
Hello 👋 I'm having trouble migrating some I have a table like following table! {
transactions (id) {
id -> Text,
amount -> Integer,
description -> Nullable<Text>,
registered_on -> Timestamp,
created_at -> Timestamp,
updated_at -> Timestamp,
deleted -> Bool,
}
}
// And the model
#[derive(
PartialEq, Debug, Clone, Insertable, Identifiable, Serialize, Deserialize, Queryable, Selectable,
)]
#[table_name = "transactions"]
pub struct Transaction {
pub id: Uuid,
pub amount: i32,
pub description: Option<String>,
#[serde(with = "ts_seconds")]
pub registered_on: NaiveDateTime,
#[serde(with = "ts_seconds")]
pub created_at: NaiveDateTime,
#[serde(with = "ts_seconds")]
pub updated_at: NaiveDateTime,
pub deleted: bool,
} And I have some custom methods to help me reuse some queries that were working fine on 1.4 impl Transaction {
pub fn in_span<'a, T>(from: T, to: T) -> BoxedQuery<'a>
where
T: 'a,
T: AsExpression<Timestamp>,
T::Expression: BoxableExpression<transactions::table, Sqlite>,
{
transactions::table
.filter(transactions::registered_on.ge(from))
.filter(transactions::registered_on.lt(to))
.into_boxed()
}
}
type SqlType = <AllColumns as Expression>::SqlType;
type BoxedQuery<'a> = transactions::BoxedQuery<'a, Sqlite, SqlType>;
type AllColumns = (
transactions::id,
transactions::amount,
transactions::description,
transactions::registered_on,
transactions::created_at,
transactions::updated_at,
transactions::deleted,
);
const ALL_COLUMNS: AllColumns = (
transactions::id,
transactions::amount,
transactions::description,
transactions::registered_on,
transactions::created_at,
transactions::updated_at,
transactions::deleted,
); But I'm getting errors when trying to use either
I've tried limiting the types, like
But it still keeps failing 😢 some help is highly appreciated, because I'm not sure what I'm doing tbh, I couldn't find an example anywhere |
Beta Was this translation helpful? Give feedback.
-
After Diesel 2.0, since to_sql now requires additional reference parameters, I can't use Jsonb type. use diesel::{
deserialize::{FromSql, FromSqlRow},
pg::{Pg, PgValue},
serialize::{Output, ToSql},
sql_types::Jsonb,
AsExpression,
};
use serde::{Deserialize, Serialize};
#[derive(Eq, PartialEq, Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(tag = "type", content = "content")]
pub enum SerializableEnum {
Messages(Vec<String>),
Value(String),
None,
}
#[derive(FromSqlRow, AsExpression, Deserialize, Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[diesel(sql_type = Jsonb)]
pub struct SerializableStruct(pub SerializableEnum);
impl FromSql<Jsonb, Pg> for SerializableStruct {
fn from_sql(bytes: PgValue<'_>) -> diesel::deserialize::Result<Self> {
let value = <serde_json::Value as FromSql<Jsonb, Pg>>::from_sql(bytes)?;
Ok(serde_json::from_value(value)?)
}
}
impl ToSql<Jsonb, Pg> for SerializableStruct
where
serde_json::Value: ToSql<Jsonb, Pg>,
{
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Pg>) -> diesel::serialize::Result {
let value = serde_json::to_value(self)?;
let res = <serde_json::Value as ToSql<Jsonb, Pg>>::to_sql(&value, out);
res
}
}
fn main() {
println!("Hello, world!");
} |
Beta Was this translation helpful? Give feedback.
-
Hi all, Great work on new release, people. I have a question about
Should all the tables participating in |
Beta Was this translation helpful? Give feedback.
-
Hi all, |
Beta Was this translation helpful? Give feedback.
-
This thread is dedicated to feedback about updating existing code bases to diesel 2.0.
We are interesting in the following information:
Useful Resources:
Beta Was this translation helpful? Give feedback.
All reactions