Update dependencies (actix-web 2)
This commit is contained in:
parent
240996a313
commit
eab43f8995
5 changed files with 528 additions and 694 deletions
1154
Cargo.lock
generated
1154
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,3 +1,9 @@
|
||||||
== Autoreload
|
== Autoreload
|
||||||
|
|
||||||
https://actix.rs/docs/autoreload/
|
https://actix.rs/docs/autoreload/
|
||||||
|
|
||||||
|
|
||||||
|
== Documentation
|
||||||
|
|
||||||
|
* Rust patterns : https://github.com/rust-unofficial/patterns/tree/master/patterns
|
||||||
|
* Rusqlite (SQLite) : https://docs.rs/rusqlite/0.20.0/rusqlite/
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,9 @@ authors = ["Grégory Burri <greg.burri@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "1.0"
|
actix-web = "2.0"
|
||||||
actix-files = "0.1"
|
actix-rt = "1.0"
|
||||||
|
actix-files = "0.2"
|
||||||
askama = "0.8" # Template system
|
askama = "0.8" # Template system
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
listenfd = "0.3" # To watch file modifications and automatically launch a build process (only used in dev/debug).
|
listenfd = "0.3" # To watch file modifications and automatically launch a build process (only used in dev/debug).
|
||||||
|
|
@ -17,5 +18,5 @@ env_logger = "0.7"
|
||||||
common = { path = "../common" }
|
common = { path = "../common" }
|
||||||
|
|
||||||
[dependencies.rusqlite]
|
[dependencies.rusqlite]
|
||||||
version = "0.20"
|
version = "0.21"
|
||||||
features = ["bundled"]
|
features = ["bundled"]
|
||||||
|
|
@ -6,12 +6,12 @@ use std::fs;
|
||||||
|
|
||||||
const CURRENT_DB_VERSION: u32 = 1;
|
const CURRENT_DB_VERSION: u32 = 1;
|
||||||
|
|
||||||
struct Connection {
|
pub struct Connection {
|
||||||
pub sqlite_con : rusqlite::Connection
|
con: rusqlite::Connection
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Connection {
|
impl Connection {
|
||||||
fn new() -> Connection {
|
pub fn new() -> Connection {
|
||||||
|
|
||||||
// TODO: use a constant in consts module.
|
// TODO: use a constant in consts module.
|
||||||
let data_dir = Path::new("data");
|
let data_dir = Path::new("data");
|
||||||
|
|
@ -20,20 +20,29 @@ impl Connection {
|
||||||
fs::DirBuilder::new().create(data_dir).unwrap();
|
fs::DirBuilder::new().create(data_dir).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
Connection { sqlite_con : rusqlite::Connection::open(data_dir.join("recipes.sqlite")).unwrap() }
|
Connection { con: rusqlite::Connection::open(data_dir.join("recipes.sqlite")).unwrap() }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_or_update(self: &Self) -> rusqlite::Result<&str> {
|
||||||
|
//let connection = Connection::new();
|
||||||
|
// let mut stmt = connection.sqlite_con.prepare("SELECT * FROM versions ORDER BY date").unwrap();
|
||||||
|
// let mut stmt = connection.sqlite_con..prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='versions'").unwrap();
|
||||||
|
|
||||||
|
// Check the Database version.
|
||||||
|
let version = {
|
||||||
|
let stmt_version_table = self.con.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='versions'")?;
|
||||||
|
/*if stmt_version_table.query(rusqlite::NO_PARAMS)?.count() == 0 {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
1 // let stmt_versions = self.con.prepare("SELECT number FROM [")
|
||||||
|
}*/
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
self.con.query_row(
|
||||||
|
"SELECT name FROM sqlite_master WHERE type='table' AND name='versions'",
|
||||||
|
rusqlite::NO_PARAMS,
|
||||||
|
|row| Ok(dbg!("test"))
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_or_update() {
|
|
||||||
let connection = Connection::new();
|
|
||||||
|
|
||||||
// let mut stmt = connection.sqlite_con.prepare("SELECT * FROM versions ORDER BY date").unwrap();
|
|
||||||
|
|
||||||
//let mut stmt = connection.sqlite_con..prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='versions'").unwrap();
|
|
||||||
connection.sqlite_con.query_row(
|
|
||||||
"SELECT name FROM sqlite_master WHERE type='table' AND name='versions'",
|
|
||||||
rusqlite::NO_PARAMS,
|
|
||||||
|row| Ok(dbg!("test"))
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
@ -2,7 +2,7 @@ use std::io::prelude::*;
|
||||||
use std::{fs::File, env::args};
|
use std::{fs::File, env::args};
|
||||||
|
|
||||||
use actix_files as fs;
|
use actix_files as fs;
|
||||||
use actix_web::{web, middleware, App, HttpServer, HttpResponse, Result, web::Query, middleware::Logger};
|
use actix_web::{get, web, Responder, middleware, App, HttpServer, HttpResponse, web::Query, middleware::Logger};
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use listenfd::ListenFd;
|
use listenfd::ListenFd;
|
||||||
|
|
@ -26,12 +26,12 @@ pub struct Request {
|
||||||
m: Option<String>
|
m: Option<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main_page(query: Query<Request>) -> Result<HttpResponse> {
|
fn main_page(query: Query<Request>) -> HttpResponse {
|
||||||
|
|
||||||
let main_template = MainTemplate { test: &"*** test ***" };
|
let main_template = MainTemplate { test: &"*** test ***" };
|
||||||
|
|
||||||
let s = main_template.render().unwrap();
|
let s = main_template.render().unwrap();
|
||||||
Ok(HttpResponse::Ok().content_type("text/html").body(s))
|
HttpResponse::Ok().content_type("text/html").body(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
|
@ -45,7 +45,8 @@ fn get_exe_name() -> String {
|
||||||
first_arg[first_arg.rfind(sep).unwrap()+1..].to_string()
|
first_arg[first_arg.rfind(sep).unwrap()+1..].to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
#[actix_rt::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
if process_args() { return Ok(()) }
|
if process_args() { return Ok(()) }
|
||||||
|
|
||||||
println!("Starting RUP as web server...");
|
println!("Starting RUP as web server...");
|
||||||
|
|
@ -85,7 +86,7 @@ fn main() -> std::io::Result<()> {
|
||||||
server.bind(&format!("0.0.0.0:{}", config.port)).unwrap()
|
server.bind(&format!("0.0.0.0:{}", config.port)).unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
server.run()
|
server.run().await
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_args() -> bool {
|
fn process_args() -> bool {
|
||||||
|
|
@ -100,7 +101,8 @@ fn process_args() -> bool {
|
||||||
print_usage();
|
print_usage();
|
||||||
return true
|
return true
|
||||||
} else if args.iter().any(|arg| arg == "--test") {
|
} else if args.iter().any(|arg| arg == "--test") {
|
||||||
let database_connection = db::create_or_update();
|
let db_connection = db::Connection::new();
|
||||||
|
db_connection.create_or_update();
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue