-
Notifications
You must be signed in to change notification settings - Fork 8
First draft of a dynamic select clause feature in diesel-dynamic-schema #10
base: master
Are you sure you want to change the base?
Conversation
Hi, is there a way to test this implementation? I tried importing both Diesel and [dependencies.diesel]
git = "https://github.com/GiGainfosystems/diesel"
branch = "feature/dynamic_queries"
features = ["postgres", "chrono", "uuidv07"]
[dependencies.diesel-dynamic-schema]
git = "https://github.com/GiGainfosystems/diesel-dynamic-schema.git"
branch = "feature/dynamic_query" I get a bunch of
And
And even:
Am I doing something wrong? I'm using Rocket with Diesel, with the same repo (https://github.com/Razican/Rocket/tree/async_dynamic_diesel). |
Just using a git dependency don't work for diesel, because we've a internal dependency on diesel_derives. You need to use a |
Cool! that worked. I will now try this :) For those with the same issue, the required configuration was the following: [dependencies]
diesel = { version = "=1.4.3", features = ["postgres", "chrono", "uuidv07"] }
[replace]
"diesel:1.4.3" = { git = "https://github.com/GiGainfosystems/diesel", branch = "feature/dynamic_queries" }
"diesel_derives:1.4.1" = { git = "https://github.com/GiGainfosystems/diesel", branch = "feature/dynamic_queries" } The features can be any, and there is no need to fork Rocket if you are using it. |
Hi @weiznich, I seem to be running into problems with this. I am using the code from the
I checked the code, and it seems that the #[cfg(feature = "postgres")]
impl<'a, QS> Expression for DynamicSelectClause<'a, diesel::pg::Pg, QS> {
type SqlType = crate::dynamic_value::Any;
} Maybe I'm doing something wrong? I tried to compile the crate and to run the tests, but I'm getting similar errors to those in Travis. |
@Razican That PR version was not really meant to be used from someone, it was just there for discussion of the API. I've uploaded a fixed version that should work as long as you use the same diesel version everywhere. |
Thanks @weiznich, it compiles now. I will try it out to see how it feels to use it, but it seems pretty good to me for now. I would maybe add the |
In my opinion exposing something like |
After working with this for some time, I feel that I had to implement this to convert the row into JSON: // Transform the list of records to JSON format.
Ok(record_list
.into_iter()
.map(|row| {
let mut record = Record::new();
for column_name in &column_list {
if let Some(value) = row.get_by_name(column_name) {
let _ = record.insert(column_name.to_owned(), value.clone().into());
}
}
record
})
.collect()) But it would be easier being able to iterate over the row fields. It would be more efficient and I avoid passing the list of columns. |
Some extra useful feature in Since all the select clause is dynamic, it makes sense to be able to test that the proper types are being added to it. |
Also add tests case for each backend
Implemented Clone for `NamedField`s
backends construct that type
That change allows `DynamicRow` to be used with `sql_query`
Added getters to columns and tables
Hi @weiznich does this now depend on the 2.0 branch of Diesel? Is there a way to make it work wit 1.4? If not, I guess it will not be possible to integrate this with a Rocket application for the time being, right? |
@Razican This depends on the diesel 2.0 branch from the beginning. There is no way to make this ever work with 1.4. Additionally to make this clear again: This is a development version. I do not want to support running that in third party applications in any way, for obvious reasons. If you really want to use a random unfinished WIP PR in your application your are on your own. Otherwise the fasted way to get this workable in an official release is by contributing to diesel/diesel-dynamic-schema for the remaining release blocker. |
Blocked on diesel-rs/diesel#2182