Move types out to postgres-shared

This commit is contained in:
Steven Fackler 2016-12-21 08:14:24 -08:00
parent e675ee71c5
commit d08dc136bc
20 changed files with 48 additions and 41 deletions

View File

@ -9,7 +9,7 @@ mod sqlstate;
mod type_gen; mod type_gen;
fn main() { fn main() {
let path = Path::new(".."); let path = Path::new("../postgres-shared/src");
sqlstate::build(path); sqlstate::build(path);
type_gen::build(path); type_gen::build(path);
} }

View File

@ -13,7 +13,7 @@ struct Code {
} }
pub fn build(path: &Path) { pub fn build(path: &Path) {
let mut file = BufWriter::new(File::create(path.join("postgres-shared/src/error/sqlstate.rs")).unwrap()); let mut file = BufWriter::new(File::create(path.join("error/sqlstate.rs")).unwrap());
let codes = parse_codes(); let codes = parse_codes();

View File

@ -20,7 +20,7 @@ struct Type {
} }
pub fn build(path: &Path) { pub fn build(path: &Path) {
let mut file = BufWriter::new(File::create(path.join("postgres/src/types/type_gen.rs")).unwrap()); let mut file = BufWriter::new(File::create(path.join("types/type_gen.rs")).unwrap());
let ranges = parse_ranges(); let ranges = parse_ranges();
let types = parse_types(&ranges); let types = parse_types(&ranges);

View File

@ -3,8 +3,23 @@ name = "postgres-shared"
version = "0.1.0" version = "0.1.0"
authors = ["Steven Fackler <sfackler@gmail.com>"] authors = ["Steven Fackler <sfackler@gmail.com>"]
[features]
with-bit-vec = ["bit-vec"]
with-chrono = ["chrono"]
with-eui48 = ["eui48"]
with-serde_json = ["serde_json"]
with-time = ["time"]
with-uuid = ["uuid"]
[dependencies] [dependencies]
hex = "0.2" hex = "0.2"
fallible-iterator = "0.1.3" fallible-iterator = "0.1.3"
phf = "=0.7.20" phf = "=0.7.20"
postgres-protocol = "0.2" postgres-protocol = "0.2"
bit-vec = { version = "0.4", optional = true }
chrono = { version = "0.2.14", optional = true }
eui48 = { version = "0.1", optional = true }
serde_json = { version = ">= 0.6, < 0.9", optional = true }
time = { version = "0.1.14", optional = true }
uuid = { version = ">= 0.1, < 0.4", optional = true }

View File

@ -10,6 +10,7 @@ use std::ops::Range;
pub mod error; pub mod error;
pub mod params; pub mod params;
pub mod types;
pub struct RowData { pub struct RowData {
buf: Vec<u8>, buf: Vec<u8>,

View File

@ -1,5 +1,3 @@
//! Traits dealing with Postgres data types
use fallible_iterator::FallibleIterator; use fallible_iterator::FallibleIterator;
use postgres_protocol; use postgres_protocol;
use postgres_protocol::types::{self, ArrayDimension}; use postgres_protocol::types::{self, ArrayDimension};
@ -13,7 +11,6 @@ pub use postgres_protocol::Oid;
pub use self::type_gen::Type; pub use self::type_gen::Type;
pub use self::special::{Date, Timestamp}; pub use self::special::{Date, Timestamp};
use {SessionInfoNew, OtherNew, WrongTypeNew, FieldNew};
/// Generates a simple implementation of `ToSql::accepts` which accepts the /// Generates a simple implementation of `ToSql::accepts` which accepts the
/// types passed to it. /// types passed to it.
@ -88,8 +85,9 @@ pub struct SessionInfo<'a> {
parameters: &'a HashMap<String, String>, parameters: &'a HashMap<String, String>,
} }
impl<'a> SessionInfoNew<'a> for SessionInfo<'a> { impl<'a> SessionInfo<'a> {
fn new(parameters: &'a HashMap<String, String>) -> SessionInfo<'a> { #[doc(hidden)]
pub fn new(parameters: &'a HashMap<String, String>) -> SessionInfo<'a> {
SessionInfo { parameters: parameters } SessionInfo { parameters: parameters }
} }
} }
@ -142,8 +140,9 @@ impl Field {
} }
} }
impl FieldNew for Field { impl Field {
fn new(name: String, type_: Type) -> Field { #[doc(hidden)]
pub fn new(name: String, type_: Type) -> Field {
Field { Field {
name: name, name: name,
type_: type_, type_: type_,
@ -174,8 +173,9 @@ struct OtherInner {
schema: String, schema: String,
} }
impl OtherNew for Other { impl Other {
fn new(name: String, oid: Oid, kind: Kind, schema: String) -> Other { #[doc(hidden)]
pub fn new(name: String, oid: Oid, kind: Kind, schema: String) -> Other {
Other(Arc::new(OtherInner { Other(Arc::new(OtherInner {
name: name, name: name,
oid: oid, oid: oid,
@ -243,8 +243,9 @@ impl Error for WrongType {
} }
} }
impl WrongTypeNew for WrongType { impl WrongType {
fn new(ty: Type) -> WrongType { #[doc(hidden)]
pub fn new(ty: Type) -> WrongType {
WrongType(ty) WrongType(ty)
} }
} }

View File

@ -21,17 +21,18 @@ name = "test"
path = "tests/test.rs" path = "tests/test.rs"
[features] [features]
with-bit-vec = ["bit-vec"] with-bit-vec = ["postgres-shared/with-bit-vec"]
with-chrono = ["chrono"] with-chrono = ["postgres-shared/with-chrono"]
with-eui48 = ["eui48"] with-eui48 = ["postgres-shared/with-eui48"]
with-serde_json = ["postgres-shared/with-serde_json"]
with-time = ["postgres-shared/time"]
with-uuid = ["postgres-shared/with-uuid"]
with-openssl = ["openssl"] with-openssl = ["openssl"]
with-native-tls = ["native-tls"] with-native-tls = ["native-tls"]
with-rustc-serialize = ["rustc-serialize"] with-rustc-serialize = ["rustc-serialize"]
with-schannel = ["schannel"] with-schannel = ["schannel"]
with-security-framework = ["security-framework"] with-security-framework = ["security-framework"]
with-serde_json = ["serde_json"]
with-time = ["time"]
with-uuid = ["uuid"]
no-logging = [] no-logging = []
@ -41,17 +42,12 @@ fallible-iterator = "0.1.3"
hex = "0.2" hex = "0.2"
log = "0.3" log = "0.3"
postgres-protocol = "0.2" postgres-protocol = "0.2"
bit-vec = { version = "0.4", optional = true }
chrono = { version = "0.2.14", optional = true }
eui48 = { version = "0.1", optional = true }
openssl = { version = "0.9", optional = true } openssl = { version = "0.9", optional = true }
native-tls = { version = "0.1", optional = true } native-tls = { version = "0.1", optional = true }
rustc-serialize = { version = "0.3", optional = true } rustc-serialize = { version = "0.3", optional = true }
schannel = { version = "0.1", optional = true } schannel = { version = "0.1", optional = true }
security-framework = { version = "0.1.2", optional = true } security-framework = { version = "0.1.2", optional = true }
serde_json = { version = ">= 0.6, < 0.9", optional = true }
time = { version = "0.1.14", optional = true }
uuid = { version = ">= 0.1, < 0.4", optional = true }
postgres-shared = { path = "../postgres-shared" } postgres-shared = { path = "../postgres-shared" }

View File

@ -77,6 +77,8 @@ extern crate hex;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
extern crate postgres_protocol; extern crate postgres_protocol;
#[macro_use]
#[macro_export]
extern crate postgres_shared; extern crate postgres_shared;
use fallible_iterator::FallibleIterator; use fallible_iterator::FallibleIterator;
@ -101,7 +103,7 @@ use priv_io::MessageStream;
use rows::{Rows, LazyRows}; use rows::{Rows, LazyRows};
use stmt::{Statement, Column}; use stmt::{Statement, Column};
use transaction::{Transaction, IsolationLevel}; use transaction::{Transaction, IsolationLevel};
use types::{IsNull, Kind, Type, SessionInfo, Oid, Other, WrongType, ToSql, FromSql, Field}; use types::{IsNull, Kind, Type, SessionInfo, Oid, Other, ToSql, FromSql, Field};
#[macro_use] #[macro_use]
mod macros; mod macros;
@ -1360,10 +1362,6 @@ trait LazyRowsNew<'trans, 'stmt> {
-> LazyRows<'trans, 'stmt>; -> LazyRows<'trans, 'stmt>;
} }
trait SessionInfoNew<'a> {
fn new(params: &'a HashMap<String, String>) -> SessionInfo<'a>;
}
trait StatementInternals<'conn> { trait StatementInternals<'conn> {
fn new(conn: &'conn Connection, fn new(conn: &'conn Connection,
info: Arc<StatementInfo>, info: Arc<StatementInfo>,
@ -1384,14 +1382,6 @@ trait NotificationsNew<'conn> {
fn new(conn: &'conn Connection) -> Notifications<'conn>; fn new(conn: &'conn Connection) -> Notifications<'conn>;
} }
trait WrongTypeNew {
fn new(ty: Type) -> WrongType;
}
trait FieldNew {
fn new(name: String, type_: Type) -> Field;
}
trait TransactionInternals<'conn> { trait TransactionInternals<'conn> {
fn new(conn: &'conn Connection, depth: u32) -> Transaction<'conn>; fn new(conn: &'conn Connection, depth: u32) -> Transaction<'conn>;

View File

@ -10,7 +10,7 @@ use std::io;
use std::ops::Deref; use std::ops::Deref;
use std::slice; use std::slice;
use {Result, SessionInfoNew, RowsNew, LazyRowsNew, StatementInternals, WrongTypeNew}; use {Result, RowsNew, LazyRowsNew, StatementInternals};
use transaction::Transaction; use transaction::Transaction;
use types::{FromSql, SessionInfo, WrongType}; use types::{FromSql, SessionInfo, WrongType};
use stmt::{Statement, Column}; use stmt::{Statement, Column};

View File

@ -14,7 +14,7 @@ use types::{SessionInfo, Type, ToSql};
use rows::{Rows, LazyRows}; use rows::{Rows, LazyRows};
use transaction::Transaction; use transaction::Transaction;
use {bad_response, err, Connection, StatementInternals, Result, RowsNew, InnerConnection, use {bad_response, err, Connection, StatementInternals, Result, RowsNew, InnerConnection,
SessionInfoNew, LazyRowsNew, ColumnNew, StatementInfo, TransactionInternals}; LazyRowsNew, ColumnNew, StatementInfo, TransactionInternals};
/// A prepared statement. /// A prepared statement.
pub struct Statement<'conn> { pub struct Statement<'conn> {

4
postgres/src/types.rs Normal file
View File

@ -0,0 +1,4 @@
//! Traits dealing with Postgres data types
#[doc(inline)]
pub use postgres_shared::types::*;