Skip to content

Commit

Permalink
Merge pull request #53 from hackerchai/upgrade-sqlx-0.5
Browse files Browse the repository at this point in the history
Feat: bump version 0.4.0
  • Loading branch information
hackerchai authored Feb 5, 2021
2 parents 31e1140 + d1d4417 commit 15b06cc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
16 changes: 7 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sqlx-adapter"
version = "0.3.0"
version = "0.4.0"
authors = ["Eason Chai <hackerchai.com@gmail.com>","Cheng JIANG <jiang.cheng@vip.163.com>"]
edition = "2018"
license = "Apache-2.0"
Expand All @@ -9,14 +9,13 @@ homepage= "https://github.com/casbin-rs/sqlx-adapter"
readme= "README.md"

[dependencies]
casbin = { version = "=2.0.5", default-features = false }
sqlx = { version = "0.4.2", default-features = false, features = [ "macros" ] }
casbin = { version = "2.0.6", default-features = false }
sqlx = { version = "0.5.1", default-features = false, features = [ "macros" ] }
async-trait = "0.1.42"
dotenv = { version = "0.15.0", default-features = false }
# Force tokio version at 0.2.x until sqlx is updated
tokio = { version = "0.2.24", default-features = false, optional = true }
tokio = { version = "1.1.1", default-features = false, optional = true }
async-std = { version = "1.9.0", default-features = false, optional = true }
actix-rt = { version = "1.1.1", default-features = false, optional = true }
actix-rt = { version = "2.0.0", default-features = false, optional = true }

[features]
default = ["postgres", "runtime-tokio-native-tls", "offline"]
Expand All @@ -41,6 +40,5 @@ offline = ["sqlx/offline"]

[dev-dependencies]
async-std = { version = "1.9.0", features = [ "attributes" ] }
# Force tokio version at 0.2.x until sqlx is updated
tokio = { version = "0.2.24", features = [ "full" ] }
actix-rt = { version = "1.1.1" }
tokio = { version = "1.1.1", features = [ "full" ] }
actix-rt = { version = "2.0.0" }
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ ALTER TABLE casbin_rules RENAME TO casbin_rule;
Add it to `Cargo.toml`

```rust
sqlx-adapter = { version = "0.3.0", features = ["postgres"] }
tokio = "0.2.24"
sqlx-adapter = { version = "0.4.0", features = ["postgres"] }
tokio = "1.1.1"

**Warning**: `tokio v1.0` or later is supported from `sqlx-adapter v0.4.0`, we recommend that you upgrade the relevant components to ensure that they work properly. The last version that supports `tokio v0.2` is `diesel-adapter v0.3.0` , you can choose according to your needs.
```

## Configure
Expand Down
34 changes: 17 additions & 17 deletions src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#![allow(clippy::toplevel_ref_arg)]
use crate::Error;
use casbin::{error::AdapterError, Error as CasbinError, Filter, Result};
use sqlx::{error::Error as SqlxError, Done};
use sqlx::error::Error as SqlxError;

use crate::models::{CasbinRule, NewCasbinRule};

#[cfg(feature = "postgres")]
use sqlx::postgres::PgDone;
use sqlx::postgres::PgQueryResult;

#[cfg(feature = "mysql")]
use sqlx::mysql::MySqlDone;
use sqlx::mysql::MySqlQueryResult;

#[cfg(feature = "postgres")]
pub type ConnectionPool = sqlx::PgPool;
Expand All @@ -19,7 +19,7 @@ pub type ConnectionPool = sqlx::PgPool;
pub type ConnectionPool = sqlx::MySqlPool;

#[cfg(feature = "postgres")]
pub async fn new(conn: &ConnectionPool) -> Result<PgDone> {
pub async fn new(conn: &ConnectionPool) -> Result<PgQueryResult> {
sqlx::query!(
"CREATE TABLE IF NOT EXISTS casbin_rule (
id SERIAL PRIMARY KEY,
Expand All @@ -40,7 +40,7 @@ pub async fn new(conn: &ConnectionPool) -> Result<PgDone> {
}

#[cfg(feature = "mysql")]
pub async fn new(conn: &ConnectionPool) -> Result<MySqlDone> {
pub async fn new(conn: &ConnectionPool) -> Result<MySqlQueryResult> {
sqlx::query!(
"CREATE TABLE IF NOT EXISTS casbin_rule (
id INT NOT NULL AUTO_INCREMENT,
Expand Down Expand Up @@ -82,7 +82,7 @@ pub async fn remove_policy(conn: &ConnectionPool, pt: &str, rule: Vec<String>) -
)
.execute(conn)
.await
.map(|n| Done::rows_affected(&n) == 1)
.map(|n| PgQueryResult::rows_affected(&n) == 1)
.map_err(|err| CasbinError::from(AdapterError(Box::new(Error::SqlxError(err)))))
}

Expand All @@ -108,7 +108,7 @@ pub async fn remove_policy(conn: &ConnectionPool, pt: &str, rule: Vec<String>) -
)
.execute(conn)
.await
.map(|n| Done::rows_affected(&n) == 1)
.map(|n| MySqlQueryResult::rows_affected(&n) == 1)
.map_err(|err| CasbinError::from(AdapterError(Box::new(Error::SqlxError(err)))))
}

Expand Down Expand Up @@ -144,7 +144,7 @@ pub async fn remove_policies(
.execute(&mut transaction)
.await
.and_then(|n| {
if Done::rows_affected(&n) == 1 {
if PgQueryResult::rows_affected(&n) == 1 {
Ok(true)
} else {
Err(SqlxError::RowNotFound)
Expand Down Expand Up @@ -191,7 +191,7 @@ pub async fn remove_policies(
.execute(&mut transaction)
.await
.and_then(|n| {
if Done::rows_affected(&n) == 1 {
if MySqlQueryResult::rows_affected(&n) == 1 {
Ok(true)
} else {
Err(SqlxError::RowNotFound)
Expand Down Expand Up @@ -297,7 +297,7 @@ pub async fn remove_filtered_policy(
boxed_query
.execute(conn)
.await
.map(|n| Done::rows_affected(&n) >= 1)
.map(|n| PgQueryResult::rows_affected(&n) >= 1)
.map_err(|err| CasbinError::from(AdapterError(Box::new(Error::SqlxError(err)))))
}

Expand Down Expand Up @@ -392,7 +392,7 @@ pub async fn remove_filtered_policy(
boxed_query
.execute(conn)
.await
.map(|n| Done::rows_affected(&n) >= 1)
.map(|n| MySqlQueryResult::rows_affected(&n) >= 1)
.map_err(|err| CasbinError::from(AdapterError(Box::new(Error::SqlxError(err)))))
}

Expand Down Expand Up @@ -507,7 +507,7 @@ pub(crate) async fn save_policy(
.execute(&mut transaction)
.await
.and_then(|n| {
if Done::rows_affected(&n) == 1 {
if PgQueryResult::rows_affected(&n) == 1 {
Ok(true)
} else {
Err(SqlxError::RowNotFound)
Expand Down Expand Up @@ -550,7 +550,7 @@ pub(crate) async fn save_policy<'a>(
.execute(&mut transaction)
.await
.and_then(|n| {
if Done::rows_affected(&n) == 1 {
if MySqlQueryResult::rows_affected(&n) == 1 {
Ok(true)
} else {
Err(SqlxError::RowNotFound)
Expand Down Expand Up @@ -580,7 +580,7 @@ pub(crate) async fn add_policy(conn: &ConnectionPool, rule: NewCasbinRule<'_>) -
)
.execute(conn)
.await
.map(|n| Done::rows_affected(&n) == 1)
.map(|n| PgQueryResult::rows_affected(&n) == 1)
.map_err(|err| CasbinError::from(AdapterError(Box::new(Error::SqlxError(err)))))?;

Ok(true)
Expand All @@ -601,7 +601,7 @@ pub(crate) async fn add_policy(conn: &ConnectionPool, rule: NewCasbinRule<'_>) -
)
.execute(conn)
.await
.map(|n| Done::rows_affected(&n) == 1)
.map(|n| MySqlQueryResult::rows_affected(&n) == 1)
.map_err(|err| CasbinError::from(AdapterError(Box::new(Error::SqlxError(err)))))?;

Ok(true)
Expand Down Expand Up @@ -631,7 +631,7 @@ pub(crate) async fn add_policies(
.execute(&mut transaction)
.await
.and_then(|n| {
if Done::rows_affected(&n) == 1 {
if PgQueryResult::rows_affected(&n) == 1 {
Ok(true)
} else {
Err(SqlxError::RowNotFound)
Expand Down Expand Up @@ -670,7 +670,7 @@ pub(crate) async fn add_policies(
.execute(&mut transaction)
.await
.and_then(|n| {
if Done::rows_affected(&n) == 1 {
if MySqlQueryResult::rows_affected(&n) == 1 {
Ok(true)
} else {
Err(SqlxError::RowNotFound)
Expand Down

0 comments on commit 15b06cc

Please sign in to comment.