Replies: 12 comments 7 replies
-
Two things:
Btw, I am never aware of Diesel 2.x, how is it different from 1.x? Finally, yes if we've figured those things, we could integrate that into SeaQuery |
Beta Was this translation helpful? Give feedback.
-
It changed quite a lot internally, but the main change needed for this feature is the return of the bind function on raw sql can now be boxed so it can run in a loop. In v1 it returns a new type of object so you cant easily loop on it. |
Beta Was this translation helpful? Give feedback.
-
SeaQuery only requires that a type implements The crates Diesel use are pq-sys and mysqlclient-sys, but if you want to automatically convert them into the structs, then using Diesel should be slightly easier. |
Beta Was this translation helpful? Give feedback.
-
I got a working version of the driver for common cases in caido@bd0f734 My only problem is with the JSON, Chrono, etc extensions. I realized that I can't use the cfg inside the macro for that, but I don't have a better idea. I can't do like the sqlx driver since the method when not using the feature returns a bool ref which diesel refuses to take as input to bind. The need for a macro at all is a bit weird, we could just add diesel as a dependency for the feature and save us a lot of problems. |
Beta Was this translation helpful? Give feedback.
-
Well, that really seems cool! I never imagined Diesel could be used as a driver. |
Beta Was this translation helpful? Give feedback.
-
Yeah I saw the postgres driver, but I don't think diesel has separate types but if we import the core without any feature it wont pull any driver code. Would that be ok? I am not sure how to do it properly since diesel v2 is not released yet though (probably not for a few months still). Otherwise I think the best we can do is to document the features that need to be created in the host to enable the support for those extensions. What is the reasoning for not allowing dependencies on the target inside the sea-query under a feature? I feel that if the ORM doesn't want to have that dependency (because it doesnt need it or what not) then it can just not use the feature and thats it? |
Beta Was this translation helpful? Give feedback.
-
Hi Emile, just to check in. Have you made any progress in this matter? It's also fine if you have changed your mind. |
Beta Was this translation helpful? Give feedback.
-
I was able to make it work in our project because we have a diesel dep, but not in the framework as a macro. Also it uses an older version and I have not updated it to support more recent breaking changes. |
Beta Was this translation helpful? Give feedback.
-
Awesome, nice to know! |
Beta Was this translation helpful? Give feedback.
-
Updated for 0.21, missing the feature flags for json/datetime/array but it is the base use diesel::query_builder::{BoxedSqlQuery, SqlQuery};
use diesel::sql_types;
use diesel::sqlite::Sqlite;
use sea_query::{Value, Values};
pub trait Bindable<Inner> {
fn bind_values(self, params: &Values) -> BoxedSqlQuery<Sqlite, SqlQuery<Inner>>;
}
impl<Inner> Bindable<Inner> for SqlQuery<Inner> {
fn bind_values(self, params: &Values) -> BoxedSqlQuery<Sqlite, Self> {
let mut query = self.into_boxed();
for value in params.0.iter() {
query =
match value {
Value::Bool(v) => query.bind::<sql_types::Nullable<sql_types::Bool>, _>(v),
Value::TinyInt(v) => query
.bind::<sql_types::Nullable<sql_types::SmallInt>, _>(v.map(|v| v as i16)),
Value::SmallInt(v) => {
query.bind::<sql_types::Nullable<sql_types::SmallInt>, _>(v)
}
Value::Int(v) => query.bind::<sql_types::Nullable<sql_types::Integer>, _>(v),
Value::BigInt(v) => query.bind::<sql_types::Nullable<sql_types::BigInt>, _>(v),
Value::TinyUnsigned(v) => query
.bind::<sql_types::Nullable<sql_types::SmallInt>, _>(v.map(|v| v as i16)),
Value::SmallUnsigned(v) => query
.bind::<sql_types::Nullable<sql_types::SmallInt>, _>(v.map(|v| v as i16)),
Value::Unsigned(v) => query
.bind::<sql_types::Nullable<sql_types::Integer>, _>(v.map(|v| v as i32)),
Value::BigUnsigned(v) => {
query.bind::<sql_types::Nullable<sql_types::BigInt>, _>(v.map(|v| v as i64))
}
Value::Float(v) => query.bind::<sql_types::Nullable<sql_types::Float>, _>(v),
Value::Double(v) => query.bind::<sql_types::Nullable<sql_types::Double>, _>(v),
Value::String(v) => query.bind::<sql_types::Nullable<sql_types::Text>, _>(
v.as_ref().map(|v| v.as_str()),
),
Value::Bytes(v) => query.bind::<sql_types::Nullable<sql_types::Blob>, _>(
v.as_ref().map(|v| v.as_ref()),
),
};
}
query
}
} |
Beta Was this translation helpful? Give feedback.
-
I just want to leave another comment here to notice all interested persons that diesel 2.0 is finally released. This means work on such an integration has now a stable basis. For anyone interested in developing an integration between diesel and sea-query: Please reach out, I can provide pointers where to start and how to structure such an integration. |
Beta Was this translation helpful? Give feedback.
-
I am reviving this post since I plan on working on it. I read the code of the traits required for sea-query to avoid using the In all cases I think we can infer the query builder from the diesel connection backend with some trait implementation magic, correct me if I am wrong @weiznich. Essentially: Query::select()
.columns(Requests::Id)
.from(Requests::Table)
.compile() // Trait extension on SelectStatement, returns a DieselSelectStatement
.get_results::<Request>(conn) // Diesel trait VS: Query::select()
.columns(Requests::Id)
.from(Requests::Table)
.get_results::<Request>(conn) // Trait extension that calls internally the diesel function Thoughts @tyt2y3, @ikrivosheev, @billy1624? For the Iden generation from the diesel schema file, I am not sure how to do it so I will have to look into it a bit more before I can propose something. |
Beta Was this translation helpful? Give feedback.
-
Hello!
We currently use diesel for most of our queries, but we are having trouble with some advanced ones where we need conditional joins. We are thinking of using sea-query for that but we still want to use diesel for the rest for now. I am going to build the driver for diesel 2 (because diesel 1.x doesnt have boxed raw queries) and I was also thinking of building a macro to generate the Iden enums from the schema.
Do you think it would worth creating a PR to integrate that in the main repo?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions