diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1d9198c..6dc2f4b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,6 +80,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions-rs/toolchain@v1 with: - toolchain: "1.67" + toolchain: "1.72" override: true + - run: cargo build --no-default-features - run: cargo build --all-features diff --git a/.gitignore b/.gitignore index 0258b71..426ae82 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ tests-integration/test-server/target tests-integration/rust-client/target node_modules +.DS_Store \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 91c03db..eadf6fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,31 +11,55 @@ homepage = "https://github.com/sunng87/pgwire" repository = "https://github.com/sunng87/pgwire" documentation = "https://docs.rs/crate/pgwire/" readme = "README.md" -rust-version = "1.67" +rust-version = "1.72" [dependencies] -log = "0.4" derive-new = "0.6" bytes = "1.1.0" -time = "0.3" -futures = "0.3" -async-trait = "0.1" -rand = "0.8" thiserror = "1" -postgres-types = { version = "0.2", features = ["with-chrono-0_4", "array-impls"]} -md5 = "0.7" -hex = "0.4" -## scram libraries -base64 = "0.22" -ring = "0.17" -stringprep = "0.1.2" -x509-certificate = "0.23" - -tokio = { version = "1.19", features = ["net", "rt", "io-util"], optional = true} +## api +tokio = { version = "1.19", features = [ + "net", + "rt", + "io-util", +], optional = true } tokio-util = { version = "0.7.3", features = ["codec", "io"], optional = true } tokio-rustls = { version = "0.26", optional = true } +futures = { version = "0.3", optional = true } +async-trait = { version = "0.1", optional = true } +rand = { version = "0.8", optional = true } +md5 = { version = "0.7", optional = true } +hex = { version = "0.4", optional = true } +## scram libraries +base64 = { version = "0.22", optional = true } +ring = { version = "0.17", optional = true } +stringprep = { version = "0.1.2", optional = true } +x509-certificate = { version = "0.23", optional = true } +## types +postgres-types = { version = "0.2", features = [ + "with-chrono-0_4", + "array-impls", +], optional = true } +chrono = { version = "0.4", features = ["std"], optional = true } -chrono = { version = "0.4", optional = true, features = ["std"] } +[features] +default = ["api"] +api = [ + "dep:tokio", + "dep:tokio-util", + "dep:tokio-rustls", + "dep:futures", + "dep:async-trait", + "dep:rand", + "dep:md5", + "dep:hex", + "dep:base64", + "dep:ring", + "dep:stringprep", + "dep:x509-certificate", + "dep:postgres-types", + "dep:chrono", +] [dev-dependencies] tokio = { version = "1.19", features = ["rt-multi-thread", "net", "macros"]} @@ -50,15 +74,6 @@ rustls-pki-types = "1.0" ## rustls-native-certs loads roots from current system gluesql = { version = "0.15", default-features = false, features = ["memory-storage"] } -[features] -default = ["tokio", "time-format"] -tokio = ["dep:tokio", "dep:tokio-util", "dep:tokio-rustls"] -time-format = ["dep:chrono"] - -[[example]] -name = "server" -required-features = ["tokio"] - [workspace] members = [ ".", diff --git a/src/error.rs b/src/error.rs index f8dd460..77e1e47 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,10 +1,7 @@ +use crate::messages::response::{ErrorResponse, NoticeResponse}; use std::io::{Error as IOError, ErrorKind}; - -use postgres_types::Oid; use thiserror::Error; -use crate::messages::response::{ErrorResponse, NoticeResponse}; - #[derive(Error, Debug)] pub enum PgWireError { #[error("Invalid protocol version, received {0}")] @@ -23,8 +20,6 @@ pub enum PgWireError { PortalNotFound(String), #[error("Statement not found for name: {0:?}")] StatementNotFound(String), - #[error("Unknown type: {0:?}")] - UnknownTypeId(Oid), #[error("Parameter index out of bound: {0:?}")] ParameterIndexOutOfBound(usize), #[error("Cannot convert postgre type {0:?} to given rust type")] diff --git a/src/lib.rs b/src/lib.rs index 77697cb..cab2d9c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,13 +57,15 @@ extern crate derive_new; /// handler layer and high-level API layer. +#[cfg(feature = "api")] pub mod api; /// error types. pub mod error; /// the protocol layer. pub mod messages; /// server entry-point for tokio based application. -#[cfg(feature = "tokio")] +#[cfg(feature = "api")] pub mod tokio; /// types and encoding related helper +#[cfg(feature = "api")] pub mod types; diff --git a/src/messages/data.rs b/src/messages/data.rs index 1a01b8f..828ab63 100644 --- a/src/messages/data.rs +++ b/src/messages/data.rs @@ -1,12 +1,11 @@ use bytes::{Buf, BufMut, BytesMut}; -use postgres_types::Oid; use super::codec; use super::Message; use crate::error::PgWireResult; -pub(crate) const FORMAT_CODE_TEXT: i16 = 0; -pub(crate) const FORMAT_CODE_BINARY: i16 = 1; +pub const FORMAT_CODE_TEXT: i16 = 0; +pub const FORMAT_CODE_BINARY: i16 = 1; #[non_exhaustive] #[derive(PartialEq, Eq, Debug, Default, new)] @@ -18,7 +17,7 @@ pub struct FieldDescription { // the attribute number of the column, default to 0 if not a column from table pub column_id: i16, // the object ID of the data type - pub type_id: Oid, + pub type_id: u32, // the size of data type, negative values denote variable-width types pub type_size: i16, // the type modifier @@ -92,7 +91,7 @@ impl Message for RowDescription { #[derive(PartialEq, Eq, Debug, Default, new, Clone)] pub struct ParameterDescription { /// parameter types - pub types: Vec, + pub types: Vec, } pub const MESSAGE_TYPE_BYTE_PARAMETER_DESCRITION: u8 = b't'; @@ -121,7 +120,7 @@ impl Message for ParameterDescription { let mut types = Vec::with_capacity(types_len as usize); for _ in 0..types_len { - types.push(buf.get_i32() as Oid); + types.push(buf.get_i32() as u32); } Ok(ParameterDescription { types }) diff --git a/src/messages/extendedquery.rs b/src/messages/extendedquery.rs index 25dcfdd..fa8c6e0 100644 --- a/src/messages/extendedquery.rs +++ b/src/messages/extendedquery.rs @@ -1,5 +1,4 @@ use bytes::{Buf, BufMut, Bytes}; -use postgres_types::Oid; use super::{codec, Message}; use crate::error::PgWireResult; @@ -10,7 +9,7 @@ use crate::error::PgWireResult; pub struct Parse { pub name: Option, pub query: String, - pub type_oids: Vec, + pub type_oids: Vec, } pub const MESSAGE_TYPE_BYTE_PARSE: u8 = b'P';