Update serde support
This commit is contained in:
parent
405d8dfce1
commit
d3182d96a6
@ -10,4 +10,4 @@ before_script:
|
||||
- "./.travis/setup.sh"
|
||||
script:
|
||||
- cargo test
|
||||
- cargo test --features "uuid rustc-serialize time unix_socket serde chrono openssl"
|
||||
- cargo test --features "uuid rustc-serialize time unix_socket serde_json chrono openssl"
|
||||
|
@ -32,7 +32,7 @@ rustc-serialize = "0.3"
|
||||
net2 = { version = "0.2", features = ["nightly"] }
|
||||
chrono = { version = "0.2.14", optional = true }
|
||||
openssl = { version = "0.6.4", optional = true }
|
||||
serde = { version = "0.3", optional = true }
|
||||
serde_json = { version = "0.6", optional = true }
|
||||
time = { version = "0.1.14", optional = true }
|
||||
unix_socket = { version = ">= 0.3, < 0.5", optional = true, features = ["socket_timeout"] }
|
||||
uuid = { version = "0.1", optional = true }
|
||||
|
@ -200,7 +200,7 @@ types. The driver currently supports the following conversions:
|
||||
<td>
|
||||
<a href="https://github.com/rust-lang/rustc-serialize">serialize::json::Json</a>
|
||||
and
|
||||
<a href="https://github.com/erickt/serde">serde::json::Value</a>
|
||||
<a href="https://github.com/erickt/serde_json">serde_json::Value</a>
|
||||
(<a href="#optional-features">optional</a>)
|
||||
</td>
|
||||
<td>JSON, JSONB</td>
|
||||
@ -284,7 +284,7 @@ implementations for `uuid`'s `Uuid` type.
|
||||
[JSON and JSONB](http://www.postgresql.org/docs/9.4/static/datatype-json.html)
|
||||
support is provided optionally by the `rustc-serialize` feature, which adds
|
||||
`ToSql` and `FromSql` implementations for `rustc-serialize`'s `Json` type, and
|
||||
the `serde` feature, which adds implementations for `serde`'s `json::Value`
|
||||
the `serde` feature, which adds implementations for `serde_json`'s `Value`
|
||||
type.
|
||||
|
||||
### TIMESTAMP/TIMESTAMPTZ/DATE/TIME types
|
||||
|
@ -49,8 +49,8 @@ mod time;
|
||||
mod slice;
|
||||
#[cfg(feature = "rustc-serialize")]
|
||||
mod rustc_serialize;
|
||||
#[cfg(feature = "serde")]
|
||||
mod serde;
|
||||
#[cfg(feature = "serde_json")]
|
||||
mod serde_json;
|
||||
#[cfg(feature = "chrono")]
|
||||
mod chrono;
|
||||
|
||||
@ -571,13 +571,13 @@ impl error::Error for WasNull {
|
||||
/// In addition, some implementations are provided for types in third party
|
||||
/// crates. These are disabled by default; to opt into one of these
|
||||
/// implementations, activate the Cargo feature corresponding to the crate's
|
||||
/// name. For example, the `serde` feature enables the implementation for the
|
||||
/// `serde::json::Value` type.
|
||||
/// name. For example, the `serde_json` feature enables the implementation for
|
||||
/// the `serde_json::Value` type.
|
||||
///
|
||||
/// | Rust type | Postgres type(s) |
|
||||
/// |-------------------------------------|-------------------------------------|
|
||||
/// | serialize::json::Json | JSON, JSONB |
|
||||
/// | serde::json::Value | JSON, JSONB |
|
||||
/// | serde_json::Value | JSON, JSONB |
|
||||
/// | time::Timespec | TIMESTAMP, TIMESTAMP WITH TIME ZONE |
|
||||
/// | chrono::NaiveDateTime | TIMESTAMP |
|
||||
/// | chrono::DateTime<UTC> | TIMESTAMP WITH TIME ZONE |
|
||||
@ -616,6 +616,7 @@ pub trait FromSql: Sized {
|
||||
///
|
||||
/// The default implementation returns
|
||||
/// `Err(Error::Conversion(Box::new(WasNull))`.
|
||||
#[allow(unused_variables)]
|
||||
fn from_sql_null(ty: &Type, ctx: &SessionInfo) -> Result<Self> {
|
||||
Err(Error::Conversion(Box::new(WasNull)))
|
||||
}
|
||||
@ -776,13 +777,13 @@ pub enum IsNull {
|
||||
/// In addition, some implementations are provided for types in third party
|
||||
/// crates. These are disabled by default; to opt into one of these
|
||||
/// implementations, activate the Cargo feature corresponding to the crate's
|
||||
/// name. For example, the `serde` feature enables the implementation for the
|
||||
/// `serde::json::Value` type.
|
||||
/// name. For example, the `serde_json` feature enables the implementation for
|
||||
/// the `serde_json::Value` type.
|
||||
///
|
||||
/// | Rust type | Postgres type(s) |
|
||||
/// |-------------------------------------|-------------------------------------|
|
||||
/// | serialize::json::Json | JSON, JSONB |
|
||||
/// | serde::json::Value | JSON, JSONB |
|
||||
/// | serde_json::Value | JSON, JSONB |
|
||||
/// | time::Timespec | TIMESTAMP, TIMESTAMP WITH TIME ZONE |
|
||||
/// | chrono::NaiveDateTime | TIMESTAMP |
|
||||
/// | chrono::DateTime<UTC> | TIMESTAMP WITH TIME ZONE |
|
||||
|
@ -1,9 +1,9 @@
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
|
||||
use std::error;
|
||||
use std::io::prelude::*;
|
||||
use byteorder::{ReadBytesExt, WriteBytesExt};
|
||||
use self::serde::json::{self, Value};
|
||||
use self::serde_json::Value;
|
||||
|
||||
use Result;
|
||||
use error::Error;
|
||||
@ -18,7 +18,7 @@ impl FromSql for Value {
|
||||
return Err(Error::Conversion(err));
|
||||
}
|
||||
}
|
||||
json::de::from_reader(raw).map_err(|err| Error::Conversion(Box::new(err)))
|
||||
serde_json::de::from_reader(raw).map_err(|err| Error::Conversion(Box::new(err)))
|
||||
}
|
||||
|
||||
accepts!(Type::Json, Type::Jsonb);
|
@ -13,8 +13,8 @@ mod uuid;
|
||||
mod time;
|
||||
#[cfg(feature = "rustc-serialize")]
|
||||
mod rustc_serialize;
|
||||
#[cfg(feature = "serde")]
|
||||
mod serde;
|
||||
#[cfg(feature = "serde_json")]
|
||||
mod serde_json;
|
||||
#[cfg(feature = "chrono")]
|
||||
mod chrono;
|
||||
|
||||
|
@ -1,22 +0,0 @@
|
||||
extern crate serde;
|
||||
|
||||
use self::serde::json::{self, Value};
|
||||
use types::test_type;
|
||||
|
||||
#[test]
|
||||
fn test_json_params() {
|
||||
test_type("JSON", &[(Some(json::from_str::<Value>("[10, 11, 12]").unwrap()),
|
||||
"'[10, 11, 12]'"),
|
||||
(Some(json::from_str::<Value>("{\"f\": \"asd\"}").unwrap()),
|
||||
"'{\"f\": \"asd\"}'"),
|
||||
(None, "NULL")])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_jsonb_params() {
|
||||
test_type("JSONB", &[(Some(json::from_str::<Value>("[10, 11, 12]").unwrap()),
|
||||
"'[10, 11, 12]'"),
|
||||
(Some(json::from_str::<Value>("{\"f\": \"asd\"}").unwrap()),
|
||||
"'{\"f\": \"asd\"}'"),
|
||||
(None, "NULL")])
|
||||
}
|
22
tests/types/serde_json.rs
Normal file
22
tests/types/serde_json.rs
Normal file
@ -0,0 +1,22 @@
|
||||
extern crate serde_json;
|
||||
|
||||
use self::serde_json::Value;
|
||||
use types::test_type;
|
||||
|
||||
#[test]
|
||||
fn test_json_params() {
|
||||
test_type("JSON", &[(Some(serde_json::from_str::<Value>("[10, 11, 12]").unwrap()),
|
||||
"'[10, 11, 12]'"),
|
||||
(Some(serde_json::from_str::<Value>("{\"f\": \"asd\"}").unwrap()),
|
||||
"'{\"f\": \"asd\"}'"),
|
||||
(None, "NULL")])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_jsonb_params() {
|
||||
test_type("JSONB", &[(Some(serde_json::from_str::<Value>("[10, 11, 12]").unwrap()),
|
||||
"'[10, 11, 12]'"),
|
||||
(Some(serde_json::from_str::<Value>("{\"f\": \"asd\"}").unwrap()),
|
||||
"'{\"f\": \"asd\"}'"),
|
||||
(None, "NULL")])
|
||||
}
|
Loading…
Reference in New Issue
Block a user