Skip to content

Commit

Permalink
Split api feature (#177)
Browse files Browse the repository at this point in the history
* Split api feature

* Restore rust-client change

* Upgrade rust-version to 1.72

* Remove unused UnknownTypeId

* Add ci task --no-default-features
  • Loading branch information
wyhaya committed Apr 25, 2024
1 parent 32ddf49 commit ebfe5aa
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 42 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
tests-integration/test-server/target
tests-integration/rust-client/target
node_modules
.DS_Store
67 changes: 41 additions & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}
Expand All @@ -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 = [
".",
Expand Down
7 changes: 1 addition & 6 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -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}")]
Expand All @@ -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")]
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
11 changes: 5 additions & 6 deletions src/messages/data.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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
Expand Down Expand Up @@ -92,7 +91,7 @@ impl Message for RowDescription {
#[derive(PartialEq, Eq, Debug, Default, new, Clone)]
pub struct ParameterDescription {
/// parameter types
pub types: Vec<Oid>,
pub types: Vec<u32>,
}

pub const MESSAGE_TYPE_BYTE_PARAMETER_DESCRITION: u8 = b't';
Expand Down Expand Up @@ -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 })
Expand Down
3 changes: 1 addition & 2 deletions src/messages/extendedquery.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use bytes::{Buf, BufMut, Bytes};
use postgres_types::Oid;

use super::{codec, Message};
use crate::error::PgWireResult;
Expand All @@ -10,7 +9,7 @@ use crate::error::PgWireResult;
pub struct Parse {
pub name: Option<String>,
pub query: String,
pub type_oids: Vec<Oid>,
pub type_oids: Vec<u32>,
}

pub const MESSAGE_TYPE_BYTE_PARSE: u8 = b'P';
Expand Down

0 comments on commit ebfe5aa

Please sign in to comment.