Skip to content

Commit

Permalink
Release 0.5.0, added ExcelPostgresBuilder, cleaned up project
Browse files Browse the repository at this point in the history
  • Loading branch information
carlvoller committed Sep 10, 2024
1 parent c6f9f91 commit cfc9465
Show file tree
Hide file tree
Showing 27 changed files with 672 additions and 304 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
python3 -m ensurepip
fi
manylinux: manylinux_2_28
working-directory: py-excel-rs
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -90,6 +91,7 @@ jobs:
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: musllinux_1_2
working-directory: py-excel-rs
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -143,6 +145,7 @@ jobs:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
working-directory: py-excel-rs
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
Expand All @@ -158,6 +161,7 @@ jobs:
with:
command: sdist
args: --out dist
working-directory: py-excel-rs
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
Expand Down
65 changes: 37 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 15 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
[package]
name = "excel-rs"
version = "0.4.2"
[workspace]
members = ["crates/*", "py-excel-rs"]
resolver = "2"

[workspace.package]
version = "0.5.0"
authors = ["Carl Voller"]
edition = "2021"
homepage = "https://github.com/carlvoller/excel-rs"
license = "MIT"
repository = "https://github.com/carlvoller/excel-rs"

[workspace.dependencies]
excel-rs-xlsx = { version = "0.5.0", path = "crates/excel-rs-xlsx", default-features = false }
excel-rs-csv = { version = "0.5.0", path = "crates/excel-rs-csv", default-features = false }
excel-rs-postgres = { version = "0.5.0", path = "crates/excel-rs-postgres", default-features = false }

[profile.release]
opt-level = 3
lto = "fat"
debug = true
overflow-checks = false
debug-assertions = false

[dependencies]
csv = "1"
pyo3 = { version = "0.21", features = ["extension-module"] }
anyhow = "1.0.86"
zip = { version = "2.2.0", default-features = false, features = ["deflate-flate2", "deflate-zlib-ng"] }
numpy = "0.21"
postgres = "0.19.8"
chrono = "0.4.38"
postgres-protocol = "0.6.7"
rust_decimal = { version = "1.36.0", features = ["db-postgres"] }
postgres_money = { version = "0.4.0", features = ["sql"] }
tokio-postgres-rustls = "0.12.0"
rustls = { version = "0.23.12", default-features = false, features = ["ring"] }

[lib]
name = "excel_rs"
crate-type = ["cdylib"]
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright 2024 Carl Ian Voller

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ with open('report.xlsx', 'wb') as f:
f.write(xlsx)
```

### Build Postgres Query to Excel:
```python
from py_excel_rs import ExcelPostgresBuilder, OrderBy

conn_string = "dbname=* user=* password=* host=*"
builder = ExcelPostgresBuilder(conn_str=conn_string, table_name="my_schema.my_table")

xlsx = builder.select_all()
.exclude(["Unwanted_Column1", "Unwanted_Column2"])
.orderBy("Usernames", OrderBy.ASCENDING)
.execute()

with open('report.xlsx', 'wb') as f:
f.write(xlsx)
```

## Rust
TODO: Add rust documentation

Expand All @@ -60,7 +76,7 @@ Tests were conducted on an Macbook Pro M1 Max with 64GB of RAM

### Python

#### py-excel-rs (2.186s)
#### py-excel-rs (2.89s)
```
$ time python test-py-excel-rs.py
python3 test-py-excel-rs.py 2.00s user 0.18s system 99% cpu 2.186 total
Expand Down
11 changes: 11 additions & 0 deletions crates/excel-rs-csv/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "excel-rs-csv"
version.workspace = true
authors.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
repository.workspace = true

[dependencies]
csv = "1"
39 changes: 39 additions & 0 deletions crates/excel-rs-csv/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use std::io::Read;

use csv::{ByteRecord, Reader};

pub fn bytes_to_csv<V: Read>(bytes: V) -> Reader<V> {
csv::ReaderBuilder::new().from_reader(bytes)
}

pub fn get_headers<V: Read>(reader: &mut Reader<V>) -> Option<&ByteRecord> {
match reader.byte_headers() {
Ok(record) => Some(record),
Err(_) => None,
}
}

pub fn get_next_record<V: Read>(reader: &mut Reader<V>) -> Option<ByteRecord> {
let mut record = csv::ByteRecord::new();
match reader.read_byte_record(&mut record) {
Ok(status) => {
if status {
Some(record)
} else {
None
}
}
Err(_) => None,
}
}

// #[cfg(test)]
// mod tests {
// use super::*;

// #[test]
// fn it_works() {
// let result = add(2, 2);
// assert_eq!(result, 4);
// }
// }
22 changes: 22 additions & 0 deletions crates/excel-rs-postgres/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "excel-rs-postgres"
version.workspace = true
authors.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
repository.workspace = true
readme = "../../README.md"
description = "excel-rs postgres"

[dependencies]
anyhow = "1.0.86"
chrono = "0.4.38"
excel-rs-xlsx = { workspace = true }
pyo3 = { version = "0.21", features = ["extension-module"] }
postgres = "0.19.8"
postgres-protocol = "0.6.7"
rust_decimal = { version = "1.36.0", features = ["db-postgres"] }
postgres_money = { version = "0.4.0", features = ["sql"] }
tokio-postgres-rustls = "0.12.0"
rustls = { version = "0.23.12", default-features = false, features = ["ring"] }
Loading

0 comments on commit cfc9465

Please sign in to comment.