Skip to content

Commit

Permalink
Prepare for publish
Browse files Browse the repository at this point in the history
  • Loading branch information
devashishdxt committed Jan 10, 2022
1 parent 89ecc89 commit 314a8e8
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 140 deletions.
11 changes: 0 additions & 11 deletions .appveyor.yml

This file was deleted.

Empty file removed .cargo-ok
Empty file.
69 changes: 0 additions & 69 deletions .travis.yml

This file was deleted.

13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@
name = "rexie"
version = "0.1.0"
authors = ["Devashish Dixit <[email protected]>"]
license = "MIT/Apache-2.0"
description = "Rexie is an easy-to-use, futures based wrapper around IndexedDB that compiles to webassembly"
homepage = "https://github.com/devashishdxt/rexie"
repository = "https://github.com/devashishdxt/rexie"
categories = ["asynchronous", "database", "wasm", "web-programming"]
keywords = ["wasm", "indexeddb", "futures", "webassembly", "idb"]
readme = "README.md"
include = ["Cargo.toml", "src/**/*.rs", "tests/**/*.rs", "README.md"]
edition = "2021"

[package.metadata.wasm-pack.profile.release]
wasm-opt = false

[lib]
path = "src/lib.rs"
crate-type = ["cdylib", "rlib"]

[features]
Expand Down Expand Up @@ -46,6 +58,7 @@ wee_alloc = { version = "0.4.5", optional = true }

[dev-dependencies]
serde = { version = "1.0.133", features = ["derive"] }
serde_json = "1.0.74"
serde-wasm-bindgen = "0.4.1"
wasm-bindgen-test = "0.3.28"

Expand Down
124 changes: 78 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,101 @@
<div align="center">
# rexie

<h1><code>wasm-pack-template</code></h1>
Rexie is an easy-to-use, futures based wrapper around IndexedDB that compiles to webassembly.

<strong>A template for kick starting a Rust and WebAssembly project using <a href="https://github.com/rustwasm/wasm-pack">wasm-pack</a>.</strong>
## Usage

<p>
<a href="https://travis-ci.org/rustwasm/wasm-pack-template"><img src="https://img.shields.io/travis/rustwasm/wasm-pack-template.svg?style=flat-square" alt="Build Status" /></a>
</p>
To use Rexie, you need to add the following to your `Cargo.toml`:

<h3>
<a href="https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html">Tutorial</a>
<span> | </span>
<a href="https://discordapp.com/channels/442252698964721669/443151097398296587">Chat</a>
</h3>
```toml
[dependencies]
rexie = "0.1"
```

<sub>Built with 🦀🕸 by <a href="https://rustwasm.github.io/">The Rust and WebAssembly Working Group</a></sub>
</div>
### Example

To create a new database, you can use the [`Rexie::builder`] method:

```rust
use rexie::*;

async fn build_database() -> Result<Rexie> {
// Create a new database
let rexie = Rexie::builder("test")
// Set the version of the database to 1.0
.version(1)
// Add an object store named `employees`
.add_object_store(
ObjectStore::new("employees")
// Set the key path to `id`
.key_path("id")
// Enable auto increment
.auto_increment(true)
// Add an index named `email` with the key path `email` with unique enabled
.add_index(Index::new("email", "email").unique(true)),
)
// Build the database
.build()
.await?;

// Check basic details of the database
assert_eq!(rexie.name(), "test");
assert_eq!(rexie.version(), 1.0);
assert_eq!(rexie.store_names(), vec!["employees"]);

Ok(rexie)
}
```

## About
To add an employee, you can use the [`Store::add`] method after creating a [`Transaction`]:

[**📚 Read this template tutorial! 📚**][template-docs]
```rust
use rexie::*;

This template is designed for compiling Rust libraries into WebAssembly and
publishing the resulting package to NPM.
async fn add_employee(rexie: &Rexie, name: &str, email: &str) -> Result<u32> {
let transaction = rexie.transaction(&["employees"], TransactionMode::ReadWrite)?;

Be sure to check out [other `wasm-pack` tutorials online][tutorials] for other
templates and usages of `wasm-pack`.
let employees = transaction.store("employees")?;

[tutorials]: https://rustwasm.github.io/docs/wasm-pack/tutorials/index.html
[template-docs]: https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html
let employee = serde_json::json!({
"name": name,
"email": email,
});
let employee = serde_wasm_bindgen::to_value(&employee).unwrap();
let employee_id = employees.add(&employee, None).await?;

## 🚴 Usage
transaction.commit().await?;
Ok(num_traits::cast(employee_id.as_f64().unwrap()).unwrap())
}
```

### 🐑 Use `cargo generate` to Clone this Template
To get an employee, you can use the [`Store::get`] method after creating a [`Transaction`]:

[Learn more about `cargo generate` here.](https://github.com/ashleygwilliams/cargo-generate)
```rust
use rexie::*;

```
cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project
cd my-project
```
async fn get_employee(rexie: &Rexie, id: u32) -> Result<Option<serde_json::Value>> {
let transaction = rexie.transaction(&["employees"], TransactionMode::ReadOnly)?;

### 🛠️ Build with `wasm-pack build`
let employees = transaction.store("employees")?;

```
wasm-pack build
let employee = employees.get(&id.into()).await?;
let employee: Option<serde_json::Value> = serde_wasm_bindgen::from_value(employee).unwrap();

transaction.commit().await?;
Ok(employee)
}
```

### 🔬 Test in Headless Browsers with `wasm-pack test`
## License

```
wasm-pack test --headless --firefox
```
Licensed under either of

### 🎁 Publish to NPM with `wasm-pack publish`
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE))
- MIT license ([LICENSE-MIT](LICENSE-MIT))

```
wasm-pack publish
```
at your option.

## 🔋 Batteries Included
## Contribution

* [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) for communicating
between WebAssembly and JavaScript.
* [`console_error_panic_hook`](https://github.com/rustwasm/console_error_panic_hook)
for logging panic messages to the developer console.
* [`wee_alloc`](https://github.com/rustwasm/wee_alloc), an allocator optimized
for small code size.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as
defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
17 changes: 17 additions & 0 deletions README.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# {{crate}}

{{readme}}

## License

Licensed under either of

- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE))
- MIT license ([LICENSE-MIT](LICENSE-MIT))

at your option.

## Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as
defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
98 changes: 84 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,87 @@
//! ## Usage
//!
//! ```rust,ignore
//! let rexie = Rexie::builder("backend")
//! .version(1)
//! .add_object_store(
//! ObjectStore::new("employees")
//! .key_path("id")
//! .add_index(Index::new("email", "email").unique(true)),
//! )
//! .build()
//! .await?;
//!
//! web_sys::console::log_1(&rexie.name().into());
//! Rexie is an easy-to-use, futures based wrapper around IndexedDB that compiles to webassembly.
//!
//! # Usage
//!
//! To use Rexie, you need to add the following to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! rexie = "0.1"
//! ```
//!
//! ## Example
//!
//! To create a new database, you can use the [`Rexie::builder`] method:
//!
//! ```rust
//! use rexie::*;
//!
//! async fn build_database() -> Result<Rexie> {
//! // Create a new database
//! let rexie = Rexie::builder("test")
//! // Set the version of the database to 1.0
//! .version(1)
//! // Add an object store named `employees`
//! .add_object_store(
//! ObjectStore::new("employees")
//! // Set the key path to `id`
//! .key_path("id")
//! // Enable auto increment
//! .auto_increment(true)
//! // Add an index named `email` with the key path `email` with unique enabled
//! .add_index(Index::new("email", "email").unique(true)),
//! )
//! // Build the database
//! .build()
//! .await?;
//!
//! // Check basic details of the database
//! assert_eq!(rexie.name(), "test");
//! assert_eq!(rexie.version(), 1.0);
//! assert_eq!(rexie.store_names(), vec!["employees"]);
//!
//! Ok(rexie)
//! }
//! ```
//!
//! To add an employee, you can use the [`Store::add`] method after creating a [`Transaction`]:
//!
//! ```rust
//! use rexie::*;
//!
//! async fn add_employee(rexie: &Rexie, name: &str, email: &str) -> Result<u32> {
//! let transaction = rexie.transaction(&["employees"], TransactionMode::ReadWrite)?;
//!
//! let employees = transaction.store("employees")?;
//!
//! let employee = serde_json::json!({
//! "name": name,
//! "email": email,
//! });
//! let employee = serde_wasm_bindgen::to_value(&employee).unwrap();
//! let employee_id = employees.add(&employee, None).await?;
//!
//! transaction.commit().await?;
//! Ok(num_traits::cast(employee_id.as_f64().unwrap()).unwrap())
//! }
//! ```
//!
//! To get an employee, you can use the [`Store::get`] method after creating a [`Transaction`]:
//!
//! ```rust
//! use rexie::*;
//!
//! async fn get_employee(rexie: &Rexie, id: u32) -> Result<Option<serde_json::Value>> {
//! let transaction = rexie.transaction(&["employees"], TransactionMode::ReadOnly)?;
//!
//! let employees = transaction.store("employees")?;
//!
//! let employee = employees.get(&id.into()).await?;
//! let employee: Option<serde_json::Value> = serde_wasm_bindgen::from_value(employee).unwrap();
//!
//! transaction.commit().await?;
//! Ok(employee)
//! }
//! ```
mod error;
mod index;
Expand Down

0 comments on commit 314a8e8

Please sign in to comment.