Skip to content

Commit 0a526c7

Browse files
authored
Merge pull request #11 from skytable/pool
Implement connection pooling
2 parents 6aa409f + 1b202fb commit 0a526c7

File tree

14 files changed

+504
-109
lines changed

14 files changed

+504
-109
lines changed

.github/workflows/release.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Publish crate
2+
on: [release]
3+
4+
jobs:
5+
publish:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v2
9+
- name: Publish
10+
run: |
11+
cargo login ${{ secrets.CARGO_TOKEN }}
12+
cargo publish

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ jobs:
1616
cargo build --verbose --no-default-features --features sync
1717
cargo build --verbose --no-default-features --features sync,ssl
1818
cargo build --verbose --no-default-features --features sync,sslv
19-
cargo build --verbose --no-default-features --features async
20-
cargo build --verbose --no-default-features --features async,aio-ssl
21-
cargo build --verbose --no-default-features --features async,aio-sslv
19+
cargo build --verbose --no-default-features --features aio
20+
cargo build --verbose --no-default-features --features aio,aio-ssl
21+
cargo build --verbose --no-default-features --features aio,aio-sslv
2222
cargo build --verbose --no-default-features --features dbg
2323
cargo build --verbose --no-default-features --features const-gen
2424
- name: Run tests

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Cargo.lock
33
.vscode
44
.DS_Store
55
examples/target
6+
scripts

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
All changes in this project will be noted in this file.
44

5-
## Unreleased
5+
## 0.7.0
6+
7+
### New features
8+
9+
- Sync connection pooling
10+
- Async connection pooling
611

712
### Breaking changes
813

914
- `SkyRawResult` is now `SkyResult`
1015
- `SkyResult` is now `SkyQueryResult`
16+
- The feature `async` is now `aio`
1117

1218
## Version 0.6.2
1319

Cargo.toml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,27 @@ license = "Apache-2.0"
99
name = "skytable"
1010
readme = "README.md"
1111
repository = "https://github.com/skytable/client-rust"
12-
version = "0.6.2"
12+
version = "0.6.3"
1313

1414
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1515

1616
[features]
17+
default = ["sync"]
18+
# sync
19+
sync = ["pool"]
20+
pool = ["r2d2"]
21+
# sync TLS
22+
ssl = ["openssl"]
23+
sslv = ["openssl/vendored"]
24+
# async
25+
aio = ["bytes", "tokio", "aio-pool"]
26+
aio-pool = ["bb8", "async-trait"]
27+
# async TLS
1728
aio-ssl = ["tokio-openssl", "openssl"]
1829
aio-sslv = ["tokio-openssl", "openssl/vendored"]
19-
async = ["bytes", "tokio"]
30+
# utilities
2031
const-gen = []
2132
dbg = []
22-
default = ["sync"]
23-
ssl = ["openssl"]
24-
sslv = ["openssl/vendored"]
25-
sync = []
2633

2734
[dependencies]
2835
bytes = { version = "1.1.0", optional = true }
@@ -33,6 +40,13 @@ tokio = { version = "1.15.0", features = [
3340
"io-std",
3441
], optional = true }
3542
tokio-openssl = { version = "0.6.3", optional = true }
43+
r2d2 = { version = "0.8.9", optional = true }
44+
bb8 = { version = "0.7.1", optional = true }
45+
async-trait = { version = "0.1.52", optional = true }
46+
47+
[dev-dependencies]
48+
tokio = { version = "1.16.1", features = ["test-util", "macros"] }
49+
3650
[package.metadata.docs.rs]
3751
all-features = true
3852
rustdoc-args = ["--cfg", "docsrs"]

README.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ This library is the official client for the free and open-source NoSQL database
77
following the instructions [here](https://docs.skytable.io/getting-started). This library supports
88
all Skytable versions that work with the [Skyhash 1.1 Protocol](https://docs.skytable.io/protocol/skyhash).
99
This version of the library was tested with the latest Skytable release
10-
(release [0.7.2-alpha.1](https://github.com/skytable/skytable/releases/v0.7.2-alpha.1)).
10+
(release [0.7.2](https://github.com/skytable/skytable/releases/v0.7.2)).
11+
12+
## Features
13+
14+
- Sync API
15+
- Async API
16+
- TLS in both sync/async APIs
17+
- Connection pooling for sync/async
18+
- Use both sync/async APIs at the same time
19+
- Always up-to-date
1120

1221
## Using this library
1322

@@ -26,7 +35,7 @@ cargo new skyapp
2635
First add this to your `Cargo.toml` file:
2736

2837
```toml
29-
skytable = "0.6.2"
38+
skytable = "0.6.3"
3039
```
3140

3241
Now open up your `src/main.rs` file and establish a connection to the server while also adding some
@@ -88,7 +97,7 @@ Way to go — you're all set! Now go ahead and run more advanced queries!
8897

8998
The `default:default` keyspace has the following declaration:
9099

91-
```
100+
```text
92101
Keymap { data:(binstr,binstr), volatile:false }
93102
```
94103

@@ -108,17 +117,22 @@ assert!(con.set("bindata", mybinarydata).unwrap());
108117

109118
## Going advanced
110119

111-
Now that you know how you can run basic queries, check out the `actions` module documentation for learning
112-
to use actions and the `types` module documentation for implementing your own Skyhash serializable
113-
types. Need to meddle with DDL queries like creating and dropping tables? Check out the `ddl` module.
114-
You can also find the [latest examples here](https://github.com/skytable/client-rust/tree/next/examples)
120+
Now that you know how you can run basic queries, check out the [`actions`] module documentation for learning
121+
to use actions and the [`types`] module documentation for implementing your own Skyhash serializable
122+
types. Need to meddle with DDL queries like creating and dropping tables? Check out the [`ddl`] module.
123+
You can also find some [examples here](https://github.com/skytable/client-rust/tree/v0.7.0-alpha.1/examples)
124+
125+
## Connection pooling
126+
127+
This library supports using sync/async connection pools. See the [`pool`] module-level documentation for examples
128+
and information.
115129

116130
## Async API
117131

118132
If you need to use an `async` API, just change your import to:
119133

120134
```toml
121-
skytable = { version = "0.6.2", features=["async"], default-features = false }
135+
skytable = { version = "0.6.3", features=["aio"], default-features = false }
122136
```
123137

124138
You can now establish a connection by using `skytable::AsyncConnection::new()`, adding `.await`s wherever
@@ -130,7 +144,7 @@ With this client driver, it is possible to use both sync and `async` APIs **at t
130144
this, simply change your import to:
131145

132146
```toml
133-
skytable = { version="0.6.2", features=["sync", "async"] }
147+
skytable = { version="0.6.3", features=["sync", "aio"] }
134148
```
135149

136150
## TLS
@@ -140,15 +154,15 @@ If you need to use TLS features, this crate will let you do so with OpenSSL.
140154
### Using TLS with sync interfaces
141155

142156
```toml
143-
skytable = { version="0.6.2", features=["sync","ssl"] }
157+
skytable = { version="0.6.3", features=["sync","ssl"] }
144158
```
145159

146160
You can now use the async `sync::TlsConnection` object.
147161

148162
### Using TLS with async interfaces
149163

150164
```toml
151-
skytable = { version="0.6.2", features=["async","aio-ssl"], default-features=false }
165+
skytable = { version="0.6.3", features=["aio","aio-ssl"], default-features=false }
152166
```
153167

154168
You can now use the async `aio::TlsConnection` object.

examples/aio/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ edition = "2018"
88
[dependencies]
99
skytable = { git="https://github.com/skytable/client-rust.git", features = [
1010
"const-gen",
11-
"async",
11+
"aio",
1212
], default-features = false }
1313
tokio = { version = "1.10.0", features = ["full"] }

src/actions.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,10 @@ use crate::SkyQueryResult;
5252
use crate::SkyResult;
5353

5454
cfg_async!(
55-
use core::{future::Future, pin::Pin};
55+
use crate::AsyncResult;
5656
);
5757

5858
cfg_async!(
59-
/// A special result that is returned when running actions (async)
60-
pub type AsyncResult<'s, T> = Pin<Box<dyn Future<Output = T> + Send + Sync + 's>>;
6159
#[doc(hidden)]
6260
/// A raw async connection to the database server
6361
pub trait AsyncSocket: Send + Sync {
@@ -111,8 +109,8 @@ macro_rules! implement_actions {
111109
}
112110
)*
113111
}
114-
#[cfg(feature = "async")]
115-
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
112+
#[cfg(feature = "aio")]
113+
#[cfg_attr(docsrs, doc(cfg(feature = "aio")))]
116114
/// Actions that can be run on an [`AsyncSocket`] connection
117115
pub trait AsyncActions: AsyncSocket {
118116
$(

src/aio.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
//!
2626
2727
use crate::deserializer::{ParseError, Parser, RawResponse};
28-
use crate::error::Error;
2928
use crate::error::SkyhashError;
3029
use crate::Element;
3130
use crate::IoResult;
@@ -110,7 +109,7 @@ macro_rules! impl_async_methods {
110109
}
111110
}
112111
impl crate::actions::AsyncSocket for $ty {
113-
fn run(&mut self, q: Query) -> crate::actions::AsyncResult<SkyQueryResult> {
112+
fn run(&mut self, q: Query) -> crate::AsyncResult<SkyQueryResult> {
114113
Box::pin(async move { self.run_simple_query(&q).await })
115114
}
116115
}
@@ -141,6 +140,7 @@ cfg_async_ssl_any!(
141140
use tokio_openssl::SslStream;
142141
use openssl::ssl::{SslContext, SslMethod, Ssl};
143142
use core::pin::Pin;
143+
use crate::error::Error;
144144

145145
/// An asynchronous database connection over Skyhash/TLS
146146
pub struct TlsConnection {

src/ddl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use crate::RespCode;
4343
use crate::SkyResult;
4444

4545
cfg_async! {
46-
use crate::actions::AsyncResult;
46+
use crate::AsyncResult;
4747
use crate::actions::AsyncSocket;
4848
}
4949

@@ -187,8 +187,8 @@ macro_rules! implement_ddl {
187187
}
188188
)*
189189
}
190-
#[cfg(feature = "async")]
191-
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
190+
#[cfg(feature = "aio")]
191+
#[cfg_attr(docsrs, doc(cfg(feature = "aio")))]
192192
/// [DDL queries](https://docs.skytable.io/ddl) that can be run on async socket
193193
/// connections
194194
pub trait AsyncDdl: AsyncSocket {

0 commit comments

Comments
 (0)