code: entity, migration, quick migration
This commit is contained in:
@@ -1,21 +1,17 @@
|
||||
use dotenvy::dotenv;
|
||||
use miniweb::auth::models::{NewUser, User};
|
||||
use sea_orm::{DatabaseConnection, Database, DbConn};
|
||||
use std::env;
|
||||
use std::io::stdin;
|
||||
|
||||
pub fn establish_connection() -> PgConnection {
|
||||
pub async fn establish_connection() -> DatabaseConnection {
|
||||
dotenv().ok();
|
||||
|
||||
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
||||
PgConnection::establish(&database_url)
|
||||
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
|
||||
let db = Database::connect(&database_url).await;
|
||||
db.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
|
||||
}
|
||||
|
||||
pub fn create_user(conn: &mut PgConnection, username: &str) -> User {
|
||||
use miniweb::schema::users;
|
||||
|
||||
let new_user = NewUser { username };
|
||||
|
||||
pub fn create_user(conn: &DbConn, username: &str) -> User {
|
||||
/*
|
||||
diesel::insert_into(users::table)
|
||||
.values(&new_user)
|
||||
@@ -25,8 +21,10 @@ pub fn create_user(conn: &mut PgConnection, username: &str) -> User {
|
||||
*/
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let connection = &mut establish_connection();
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let connection = establish_connection().await;
|
||||
|
||||
let mut username = String::new();
|
||||
|
||||
@@ -34,6 +32,6 @@ fn main() {
|
||||
stdin().read_line(&mut username).unwrap();
|
||||
let username = username.trim_end(); // Remove the trailing newline
|
||||
|
||||
let user = create_user(connection, username);
|
||||
let user = create_user(&connection, username);
|
||||
println!("\nSaved user {} with id {}", username, user.id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user