Merge remote-tracking branch 'origin/master'

# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	src/main.rs
This commit is contained in:
LingandRX 2024-11-06 20:31:25 +08:00
commit 00f301eb83
3 changed files with 2493 additions and 40 deletions

2476
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -4,4 +4,5 @@ version = "0.1.0"
edition = "2021"
[dependencies]
rand = "0.8.5"
mysql = "25.0.1"
actix-web = "4"

View File

@ -1,41 +1,21 @@
use std::io;
use std::cmp::Ordering;
use rand::Rng;
use mysql::*;
use mysql::prelude::*;
fn main() -> Result<()> {
// 连接mysql
let url = "mysql://root:0andrx@122.152.201.90:9912/test_server";
let pool = Pool::new(url)?;
let mut conn = pool.get_conn()?;
fn main() {
println!("Hello, world!");
let secret_number = rand::thread_rng().gen_range(1..=100);
// 执行查询
conn.query_drop(
r"CREATE TABLE IF NOT EXISTS users (
id INT PRIMARY KEY AUTO_INCREMENT,
name TEXT NOT NULL,
age INT NOT NULL
)"
)?;
println!("Created users table");
loop {
// println!("The secret number is {}", secret_number);
println!("Please enter command:");
let mut command = String::new();
io::stdin()
.read_line(&mut command)
.expect("Failed to read line");
let command: u32 = match command.trim().parse() {
Ok(num) => num,
Err(_) => {
println!("Please input a number!");
continue;
},
};
println!("The command is {command}");
match command.cmp(&secret_number) {
Ordering::Less => println!("Too small!"),
Ordering::Equal => {
println!("You win!");
break;
}
Ordering::Greater => println!("Too big!"),
}
}
Ok(())
}