Skip to content

Commit

Permalink
Feat: Persistant Storage (#306)
Browse files Browse the repository at this point in the history
* feat/Persist-Resource

* feat: Added generic Trait for Persist

* feat: Ability to easily save structs to File

* feat: Ability to easily save structs to File

* feat: Added example and improved error handling

* feat: Improved Error handling & Formatting

* feat: Improved Error handling and Docs

* feat: formatting

* feat: cargo sort

* feat: Added comment recommendations

* feat: fixed loader project_name issue

* feat: added missing ";"

* feat: cargo fmt

* feat: error & example improvements

* feat: move optional feature down

* refactor: make path filesystem agnostic

* refactor: remove stale comment

* bug: accidental file create on load

* refactor: sort dependencies

Co-authored-by: chesedo <pieter@chesedo.me>
  • Loading branch information
Butch78 and chesedo authored Sep 21, 2022
1 parent 60011c4 commit dbfb0ee
Show file tree
Hide file tree
Showing 11 changed files with 453 additions and 5 deletions.
206 changes: 201 additions & 5 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions api/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ impl ShuttleFactory {

#[async_trait]
impl Factory for ShuttleFactory {
fn get_project_name(&self) -> ProjectName {
self.project_name.clone()
}

async fn get_db_connection_string(
&mut self,
db_type: Type,
Expand Down
4 changes: 4 additions & 0 deletions cargo-shuttle/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ impl Factory for LocalFactory {

Ok(conn_str)
}

fn get_project_name(&self) -> ProjectName {
self.project.clone()
}
}

impl LocalFactory {
Expand Down
12 changes: 12 additions & 0 deletions examples/rocket/persist/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "persist"
version = "0.1.0"
edition = "2021"

[lib]

[dependencies]
rocket = { version = "0.5.0-rc.1", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
sqlx = { version = "0.5", features = ["runtime-tokio-native-tls", "postgres"] }
shuttle-service = { version = "0.5.0", features = ["web-rocket", "persist"] }
35 changes: 35 additions & 0 deletions examples/rocket/persist/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Persist Example

An example app to show what you can do with shuttle.

## How to deploy the example

To deploy the examples, check out the repository locally

```bash
$ git clone https://github.com/shuttle-hq/shuttle.git
```

navigate to the Persist root folder

```bash
$ cd examples/rocket/persist
```

Pick a project name that is something unique - in shuttle,
projects are globally unique. Then run

```bash
$ cargo shuttle deploy --name=$PROJECT_NAME
```

Once deployed you can post to the endpoint the following values:
```bash
curl -X POST -H "Content-Type: application/json" -d '{"date":"2020-12-22", "temp_high":5, "temp_low":5, "precipitation": 5}' {$PROJECT_NAME}.shuttleapp.rs
```

The json data will then persist within Shuttle it can be queried with the following curl request

```bash
curl {$PROJECT_NAME}.shuttleapp.rs/2020-12-22
```
1 change: 1 addition & 0 deletions examples/rocket/persist/Shuttle.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name = "persist-rocket-app"
Loading

0 comments on commit dbfb0ee

Please sign in to comment.