1
0
mirror of https://github.com/actix/examples synced 2024-11-27 16:02:57 +01:00

delete db/r2d2 example

This commit is contained in:
Rob Ede 2022-02-06 08:25:38 +00:00
parent a4d43c0ff8
commit da60a30fd9
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
22 changed files with 29 additions and 123 deletions

41
Cargo.lock generated
View File

@ -1548,7 +1548,7 @@ dependencies = [
"rand 0.7.3",
"serde 1.0.136",
"serde_json",
"uuid 0.8.2",
"uuid",
]
[[package]]
@ -1567,7 +1567,7 @@ dependencies = [
"serde 1.0.136",
"serde_bytes",
"serde_json",
"uuid 0.8.2",
"uuid",
]
[[package]]
@ -2258,7 +2258,7 @@ dependencies = [
"libsqlite3-sys 0.9.1",
"pq-sys",
"r2d2",
"uuid 0.8.2",
"uuid",
]
[[package]]
@ -2273,7 +2273,7 @@ dependencies = [
"futures",
"serde 1.0.136",
"serde_json",
"uuid 0.8.2",
"uuid",
]
[[package]]
@ -3357,7 +3357,7 @@ dependencies = [
"smartstring",
"static_assertions 1.1.0",
"url",
"uuid 0.8.2",
"uuid",
]
[[package]]
@ -3374,7 +3374,7 @@ dependencies = [
"r2d2_mysql",
"serde 1.0.136",
"serde_json",
"uuid 0.8.2",
"uuid",
]
[[package]]
@ -3830,7 +3830,7 @@ dependencies = [
"trust-dns-proto 0.20.4",
"trust-dns-resolver 0.20.4",
"typed-builder",
"uuid 0.8.2",
"uuid",
"version_check 0.9.4",
"webpki 0.21.4",
"webpki-roots 0.21.1",
@ -3862,7 +3862,7 @@ dependencies = [
"actix-web 4.0.0-rc.2",
"futures-util",
"sanitize-filename",
"uuid 0.8.2",
"uuid",
]
[[package]]
@ -3930,7 +3930,7 @@ dependencies = [
"sha2 0.8.2",
"time 0.1.43",
"twox-hash",
"uuid 0.8.2",
"uuid",
]
[[package]]
@ -4622,18 +4622,6 @@ dependencies = [
"scheduled-thread-pool",
]
[[package]]
name = "r2d2-example"
version = "1.0.0"
dependencies = [
"actix-web 4.0.0-rc.2",
"env_logger 0.9.0",
"r2d2",
"r2d2_sqlite",
"rusqlite",
"uuid 1.0.0-alpha.1",
]
[[package]]
name = "r2d2_mysql"
version = "17.0.0"
@ -5535,7 +5523,7 @@ dependencies = [
"serde_json",
"sparkpost",
"time 0.3.7",
"uuid 0.8.2",
"uuid",
]
[[package]]
@ -6693,15 +6681,6 @@ dependencies = [
"serde 1.0.136",
]
[[package]]
name = "uuid"
version = "1.0.0-alpha.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb3ab47baa004111b323696c6eaa2752e7356f7f77cf6b6dc7a2087368ce1ca4"
dependencies = [
"getrandom 0.2.4",
]
[[package]]
name = "v_escape"
version = "0.13.2"

View File

@ -17,7 +17,6 @@ members = [
"database_interactions/diesel",
"database_interactions/mongodb",
"database_interactions/pg",
"database_interactions/r2d2",
"database_interactions/redis",
"database_interactions/simple-auth-server",
"forms/form",

View File

@ -42,7 +42,7 @@ impl Distribution<CustomError> for Standard {
}
}
/// Actix web uses `ResponseError` for conversion of errors to a response
/// Actix Web uses `ResponseError` for conversion of errors to a response
impl ResponseError for CustomError {
fn error_response(&self) -> HttpResponse {
match self {

View File

@ -1,6 +1,6 @@
# diesel
Basic integration of [Diesel](https://diesel.rs/) using SQLite for Actix web.
Basic integration of [Diesel](https://diesel.rs/) using SQLite for Actix Web.
## Usage

View File

@ -26,7 +26,7 @@ pub fn insert_new_user(
nm: &str,
conn: &SqliteConnection,
) -> Result<models::User, DbError> {
// It is common when using Diesel with Actix web to import schema-related
// It is common when using Diesel with Actix Web to import schema-related
// modules inside a function's scope (rather than the normal module's scope)
// to prevent import collisions and namespace pollution.
use crate::schema::users::dsl::*;

View File

@ -1,4 +1,4 @@
//! Actix web Diesel integration example
//! Actix Web Diesel integration example
//!
//! Diesel does not support tokio, so we have to run it in separate threads using the web::block
//! function which offloads blocking code (like Diesel's) in order to not block the server's thread.

View File

@ -1,6 +1,6 @@
# MongoDB
Simple example of MongoDB usage with Actix web. For more information on the MongoDB Rust driver,
Simple example of MongoDB usage with Actix Web. For more information on the MongoDB Rust driver,
visit the [documentation](https://docs.rs/mongodb/2.0.0/mongodb/index.html) and
[source code](https://github.com/mongodb/mongo-rust-driver).
@ -22,4 +22,3 @@ MongoDB manual.
### Run the example
To execute the example code, run `cargo run` in the `database_interactions/mongodb` directory.

View File

@ -1,14 +0,0 @@
[package]
name = "r2d2-example"
version = "1.0.0"
edition = "2021"
[dependencies]
actix-web = "4.0.0-rc.1"
env_logger = "0.9.0"
uuid = { version = "1.0.0-alpha.1", features = ["v4"] }
r2d2 = "0.8"
r2d2_sqlite = "0.18.0"
rusqlite = "0.25.4"

View File

@ -1,57 +0,0 @@
//! Actix web r2d2 example
use std::io;
use actix_web::{
error::InternalError, http::StatusCode, middleware, web, App, Error, HttpResponse,
HttpServer,
};
use r2d2::Pool;
use r2d2_sqlite::SqliteConnectionManager;
/// Async request handler. Ddb pool is stored in application state.
async fn index(
path: web::Path<String>,
db: web::Data<Pool<SqliteConnectionManager>>,
) -> Result<HttpResponse, Error> {
// execute sync code in threadpool
let res = web::block(move || {
let conn = db.get().unwrap();
let uuid = format!("{}", uuid::Uuid::new_v4());
conn.execute(
"INSERT INTO users (id, name) VALUES ($1, $2)",
&[&uuid, &path.into_inner()],
)
.unwrap();
conn.query_row("SELECT name FROM users WHERE id=$1", &[&uuid], |row| {
row.get::<_, String>(0)
})
})
.await
.unwrap()
.map(|user| HttpResponse::Ok().json(user))
.map_err(|e| InternalError::new(e, StatusCode::INTERNAL_SERVER_ERROR))?;
Ok(res)
}
#[actix_web::main]
async fn main() -> io::Result<()> {
std::env::set_var("RUST_LOG", "actix_web=debug");
env_logger::init();
// r2d2 pool
let manager = SqliteConnectionManager::file("test.db");
let pool = r2d2::Pool::new(manager).unwrap();
// start http server
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(pool.clone())) // <- store db pool in app state
.wrap(middleware::Logger::default())
.route("/{name}", web::get().to(index))
})
.bind("127.0.0.1:8080")?
.run()
.await
}

View File

@ -17,7 +17,7 @@
### Crates Used
- [actix-web](https://crates.io/crates/actix-web) // Actix web is a simple, pragmatic and extremely fast web framework for Rust.
- [actix-web](https://crates.io/crates/actix-web) // Actix Web is a simple, pragmatic and extremely fast web framework for Rust.
- [rust-argon2](https://crates.io/crates/rust-argon2) // crate for hashing passwords using the cryptographically-secure Argon2 hashing algorithm.
- [chrono](https://crates.io/crates/chrono) // Date and time library for Rust.
- [diesel](https://crates.io/crates/diesel) // A safe, extensible ORM and Query Builder for PostgreSQL, SQLite, and MySQL.

View File

@ -1,4 +1,4 @@
Getting started using [Async-graphql](https://github.com/async-graphql/async-graphql) with Actix web.
Getting started using [Async-graphql](https://github.com/async-graphql/async-graphql) with Actix Web.
## Run

View File

@ -1,6 +1,6 @@
# Juniper
[Juniper](https://github.com/graphql-rust/juniper) integration for Actix web.
[Juniper](https://github.com/graphql-rust/juniper) integration for Actix Web.
If you want more advanced example, see also the [juniper-advanced example].
[juniper-advanced example]: https://github.com/actix/examples/tree/master/graphql/juniper-advanced

View File

@ -1,4 +1,4 @@
//! Actix web juniper example
//! Actix Web juniper example
//!
//! A simple example integrating juniper in Actix Web
use std::io;

View File

@ -1,6 +1,6 @@
# json
Json's `Getting Started` guide using json (serde-json or json-rust) for Actix web
Json's `Getting Started` guide using json (serde-json or json-rust) for Actix Web
## Usage

View File

@ -1,6 +1,6 @@
# Casbin
Basic integration of [Casbin-RS](https://github.com/casbin/casbin-rs) with [RBAC](https://en.wikipedia.org/wiki/Role-based_access_control) for Actix web.
Basic integration of [Casbin-RS](https://github.com/casbin/casbin-rs) with [RBAC](https://en.wikipedia.org/wiki/Role-based_access_control) for Actix Web.
## Usage

View File

@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8" />
<title>Actix web</title>
<title>Actix Web</title>
</head>
<body>
<h1>Welcome!</h1>

View File

@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8" />
<title>Actix web</title>
<title>Actix Web</title>
</head>
<body>
<h1>Hi, {{ name }}!</h1>

View File

@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8" />
<title>Actix web</title>
<title>Actix Web</title>
</head>
<body>
<h1>Welcome!</h1>

View File

@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8" />
<title>Actix web</title>
<title>Actix Web</title>
</head>
<body>
<h1>Hi, {{ name }}!</h1>

View File

@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8" />
<title>Actix web</title>
<title>Actix Web</title>
</head>
<body>
<h1>Welcome!</h1>

View File

@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8" />
<title>Actix web</title>
<title>Actix Web</title>
</head>
<body>
<h1>Hi, {name}!</h1>

View File

@ -1,4 +1,4 @@
{{#> base title = "Actix web" }}
{{#> base title = "Actix Web" }}
{{~#if let Some(name) = query.get("name") }}
{{ let lastname = query.get("lastname").ok_or(MyErr("Bad query"))? }}
{{> card/hi ~}}