Skip to content

Commit 3d665fa

Browse files
authored
Merge pull request #65 from weiznich/update_main_to_contain_0.2
Update main to contain 0.2
2 parents 8d08575 + 8f0ccde commit 3d665fa

File tree

4 files changed

+209
-10
lines changed

4 files changed

+209
-10
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- 0.2.x
78

89
name: CI Tests
910

@@ -142,3 +143,23 @@ jobs:
142143

143144
- name: Check formating
144145
run: cargo +stable fmt --all -- --check
146+
minimal_rust_version:
147+
name: Check Minimal supported rust version (1.65.0)
148+
runs-on: ubuntu-latest
149+
steps:
150+
- uses: actions/checkout@v3
151+
- uses: dtolnay/[email protected]
152+
- uses: dtolnay/rust-toolchain@nightly
153+
- uses: taiki-e/install-action@cargo-hack
154+
- uses: taiki-e/install-action@cargo-minimal-versions
155+
- name: Cache cargo registry
156+
uses: actions/cache@v2
157+
with:
158+
path: |
159+
~/.cargo/registry
160+
~/.cargo/git
161+
key: minimal_rust_version-cargo-${{ hashFiles('**/Cargo.toml') }}
162+
- name: Check diesel_derives
163+
# cannot test mysql yet as that crate
164+
# has broken min-version dependencies
165+
run: cargo +stable minimal-versions check -p diesel-async --features "postgres bb8 deadpool mobc"

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All user visible changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/), as described
55
for Rust libraries in [RFC #1105](https://github.com/rust-lang/rfcs/blob/master/text/1105-api-evolution.md)
66

7+
## [0.2.1] - 2023-03-08
8+
9+
* Dependency updates for `mobc` and `mysql-async` to allow newer versions as well
10+
* Extend the README
11+
* Improve the version constraint for diesel so that we do not end up using a newer
12+
diesel version that's incompatible
13+
714
## [0.2.0] - 2022-12-16
815

916
* [#38](https://github.com/weiznich/diesel_async/pull/38) Relax the requirements for borrowed captures in the transaction closure

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "diesel-async"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
authors = ["Georg Semmler <[email protected]>"]
55
edition = "2018"
66
autotests = false
@@ -10,21 +10,21 @@ repository = "https://github.com/weiznich/diesel_async"
1010
keywords = ["orm", "database", "sql", "async"]
1111
categories = ["database"]
1212
description = "An async extension for Diesel the safe, extensible ORM and Query Builder"
13-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
13+
rust-version = "1.65.0"
1414

1515
[dependencies]
16-
diesel = { version = "2.0.0", default-features = false, features = ["i-implement-a-third-party-backend-and-opt-into-breaking-changes"]}
17-
async-trait = "0.1.51"
16+
diesel = { version = "~2.0.0", default-features = false, features = ["i-implement-a-third-party-backend-and-opt-into-breaking-changes"]}
17+
async-trait = "0.1.66"
1818
futures-channel = { version = "0.3.17", default-features = false, features = ["std", "sink"], optional = true }
1919
futures-util = { version = "0.3.17", default-features = false, features = ["std", "sink"] }
2020
tokio-postgres = { version = "0.7.2", optional = true}
21-
tokio = { version = "1", optional = true}
22-
mysql_async = { version = "0.30.0", optional = true}
21+
tokio = { version = "1.26", optional = true}
22+
mysql_async = { version = ">=0.30.0,<0.32", optional = true}
2323
mysql_common = {version = "0.29.0", optional = true}
2424

2525
bb8 = {version = "0.8", optional = true}
2626
deadpool = {version = "0.9", optional = true}
27-
mobc = {version = "0.7", optional = true}
27+
mobc = {version = ">=0.7,<0.9", optional = true}
2828
scoped-futures = {version = "0.1", features = ["std"]}
2929

3030
[dev-dependencies]
@@ -50,4 +50,4 @@ rustc-args = ["--cfg", "doc_cfg"]
5050
rustdoc-args = ["--cfg", "doc_cfg"]
5151

5252
[patch.crates-io]
53-
diesel = { git = "https://github.com/diesel-rs/diesel", rev = "88129db" }
53+
diesel = { git = "https://github.com/diesel-rs/diesel", rev = "b878fed" }

README.md

Lines changed: 173 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,180 @@ Rust's type system to create a low overhead query builder that "feels like
66
Rust."
77

88
Diesel-async provides an async implementation of diesels connection implementation
9-
and any method that may issue an query. It is designed as pure async drop in replacement
10-
for the corresponding diesel methods.
9+
and any method that may issue an query. It is designed as pure async drop-in replacement
10+
for the corresponding diesel methods. Similar to diesel the crate is designed in a way
11+
that allows third party crates to extend the existing infrastructure and even provide
12+
their own connection implementations.
1113

1214
Supported databases:
15+
1316
1. PostgreSQL
1417
2. MySQL
1518

19+
## Usage
20+
21+
### Simple usage
22+
23+
Diesel-async is designed to work in combination with diesel, not to replace diesel. For this it
24+
provides drop-in replacement for diesel functionality that actually interacts with the database.
25+
26+
A normal project should use a setup similar to the following one:
27+
28+
```toml
29+
[dependencies]
30+
diesel = "2.0.3" # no backend features need to be enabled
31+
diesel-async = { version = "0.2.1", features = ["postgres"] }
32+
```
33+
34+
This allows to import the relevant traits from both crates:
35+
36+
```rust
37+
use diesel::prelude::*;
38+
use diesel_async::{RunQueryDsl, AsyncConnection, AsyncPgConnection};
39+
40+
// ordinary diesel model setup
41+
42+
table! {
43+
users {
44+
id -> Integer,
45+
name -> Text,
46+
}
47+
}
48+
49+
#[derive(Queryable, Selectable)]
50+
#[diesel(table_name = users)]
51+
struct User {
52+
id: i32,
53+
name: Text,
54+
}
55+
56+
// create an async connection
57+
let mut connection = AsyncPgConnection::establish(std::env::var("DATABASE_URL")?).await?;
58+
59+
// use ordinary diesel query dsl to construct your query
60+
let data: Vec<User> = users::table
61+
.filter(users::id.gt(0))
62+
.or_filter(users::name.like("%Luke"))
63+
.select(User::as_select())
64+
// execute the query via the provided
65+
// async `diesel_async::RunQueryDsl`
66+
.load(&mut connection)
67+
.await?;
68+
```
69+
70+
### Async Transaction Support
71+
72+
Diesel-async provides an ergonomic interface to wrap several statements into a shared
73+
database transaction. Such transactions are automatically rolled back as soon as
74+
the inner closure returns an error
75+
76+
``` rust
77+
connection.transaction::<_, diesel::result::Error, _>(|conn| async move {
78+
diesel::insert_into(users::table)
79+
.values(users::name.eq("Ruby"))
80+
.execute(conn)
81+
.await?;
82+
83+
let all_names = users::table.select(users::name).load::<String>(conn).await?;
84+
Ok(())
85+
}.scope_boxed()
86+
).await?;
87+
```
88+
89+
### Streaming Query Support
90+
91+
Beside loading data directly into a vector, diesel-async also supports returning a
92+
value stream for each query. This allows to process data from the database while they
93+
are still received.
94+
95+
```rust
96+
// use ordinary diesel query dsl to construct your query
97+
let data: impl Stream<Item = QueryResult<User>> = users::table
98+
.filter(users::id.gt(0))
99+
.or_filter(users::name.like("%Luke"))
100+
.select(User::as_select())
101+
// execute the query via the provided
102+
// async `diesel_async::RunQueryDsl`
103+
.load_stream(&mut connection)
104+
.await?;
105+
106+
```
107+
108+
### Built-in Connection Pooling Support
109+
110+
Diesel-async provides built-in support for several connection pooling crates. This includes support
111+
for:
112+
113+
* [deadpool](https://crates.io/crates/deadpool)
114+
* [bb8](https://crates.io/crates/bb8)
115+
* [mobc](https://crates.io/crates/mobc)
116+
117+
#### Deadpool
118+
119+
``` rust
120+
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
121+
use diesel_async::pooled_connection::deadpool::Pool;
122+
use diesel_async::RunQueryDsl;
123+
124+
// create a new connection pool with the default config
125+
let config = AsyncDieselConnectionManager::<diesel_async::AsyncPgConnection>::new(std::env::var("DATABASE_URL")?);
126+
let pool = Pool::builder().build(config)?;
127+
128+
// checkout a connection from the pool
129+
let mut conn = pool.get().await?;
130+
131+
// use the connection as ordinary diesel-async connection
132+
let res = users::table.select(User::as_select()).load::(&mut conn).await?;
133+
```
134+
135+
#### BB8
136+
137+
``` rust
138+
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
139+
use diesel_async::pooled_connection::bb8::Pool;
140+
use diesel_async::RunQueryDsl;
141+
142+
// create a new connection pool with the default config
143+
let config = AsyncDieselConnectionManager::<diesel_async::AsyncPgConnection>::new(std::env::var("DATABASE_URL")?);
144+
let pool = Pool::builder().build(config).await?;
145+
146+
// checkout a connection from the pool
147+
let mut conn = pool.get().await?;
148+
149+
// use the connection as ordinary diesel-async connection
150+
let res = users::table.select(User::as_select()).load::(&mut conn).await?;
151+
```
152+
153+
#### Mobc
154+
155+
``` rust
156+
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
157+
use diesel_async::pooled_connection::mobc::Pool;
158+
use diesel_async::RunQueryDsl;
159+
160+
// create a new connection pool with the default config
161+
let config = AsyncDieselConnectionManager::<diesel_async::AsyncPgConnection>::new(std::env::var("DATABASE_URL")?);
162+
let pool = Pool::new(config);
163+
164+
// checkout a connection from the pool
165+
let mut conn = pool.get().await?;
166+
167+
// use the connection as ordinary diesel-async connection
168+
let res = users::table.select(User::as_select()).load::(&mut conn).await?;
169+
```
170+
171+
## Crate Feature Flags
172+
173+
Diesel-async offers several configurable features:
174+
175+
* `postgres`: Enables the implementation of `AsyncPgConnection`
176+
* `mysql`: Enables the implementation of `AsyncMysqlConnection`
177+
* `deadpool`: Enables support for the `deadpool` connection pool implementation
178+
* `bb8`: Enables support for the `bb8` connection pool implementation
179+
* `mobc`: Enables support for the `mobc` connection pool implementation
180+
181+
By default no features are enabled.
182+
16183
## Code of conduct
17184

18185
Anyone who interacts with Diesel in any space, including but not limited to
@@ -28,6 +195,10 @@ Licensed under either of these:
28195
https://opensource.org/licenses/MIT)
29196

30197
### Contributing
198+
199+
Contributions are explicitly welcome. Please consider opening a [discussion](https://github.com/weiznich/diesel_async/discussions/categories/ideas)
200+
with your idea first, to discuss possible designs.
201+
31202
Unless you explicitly state otherwise, any contribution you intentionally submit
32203
for inclusion in the work, as defined in the Apache-2.0 license, shall be
33204
dual-licensed as above, without any additional terms or conditions.

0 commit comments

Comments
 (0)