Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upPrinted schema contains Citext types #1624
Comments
This comment has been minimized.
|
|
sgrif
closed this
Apr 7, 2018
This comment has been minimized.
alexfedoseev
commented
Apr 8, 2018
|
@sgrif Yeah, |
This comment has been minimized.
|
You'd need to fully implement it as a custom type, like this test |
This comment has been minimized.
alexfedoseev
commented
Apr 8, 2018
|
Gotcha, thanks! |
This comment has been minimized.
Boscop
commented
Aug 30, 2018
|
But then how to support case-insensitive string comparison with a custom Citext type? |
This comment has been minimized.
This comment has been minimized.
alexfedoseev
commented
Sep 17, 2018
|
Recent activity reminded me about this task so I tried to implement it on the weekend. AFAIU from the history, the issue w/ this type is that @sgrif Can you take a look if what I did makes sense (just requires some adjustments) or I did something stupid and it should be implemented differently? Thanks in advance! use std::io::Write;
use diesel::deserialize::{self, FromSql};
use diesel::expression::operators::Eq;
use diesel::expression::{AsExpression, Expression};
use diesel::expression_methods::ExpressionMethods;
use diesel::pg::Pg;
use diesel::serialize::{self, Output, ToSql};
use diesel::sql_types::Text;
#[derive(Debug, Clone, Copy, SqlType)]
#[postgres(type_name = "citext")]
pub struct Citext;
impl ToSql<Citext, Pg> for String {
fn to_sql<W: Write>(&self, out: &mut Output<W, Pg>) -> serialize::Result {
ToSql::<Text, Pg>::to_sql(self, out)
}
}
impl ToSql<Citext, Pg> for str {
fn to_sql<W: Write>(&self, out: &mut Output<W, Pg>) -> serialize::Result {
ToSql::<Text, Pg>::to_sql(self, out)
}
}
impl FromSql<Citext, Pg> for String {
fn from_sql(bytes: Option<&[u8]>) -> deserialize::Result<Self> {
FromSql::<Text, Pg>::from_sql(bytes)
}
}
impl Expression for Citext {
type SqlType = Text;
}
impl ExpressionMethods for Citext {
// default implementation from current source
fn eq<T: AsExpression<Self::SqlType>>(self, other: T) -> Eq<Self, T::Expression> {
Eq::new(self, other.as_expression())
}
}But it gives me the following error:
I'm not sure why it conflicts since My guess is that |
This comment has been minimized.
|
There's no reason that you'd need to do anything related to |
This comment has been minimized.
alexfedoseev
commented
Sep 19, 2018
The reason why I get there is that in #1215 you said that
I'm not sure I understand this part either. In all examples I've seen (1, 2) there is re-implementation using some base diesel type, e.g.: impl FromSql<Citext, Pg> for String {
fn from_sql(bytes: Option<&[u8]>) -> deserialize::Result<Self> {
FromSql::<Text, Pg>::from_sql(bytes)
}
}But you're saying to Sorry for lots of questions! |
alexfedoseev commentedApr 7, 2018
Setup
I'm not sure I understand what
Setupsection means but I'm usingdieselwithhyper,r2d2and number of other packages to build web server.Versions
rustc 1.26.0-nightly (e5277c145 2018-03-28){ version = "=1.1.1", features = ["postgres", "chrono"] }postgres:10.0macOS 10.12.6Feature Flags
["postgres", "chrono"]Problem Description
I use
citextextension in postgres db and when I print schema by runningdiesel print-schemaoutput containsCitexttypes. AFAIU this type was added then removed. I'm not sure if it's a bug (that generated output containsCitexttype) or should I handle this type in my app somehow? For now I just manually replace it w/Text.What are you trying to accomplish?
I'm trying to generate valid schema w/ fields of
citexttype.What is the expected output?
I'm not sure :)
What is the actual output?
Printed schema contains
Citexttypes.Are you seeing any additional errors?
Nope, only errors related to unavailable
Citexttype.Steps to reproduce
Run
diesel print-schemaagainst postgres db which usescitextextension.Checklist