Skip to content

Commit

Permalink
Merge pull request #55 from hackerchai/feature/sqlite
Browse files Browse the repository at this point in the history
Feature/sqlite
  • Loading branch information
hackerchai authored Feb 5, 2021
2 parents 62feaa7 + 7db7a92 commit 80e93b7
Show file tree
Hide file tree
Showing 8 changed files with 499 additions and 308 deletions.
74 changes: 72 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ jobs:
components: rustfmt, clippy
override: true

- name: Install PostgreSQL & MySQL Dependencies
run: sudo apt-get install libpq-dev postgresql-client mysql-client libmysqlclient-dev
- name: Install PostgreSQL & MySQL & SQLite Dependencies
run: sudo apt-get install libpq-dev postgresql-client mysql-client libmysqlclient-dev libsqlite3-dev sqlite3

- name: Create SQLite DB
run: |
touch casbin.db
- name: Create PostgresSQL Table
run: psql postgres://casbin_rs:casbin_rs@127.0.0.1:5432/casbin -c "CREATE TABLE IF NOT EXISTS casbin_rule (
Expand Down Expand Up @@ -76,6 +80,20 @@ jobs:
CONSTRAINT unique_key_sqlx_adapter UNIQUE(ptype, v0, v1, v2, v3, v4, v5)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
- name: Create SQLite Table
run: |
sqlite3 casbin.db -cmd "CREATE TABLE IF NOT EXISTS casbin_rule (
id INTEGER PRIMARY KEY,
ptype VARCHAR(12) NOT NULL,
v0 VARCHAR(128) NOT NULL,
v1 VARCHAR(128) NOT NULL,
v2 VARCHAR(128) NOT NULL,
v3 VARCHAR(128) NOT NULL,
v4 VARCHAR(128) NOT NULL,
v5 VARCHAR(128) NOT NULL,
CONSTRAINT unique_key_diesel_adapter UNIQUE(ptype, v0, v1, v2, v3, v4, v5)
);"
- name: Cargo Build
uses: actions-rs/cargo@v1
with:
Expand Down Expand Up @@ -185,6 +203,58 @@ jobs:
command: test
args: --no-default-features --features mysql,runtime-actix-rustls

#SQLite
#async-std
- name: Cargo Test For SQLite,runtime-async-std-native-tls
uses: actions-rs/cargo@v1
env:
DATABASE_URL: sqlite:casbin.db
with:
command: test
args: --no-default-features --features sqlite,runtime-async-std-native-tls

- name: Cargo Test For SQLite,runtime-async-std-rustls
uses: actions-rs/cargo@v1
env:
DATABASE_URL: sqlite:casbin.db
with:
command: test
args: --no-default-features --features sqlite,runtime-async-std-rustls

# tokio
- name: Cargo Test For SQLite,runtime-tokio-native-tls
uses: actions-rs/cargo@v1
env:
DATABASE_URL: sqlite:casbin.db
with:
command: test
args: --no-default-features --features sqlite,runtime-tokio-native-tls

- name: Cargo Test For SQLite,runtime-tokio-rustls
uses: actions-rs/cargo@v1
env:
DATABASE_URL: sqlite:casbin.db
with:
command: test
args: --no-default-features --features sqlite,runtime-tokio-rustls

# actix
- name: Cargo Test For SQLite,runtime-actix-native-tls
uses: actions-rs/cargo@v1
env:
DATABASE_URL: sqlite:casbin.db
with:
command: test
args: --no-default-features --features sqlite,runtime-actix-native-tls

- name: Cargo Test For SQLite,runtime-actix-rustls
uses: actions-rs/cargo@v1
env:
DATABASE_URL: sqlite:casbin.db
with:
command: test
args: --no-default-features --features sqlite,runtime-actix-rustls

- name: Cargo Clippy
uses: actions-rs/cargo@v1
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
.idea/
Cargo.lock
.DS_Store
*.db
*.db-wal
*.db-shm
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sqlx-adapter"
version = "0.4.0"
version = "0.4.1"
authors = ["Eason Chai <hackerchai.com@gmail.com>","Cheng JIANG <jiang.cheng@vip.163.com>"]
edition = "2018"
license = "Apache-2.0"
Expand All @@ -23,6 +23,7 @@ default = ["postgres", "runtime-tokio-native-tls", "offline"]
#databases
postgres = ["sqlx/postgres"]
mysql = ["sqlx/mysql"]
sqlite = ["sqlx/sqlite"]

# async runtime
# async-std
Expand Down
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ Based on [Sqlx](https://github.com/launchbadge/sqlx), The current supported data

- [Mysql](https://www.mysql.com/)
- [Postgres](https://github.com/lib/pq)
- [SQLite](https://www.sqlite.org)

## Notice
In order to unify the database table name in Casbin ecosystem, we decide to use `casbin_rule` instead of `casbin_rules` from version `0.4.0`. If you are using old version `sqlx-adapter` in your production environment, please use following command and update `sqlx-adapter` version:

````SQL
# MySQL & PostgreSQL
# MySQL & PostgreSQL & SQLite
ALTER TABLE casbin_rules RENAME TO casbin_rule;
````

Expand All @@ -26,7 +27,7 @@ ALTER TABLE casbin_rules RENAME TO casbin_rule;
Add it to `Cargo.toml`

```rust
sqlx-adapter = { version = "0.4.0", features = ["postgres"] }
sqlx-adapter = { version = "0.4.1, features = ["postgres"] }
tokio = "1.1.1"
```
Expand Down Expand Up @@ -121,6 +122,21 @@ tokio = "1.1.1"
PRIMARY KEY(id),
CONSTRAINT unique_key_sqlx_adapter UNIQUE(ptype, v0, v1, v2, v3, v4, v5)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
# SQLite
touch casbin.db
sqlite3 casbin.db -cmd "CREATE TABLE IF NOT EXISTS casbin_rule (
id INTEGER PRIMARY KEY,
ptype VARCHAR(12) NOT NULL,
v0 VARCHAR(128) NOT NULL,
v1 VARCHAR(128) NOT NULL,
v2 VARCHAR(128) NOT NULL,
v3 VARCHAR(128) NOT NULL,
v4 VARCHAR(128) NOT NULL,
v5 VARCHAR(128) NOT NULL,
CONSTRAINT unique_key_diesel_adapter UNIQUE(ptype, v0, v1, v2, v3, v4, v5)
);"
```
3. Configure `env`
Expand All @@ -130,6 +146,7 @@ tokio = "1.1.1"
```bash
DATABASE_URL=postgres://casbin_rs:casbin_rs@localhost:5432/casbin
# DATABASE_URL=mysql://casbin_rs:casbin_rs@localhost:3306/casbin
# DATABASE_URL=sqlite:casbin.db
POOL_SIZE=8
```
Expand Down Expand Up @@ -164,5 +181,6 @@ async fn main() -> Result<()> {

- `postgres`
- `mysql`
- `sqlite`

*Attention*: `postgres` and `mysql` are mutual exclusive which means that you can only activate one of them. Currently we don't have support for `sqlite`, it may be added in the near future.
*Attention*: `postgres`, `mysql`, `sqlite` are mutual exclusive which means that you can only activate one of them.
Loading

0 comments on commit 80e93b7

Please sign in to comment.