-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing diesel::Expression
, etc., for custom types outside diesel?
#562
Comments
diesel::Expression
, etc., for custom types outside diesel?diesel::Expression
, etc., for custom types outside diesel?
Not at the moment. We should probably make those macros public (with a Anyway it needs further exploration and discussion. I'm fine with making those macros public for the time being if you'd like to open a PR. |
I am preparing a small PR to make the macros public, as I would like to use them as well. Would it make sense to also make Edit: There's also |
Thanks for this effort. It should make it easier to deal with #343. AIUI, registering a new type Edit: Sorry, I should have read the issue more closely. It looks like you are not adding a new database type, but registering a Rust type for use with Diesel. Please disregard the above if it does not actually apply to your situation. |
@DTSu No, |
Did the details of how to do this change in diesel 0.10? I'm now getting these errors, using diesel and diesel_codegen 0.10.0 (with the postgres feature):
The struct in question is: #[derive(AsChangeset, Debug, Clone, Identifiable, Insertable, Queryable)]
#[table_name = "profiles"]
pub struct Profile {
pub id: ruma_identifiers::UserId,
pub avatar_url: Option<String>,
pub displayname: Option<String>,
} The previously working implementations for |
Moving my question to its own issue: #640 |
Closing as a duplicate of #162. See #343 (comment) for some thoughts on this. |
Also I should expand on this a little bit since this issue is slightly different. Specifically for the case of "implementing support for a Rust type that is not crate local, for a SQL type which is crate local" (an example of this is implementing support for |
As a followup to #561, I'd like to try defining a custom
ToSql
andFromSql
implementation for a type in a crate besidesdiesel
. I'm going to try this with https://github.com/faradayio/bigml-rs, which a client for the commercial BigML machine learning service.This crate contains a type
Id
, which represents a string of the formsource/1234
orexecution/5678
. Because these strings refer to different types of resources, theId
type takes parameters:Id<Source>
orId<Execution>
. So far, no problems.I can declare
ToSql
andFromSql
instances as follows:But if I try to use these impls, I run into problems. This code:
...gives me the errors:
It looks like the missing pieces are basically:
But the macros
queryable_impls!
andexpression_impls!
are private, and relatively large and complex. Is there a story for implementing these traits correctly from outsidediesel
itself?The text was updated successfully, but these errors were encountered: