postgres 0.8.9

A native PostgreSQL driver
Documentation
use serialize::json;
use std::io::prelude::*;
use byteorder::{ReadBytesExt, WriteBytesExt};

use {Result, Error};
use types::{FromSql, ToSql, IsNull, Type};

impl FromSql for json::Json {
    fn from_sql<R: Read>(ty: &Type, raw: &mut R) -> Result<json::Json> {
        if let Type::Jsonb = *ty {
            // We only support version 1 of the jsonb binary format
            if try!(raw.read_u8()) != 1 {
                return Err(Error::BadResponse);
            }
        }
        json::Json::from_reader(raw).map_err(|_| Error::BadResponse)
    }

    accepts!(Type::Json, Type::Jsonb);
}

impl ToSql for json::Json {
    fn to_sql<W: Write+?Sized>(&self, ty: &Type, mut out: &mut W) -> Result<IsNull> {
        if let Type::Jsonb = *ty {
            try!(out.write_u8(1));
        }

        try!(write!(out, "{}", self));

        Ok(IsNull::No)
    }

    accepts!(Type::Json, Type::Jsonb);
    to_sql_checked!();
}