mirror of
https://github.com/actix/examples
synced 2025-06-26 17:17:42 +02:00
group imports
This commit is contained in:
@ -5,9 +5,8 @@ mod model;
|
||||
mod test;
|
||||
|
||||
use actix_web::{get, post, web, App, HttpResponse, HttpServer};
|
||||
use mongodb::{bson::doc, options::IndexOptions, Client, Collection, IndexModel};
|
||||
|
||||
use model::User;
|
||||
use mongodb::{bson::doc, options::IndexOptions, Client, Collection, IndexModel};
|
||||
|
||||
const DB_NAME: &str = "myApp";
|
||||
const COLL_NAME: &str = "users";
|
||||
|
@ -51,10 +51,11 @@ mod errors {
|
||||
}
|
||||
|
||||
mod db {
|
||||
use crate::{errors::MyError, models::User};
|
||||
use deadpool_postgres::Client;
|
||||
use tokio_pg_mapper::FromTokioPostgresRow;
|
||||
|
||||
use crate::{errors::MyError, models::User};
|
||||
|
||||
pub async fn add_user(client: &Client, user_info: User) -> Result<User, MyError> {
|
||||
let _stmt = include_str!("../sql/add_user.sql");
|
||||
let _stmt = _stmt.replace("$table_fields", &User::sql_table_fields());
|
||||
@ -80,10 +81,11 @@ mod db {
|
||||
}
|
||||
|
||||
mod handlers {
|
||||
use crate::{db, errors::MyError, models::User};
|
||||
use actix_web::{web, Error, HttpResponse};
|
||||
use deadpool_postgres::{Client, Pool};
|
||||
|
||||
use crate::{db, errors::MyError, models::User};
|
||||
|
||||
pub async fn add_user(
|
||||
user: web::Json<User>,
|
||||
db_pool: web::Data<Pool>,
|
||||
@ -98,13 +100,14 @@ mod handlers {
|
||||
}
|
||||
}
|
||||
|
||||
use crate::config::ExampleConfig;
|
||||
use ::config::Config;
|
||||
use actix_web::{web, App, HttpServer};
|
||||
use dotenv::dotenv;
|
||||
use handlers::add_user;
|
||||
use tokio_postgres::NoTls;
|
||||
|
||||
use crate::config::ExampleConfig;
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
dotenv().ok();
|
||||
|
@ -1,7 +1,8 @@
|
||||
use std::{thread::sleep, time::Duration};
|
||||
|
||||
use actix_web::{error, web, Error};
|
||||
use rusqlite::Statement;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{thread::sleep, time::Duration};
|
||||
|
||||
pub type Pool = r2d2::Pool<r2d2_sqlite::SqliteConnectionManager>;
|
||||
pub type Connection = r2d2::PooledConnection<r2d2_sqlite::SqliteConnectionManager>;
|
||||
|
Reference in New Issue
Block a user