Skip to content

Commit

Permalink
Replace feature sqlite with sqlitefaster.
Browse files Browse the repository at this point in the history
  • Loading branch information
z-Wind committed Aug 22, 2024
1 parent f0623ce commit afe58d0
Show file tree
Hide file tree
Showing 41 changed files with 485 additions and 3,777 deletions.
55 changes: 6 additions & 49 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,12 @@ jobs:
- name: Rust Cache dependencies
uses: Swatinem/rust-cache@v2

- name: Clippy --features sqlite,postgresql,mysql,xml,sqlitefaster
run: cargo clippy --features sqlite,postgresql,mysql,xml,sqlitefaster --all-targets -- -D warnings
- name: Clippy --features sqlite,postgresql,mysql,xml
run: cargo clippy --features sqlite,postgresql,mysql,xml --all-targets -- -D warnings

- name: Clippy --features sqlite
run: cargo clippy --features sqlite --all-targets -- -D warnings

- name: Clippy --features sqlitefaster
run: cargo clippy --features sqlitefaster --all-targets -- -D warnings

- name: Clippy --features postgresql
run: cargo clippy --features postgresql --all-targets -- -D warnings

Expand All @@ -52,15 +49,12 @@ jobs:
- name: Clippy --features xml
run: cargo clippy --features xml --all-targets -- -D warnings

- name: Clippy --features sqlite,postgresql,mysql,xml,sqlitefaster,decimal
run: cargo clippy --features sqlite,postgresql,mysql,xml,sqlitefaster,decimal --all-targets -- -D warnings
- name: Clippy --features sqlite,postgresql,mysql,xml,decimal
run: cargo clippy --features sqlite,postgresql,mysql,xml,decimal --all-targets -- -D warnings

- name: Clippy --features sqlite,decimal
run: cargo clippy --features sqlite,decimal --all-targets -- -D warnings

- name: Clippy --features sqlitefaster,decimal
run: cargo clippy --features sqlitefaster,decimal --all-targets -- -D warnings

- name: Clippy --features postgresql,decimal
run: cargo clippy --features postgresql,decimal --all-targets -- -D warnings

Expand Down Expand Up @@ -122,10 +116,10 @@ jobs:

- name: Install latest nextest release
uses: taiki-e/install-action@nextest

- name: Check Schema
run: cargo check --features sqlite,schema --all-targets
env:
env:
DATABASE_URL: "sqlite://tests/db/sqlite/complex_sample.gnucash?mode=ro"

- name: Run tests --features sqlite
Expand All @@ -140,43 +134,6 @@ jobs:
cargo test --doc --features sqlite,decimal
test_sqlitefaster:
name: Test SQLiteFaster
needs: [lint]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest

steps:
- uses: actions/checkout@v4

- name: Rust Cache dependencies
uses: Swatinem/rust-cache@v2

- name: Install latest nextest release
uses: taiki-e/install-action@nextest

- name: Check Schema
run: cargo check --features sqlitefaster --all-targets
env:
DATABASE_URL: "file:/tests/db/sqlite/complex_sample.gnucash"

- name: Run tests --features sqlitefaster
run: cargo nextest run --config-file ${{ github.workspace }}/.github/nextest.toml --profile ci --features sqlitefaster

- name: Run tests --features sqlitefaster,decimal
run: cargo nextest run --config-file ${{ github.workspace }}/.github/nextest.toml --profile ci --features sqlitefaster,decimal

- name: Run doc tests
run: |
cargo test --doc --features sqlitefaster
cargo test --doc --features sqlitefaster,decimal
test_mysql:
name: Test MySQL
needs: [lint]
Expand Down
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"rust-analyzer.cargo.features": [
"sqlite",
"sqlitefaster",
"postgresql",
"mysql",
"xml",
Expand Down
26 changes: 12 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rucash"
version = "0.4.2"
version = "0.5.0"
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/z-Wind/rucash"
Expand All @@ -18,16 +18,20 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
sqlx = { version = "0.8", optional = true }
# sqlx = { version = "0.8", optional = true }
sqlx = { git = "https://github.com/launchbadge/sqlx.git", rev = "6f2905695b9606b5f51b40ce10af63ac9e696bb8", optional = true }
chrono = "0.4"
rust_decimal = { version = "1.35", optional = true }
rust_decimal = { version = "1.36", optional = true }
xmltree = { version = "0.10", optional = true }
itertools = "0.13"
flate2 = "1.0"
tokio = { version = "1.39", features = ["sync"] }
num-traits = "0.2"
thiserror = "1.0"
rusqlite = { version = "*", features = ["bundled", "chrono"], optional = true }
rusqlite = { version = "0.32", features = [
"bundled",
"chrono",
], optional = true }

[lib]
name = "rucash"
Expand All @@ -41,15 +45,14 @@ tokio = { version = "1.39", features = ["rt-multi-thread", "macros"] }

[features]
default = []
schema = []
schema = ["sqlx_common", "sqlx/sqlite"]
sqlx_common = [
"sqlx/any",
"sqlx/runtime-tokio-rustls",
"sqlx/macros",
"sqlx/chrono",
]
sqlite = ["sqlx_common", "sqlx/sqlite"]
sqlitefaster = ["rusqlite"]
sqlite = ["rusqlite"]
postgresql = ["sqlx_common", "sqlx/postgres"]
mysql = ["sqlx_common", "sqlx/mysql"]
xml = ["xmltree"]
Expand All @@ -58,18 +61,13 @@ decimal = ["rust_decimal"]
[[bench]]
name = "benchmark"
harness = false
required-features = ["sqlite", "xml", "sqlitefaster"]
required-features = ["sqlite", "xml"]

[[test]]
name = "sqlite"
path = "tests/sqlite.rs"
required-features = ["sqlite"]

[[test]]
name = "sqlitefaster"
path = "tests/sqlitefaster.rs"
required-features = ["sqlitefaster"]

[[test]]
name = "mysql"
path = "tests/mysql.rs"
Expand All @@ -88,4 +86,4 @@ required-features = ["postgresql"]
[[test]]
name = "all"
path = "tests/all.rs"
required-features = ["sqlite", "postgresql", "mysql", "xml", "sqlitefaster"]
required-features = ["sqlite", "postgresql", "mysql", "xml"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use rucash::{Book, SQLiteQuery};

#[tokio::main]
async fn main() {
let query = SQLiteQuery::new("sqlite://tests/db/sqlite/complex_sample.gnucash?mode=ro").await.unwrap();
let query = SQLiteQuery::new("tests/db/sqlite/complex_sample.gnucash").unwrap();
let book = Book::new(query).await.unwrap();
let accounts = book.accounts();
}
Expand All @@ -49,7 +49,7 @@ async fn main() {
```toml
# Cargo.toml
[dependencies]
rucash = { version = "0.4", features = [ "sqlite", "decimal" ] }
rucash = { version = "0.5", features = [ "sqlite", "decimal" ] }
```

#### Cargo Feature Flags
Expand Down
44 changes: 4 additions & 40 deletions benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};

fn uri_sqlite() -> String {
format!(
"sqlite://{}/tests/db/sqlite/complex_sample.gnucash?mode=ro",
"file:/{}/tests/db/sqlite/complex_sample.gnucash",
env!("CARGO_MANIFEST_DIR")
)
}
Expand All @@ -14,17 +14,10 @@ fn uri_xml() -> String {
)
}

fn uri_sqlitefaster() -> String {
format!(
"file:/{}/tests/db/sqlite/complex_sample.gnucash",
env!("CARGO_MANIFEST_DIR")
)
}

fn benchmark_sql_query(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();
let book = rt.block_on(async {
let query = rucash::SQLiteQuery::new(&uri_sqlite()).await.unwrap();
let query = rucash::SQLiteQuery::new(&uri_sqlite()).unwrap();
rucash::Book::new(query).await.unwrap()
});

Expand All @@ -36,25 +29,10 @@ fn benchmark_sql_query(c: &mut Criterion) {
});
}

fn benchmark_sql_faster_query(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();
let book = rt.block_on(async {
let query = rucash::SQLiteQueryFaster::new(&uri_sqlitefaster()).unwrap();
rucash::Book::new(query).await.unwrap()
});

c.bench_function("sql faster query", |b| {
b.to_async(&rt).iter(|| async {
book.accounts_contains_name_ignore_case(black_box("aS"))
.await
});
});
}

fn benchmark_vec_filter(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();
let book = rt.block_on(async {
let query = rucash::SQLiteQuery::new(&uri_sqlite()).await.unwrap();
let query = rucash::SQLiteQuery::new(&uri_sqlite()).unwrap();
rucash::Book::new(query).await.unwrap()
});

Expand Down Expand Up @@ -84,7 +62,7 @@ fn benchmark_xml_book(c: &mut Criterion) {
fn benchmark_sqlite_book(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();
let book = rt.block_on(async {
let query = rucash::SQLiteQuery::new(&uri_sqlite()).await.unwrap();
let query = rucash::SQLiteQuery::new(&uri_sqlite()).unwrap();
rucash::Book::new(query).await.unwrap()
});

Expand All @@ -93,25 +71,11 @@ fn benchmark_sqlite_book(c: &mut Criterion) {
});
}

fn benchmark_sqlitefaster_book(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();
let book = rt.block_on(async {
let query = rucash::SQLiteQueryFaster::new(&uri_sqlitefaster()).unwrap();
rucash::Book::new(query).await.unwrap()
});

c.bench_function("SqliteFasterBook", |b| {
b.to_async(&rt).iter(|| async { book.accounts().await })
});
}

criterion_group!(
benches,
benchmark_sql_query,
benchmark_sql_faster_query,
benchmark_vec_filter,
benchmark_xml_book,
benchmark_sqlite_book,
benchmark_sqlitefaster_book,
);
criterion_main!(benches);
16 changes: 7 additions & 9 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,25 @@ all: test build
build:
cargo build
test:
cargo test --features sqlite,postgresql,mysql,xml,sqlitefaster
cargo test --features sqlite,postgresql,mysql,xml
cargo test --features sqlite
cargo test --features sqlitefaster
cargo test --features postgresql
cargo test --features mysql
cargo test --features xml
cargo test --features sqlite,postgresql,mysql,xml,sqlitefaster,decimal
cargo test --features sqlite,postgresql,mysql,xml,decimal
cargo test --features sqlite,decimal
cargo test --features sqlitefaster,decimal
cargo test --features postgresql,decimal
cargo test --features mysql,decimal
cargo test --features xml,decimal
clean:
cargo clean
bench:
cargo bench --features sqlite,xml,sqlitefaster
cargo bench --features sqlite,xml
check:
cargo check --features sqlite,postgresql,mysql,xml,sqlitefaster --all-targets
cargo clippy --features sqlite,postgresql,mysql,xml,sqlitefaster --all-targets
cargo check --features sqlite,postgresql,mysql,xml,sqlitefaster,decimal --all-targets
cargo clippy --features sqlite,postgresql,mysql,xml,sqlitefaster,decimal --all-targets
cargo check --features sqlite,postgresql,mysql,xml --all-targets
cargo clippy --features sqlite,postgresql,mysql,xml --all-targets
cargo check --features sqlite,postgresql,mysql,xml,decimal --all-targets
cargo clippy --features sqlite,postgresql,mysql,xml,decimal --all-targets
checkschema:
export DATABASE_URL=sqlite://tests/db/sqlite/complex_sample.gnucash?mode=ro
cargo check --features sqlite,schema --all-targets
Expand Down
Loading

0 comments on commit afe58d0

Please sign in to comment.