Skip to content

Instantly share code, notes, and snippets.

@amitu amitu/

Last active Jun 28, 2020
What would you like to do?
citext for diesel/postgresql
diesel print-schema > src/
sed -i '' -e 's/Citext/mycrate::sql_types::Citext/g' src/
use diesel::{
deserialize::{self, FromSql},
serialize::{self, Output, ToSql},
use std::io::Write;
#[derive(Debug, Clone, Copy, SqlType, QueryId)]
#[postgres(type_name = "citext")]
pub struct Citext;
#[derive(Clone, Debug, FromSqlRow, AsExpression, PartialOrd, PartialEq)]
#[sql_type = "Citext"]
pub struct CiString(pub String);
pub fn citext(s: &str) -> CiString {
impl ToSql<Citext, Pg> for CiString {
fn to_sql<W: Write>(&self, out: &mut Output<W, Pg>) -> serialize::Result {
ToSql::<Text, Pg>::to_sql(&self.0, out)
impl FromSql<Citext, Pg> for CiString {
fn from_sql(bytes: Option<&[u8]>) -> deserialize::Result<Self> {
Ok(CiString(FromSql::<Text, Pg>::from_sql(bytes)?))

This comment has been minimized.

Copy link

manonthemat commented Apr 13, 2020

Would love to have citext support for diesel via a crate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.